livingstyleguide
livingstyleguide copied to clipboard
ActiveSupport::VERSION not found when using Markdown in *.lsg file
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.
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
Sounds good. Do you want to open a pull request?
Hi, any idea when this is going to be release on rubygems? The current version doesn't contain this fix yet. :)
@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.
@Dahie done: https://twitter.com/LSGorg/status/1048126173467873280
@hagenburger woop woop, thank you! <3