{"action":"created","issue":{"url":"https://api.github.com/repos/yasaichi/gakubuchi/issues/4","repository_url":"https://api.github.com/repos/yasaichi/gakubuchi","labels_url":"https://api.github.com/repos/yasaichi/gakubuchi/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/yasaichi/gakubuchi/issues/4/comments","events_url":"https://api.github.com/repos/yasaichi/gakubuchi/issues/4/events","html_url":"https://github.com/yasaichi/gakubuchi/issues/4","id":149084283,"number":4,"title":"Fails to run gakubuchi without Haml","user":{"login":"5t111111","id":333180,"avatar_url":"https://avatars.githubusercontent.com/u/333180?v=3","gravatar_id":"","url":"https://api.github.com/users/5t111111","html_url":"https://github.com/5t111111","followers_url":"https://api.github.com/users/5t111111/followers","following_url":"https://api.github.com/users/5t111111/following{/other_user}","gists_url":"https://api.github.com/users/5t111111/gists{/gist_id}","starred_url":"https://api.github.com/users/5t111111/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/5t111111/subscriptions","organizations_url":"https://api.github.com/users/5t111111/orgs","repos_url":"https://api.github.com/users/5t111111/repos","events_url":"https://api.github.com/users/5t111111/events{/privacy}","received_events_url":"https://api.github.com/users/5t111111/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/yasaichi/gakubuchi/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-04-18T08:44:05Z","updated_at":"2016-04-18T15:06:29Z","closed_at":null,"body":"I've installed gakubuchi and found both \"generator\" and \"rails server\" fail to run without Haml installed.\r\n\r\n```\r\n$ bin/rails generate gakubuchi:install\r\n/path/to/active_support/dependencies.rb:274:in `require': cannot load such file -- haml (LoadError)\r\n```\r\n\r\n```\r\n$ bin/rails s\r\n...\r\n/path/to/active_support/dependencies.rb:274:in `require': cannot load such file -- haml (LoadError)\r\n```\r\n\r\nI don't know the root cause of the problem yet, but I thought the expected behavior is that a `NameError` occurs in [engine_registrar.rb](https://github.com/yasaichi/gakubuchi/blob/master/lib/gakubuchi/engine_registrar.rb#L21-L25) when you don't install Haml (`haml-rails`) . However, even if you don't need Haml at all, in fact `LoadError` is thrown in `constantize` process in the above code.\r\n\r\nDirty and rough workaround for me (using Slim) is either one of:\r\n\r\n- Simply remove [this line](https://github.com/yasaichi/gakubuchi/blob/master/lib/gakubuchi/railtie.rb#L6)\r\n- Rescue `LoadError` in addition to `NameError` on `constantize` method.\r\n\r\nWhat is the good way to solve this problem? \r\n\r\nFYI: I've confirmed that the same error occurred on both Rails 4.2.6 and 5.0.0.beta3, and I can also provide full backtraces if you want.\r\n\r\nThanks in advance."},"comment":{"url":"https://api.github.com/repos/yasaichi/gakubuchi/issues/comments/211419339","html_url":"https://github.com/yasaichi/gakubuchi/issues/4#issuecomment-211419339","issue_url":"https://api.github.com/repos/yasaichi/gakubuchi/issues/4","id":211419339,"user":{"login":"5t111111","id":333180,"avatar_url":"https://avatars.githubusercontent.com/u/333180?v=3","gravatar_id":"","url":"https://api.github.com/users/5t111111","html_url":"https://github.com/5t111111","followers_url":"https://api.github.com/users/5t111111/followers","following_url":"https://api.github.com/users/5t111111/following{/other_user}","gists_url":"https://api.github.com/users/5t111111/gists{/gist_id}","starred_url":"https://api.github.com/users/5t111111/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/5t111111/subscriptions","organizations_url":"https://api.github.com/users/5t111111/orgs","repos_url":"https://api.github.com/users/5t111111/repos","events_url":"https://api.github.com/users/5t111111/events{/privacy}","received_events_url":"https://api.github.com/users/5t111111/received_events","type":"User","site_admin":false},"created_at":"2016-04-18T15:06:29Z","updated_at":"2016-04-18T15:06:29Z","body":"@yasaichi Thank you for details 😄 \r\n\r\nExpanding the exception class to the ancestor one would be pretty easy fix, so I'm willing to send you a pull request.\r\n\r\nHowever, you know catching wider exceptions is kind of something should be avoided, moreover, since in most use-cases you don't want to use both Haml and Slim at once, leaving users to choose a template engine they want to use would make sense.\r\n\r\nWhat I mean is that I think you can get rid of template engine registrations from `railtie.rb`, and you can add them in the initializer like the followings:\r\n\r\n__railtie.rb__\r\n\r\n```ruby\r\nmodule Gakubuchi\r\n  class Railtie < ::Rails::Railtie\r\n    rake_tasks do\r\n      ::Dir.glob(::File.expand_path('../../tasks/*.rake', __FILE__)).each { |path| load path }\r\n    end\r\n  end\r\nend\r\n```\r\n\r\n__gakubuchi.rb.erb__\r\n\r\n```erb\r\nGakubuchi.configure do |config|\r\n\r\n  ~*~* snip ~*~*\r\n\r\nend\r\n\r\nRails.application.config.assets.configure do |env|\r\n  engine_registrar = Gakubuchi::EngineRegistrar.new(env)\r\n\r\n  # Choose the template engine you prefer for writing static pages\r\n  # (only Haml or Slim for the moment).\r\n  <%- if options.engine.blank? -%>\r\n  engine_registrar.register(:haml, '::Tilt::HamlTemplate')\r\n  engine_registrar.register(:slim, '::Slim::Template')\r\n  <%- elsif options.engine == 'haml' -%>\r\n  engine_registrar.register(:haml, '::Tilt::HamlTemplate')\r\n  # engine_registrar.register(:slim, '::Slim::Template')\r\n  <%- elsif options.engine == 'slim' -%>\r\n  # engine_registrar.register(:haml, '::Tilt::HamlTemplate')\r\n  engine_registrar.register(:slim, '::Slim::Template')\r\n  <%- end -%>\r\nend\r\n```\r\n\r\nthen add kind of this to `install_generator.rb` .\r\n\r\n```ruby\r\n      class_option :engine,\r\n        type: :string,\r\n        aliases: '-e',\r\n        desc: 'Template engine to use'\r\n```\r\n\r\nHow does this fix sound to you?"}}