livingstyleguide icon indicating copy to clipboard operation
livingstyleguide copied to clipboard

ActiveSupport::VERSION not found when using Markdown in *.lsg file

Open hkockerbeck opened this issue 7 years ago • 6 comments

I'm trying to use livingstyleguide in a Middleman project, installed as described in the https://github.com/livingstyleguide/livingstyleguide#middleman-integration. But as soon as I use Markdown syntax in a *.lsg file, I get the error

NameError at /styleguide.html
uninitialized constant ActiveSupport::VERSION

Ruby 	/home/henning/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/livingstyleguide-2.0.2/lib/livingstyleguide/markdown_extensions.rb: in slug, line 73
Web 	GET localhost/styleguide.html

Traceback (innermost first)

    /home/henning/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/livingstyleguide-2.0.2/lib/livingstyleguide/markdown_extensions.rb: in slug
              if ::ActiveSupport::VERSION::MAJOR >= 5
...

I'm using Ruby 2.4.1, Middleman 4.2.1 and livingstyleguide 2.0.2.

hkockerbeck avatar Jul 05 '17 16:07 hkockerbeck

I looked into the issue a bit further, and it looks like you need to require the "base ActiveSupport" in addition to the part you want to use. See for example the Rails guides on ActiveSupport Extensions. A short trial run in pry also supports this:

[1] pry(main)> require 'active_support/core_ext/string/inflections'
=> true
[2] pry(main)> ActiveSupport::VERSION::MAJOR
NameError: uninitialized constant ActiveSupport::VERSION
from (pry):2:in `__pry__'

compared to

[1] pry(main)> require 'active_support'
=> true
[2] pry(main)> require 'active_support/core_ext/string/inflections'
=> true
[3] pry(main)> ::ActiveSupport::VERSION::MAJOR
=> 5

So I'd suggest to add another require to the slug function in markdown_extensions.rb like so

def slug(text)
      require "active_support"
      require "active_support/core_ext/string/inflections"
      if ::ActiveSupport::VERSION::MAJOR >= 5
        ::ActiveSupport::Inflector.parameterize(text, separator: "-")
      else
        ::ActiveSupport::Inflector.parameterize(text, "-")
      end
    rescue LoadError
      text.downcase.gsub(/[ _\.\-!\?\(\)\[\]]+/, "-").gsub(/^-|-$/, "")
end

hkockerbeck avatar Jul 05 '17 17:07 hkockerbeck

Sounds good. Do you want to open a pull request?

hagenburger avatar Jul 05 '17 20:07 hagenburger

Hi, any idea when this is going to be release on rubygems? The current version doesn't contain this fix yet. :)

Dahie avatar Oct 04 '18 10:10 Dahie

@Dahie thanks for the reminder. I’ll try to check tonight. I’m not actively using it right now as I’m working on JavaScript projects only. Most of my development goes into PIMD – which is based on the ideas and learnings of LivingStyleGuide. I’d love to have a Ruby integration later on.

hagenburger avatar Oct 04 '18 10:10 hagenburger

@Dahie done: https://twitter.com/LSGorg/status/1048126173467873280

hagenburger avatar Oct 05 '18 08:10 hagenburger

@hagenburger woop woop, thank you! <3

Dahie avatar Oct 05 '18 08:10 Dahie