rails-composer icon indicating copy to clipboard operation
rails-composer copied to clipboard

Slim or HAML as template language choice for Custom application

Open rylanb opened this issue 9 years ago • 18 comments

This isn't a huge deal, but some strange behavior I've noticed is that if I select anything but ERB for the template language.

Ruby Version: 2.2.4 Rails Version: 4.2.6 RVM 1.26.11, with project specific gemset.

Steps:

  1. gem install rails
  2. rails new . -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb
  3. Custom application (experimental)
  4. Select Slim or HAML as template lang

Error: composer importing html2haml and haml2slim conversion tools The template [https://raw.github.com/RailsApps/rails-composer/master/composer.rb] could not be loaded. Error: cannot load such file -- html2haml

Gist of Console Inputs: https://gist.github.com/rylanb/68ef2900211c203736cf73f52217ac3b

Let me know if you have any questions. I just switched to ERB and did it after with no problems, but thought it would be worth adding an issue. Thanks for all your hard work!

rylanb avatar Apr 11 '16 02:04 rylanb

Hello @rylanb, I had a look at this to see if the problem still exists. I replicated your steps and did not get the error you received in the past. I made an example app of this so you can take a peek if you'd like to as well: https://github.com/Schwad/rylanb-rails-composer-replicator-app

Do you think that this is fixed now and can be closed, or what are your thoughts? :)

Schwad avatar Sep 02 '17 18:09 Schwad

@Schwad thanks for checking! Looks like the issue has gone away!

I'll close. Thanks for looking into this!

rylanb avatar Sep 04 '17 19:09 rylanb

Ok I posted that pre-emptively. At the VERY end it gave me this output:

Bundle complete! 42 Gemfile dependencies, 130 gems now installed.
Gems in the group production were not installed.
Bundled gems are installed into ./vendor/bundle.
    composer  Updating gem paths.
WARN: Unresolved specs during Gem::Specification.reset:
      minitest (~> 5.1)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
    composer  Stage Two (running recipe 'stage_two' callbacks).
    composer  importing html2haml conversion tool
The template [https://raw.github.com/RailsApps/rails-composer/master/composer.rb] could not be loaded. Error: cannot load such file -- html2haml

After install and selecting haml.

I can't find the Readme with the steps I selected to install... ?

Full terminal output: https://gist.github.com/rylanb/0311fdc59c9ea07d4a6646dc6d32e9b3

rylanb avatar Sep 04 '17 19:09 rylanb

I made a .rvm-gemset and a .ruby-version ruby-2.4.0@test-composer and then gem install rails. I vendor gems locally in vendor/bundle.

My terminal output should show you the options I chose.

rylanb avatar Sep 04 '17 19:09 rylanb

Hello,

i selected Slim as template engine and the results is :

extras
      extras  recipe stage two
        gsub    Gemfile
        gsub    app/assets/javascripts/application.js
        gsub    app/views/layouts/application.html.slim
The template [https://raw.github.com/RailsApps/rails-composer/master/composer.rb] could not be loaded. Error: No such file or directory @ rb_sysopen - /Users/edo/dev/onyx-crm/app/views/layouts/application.html.slim

application.html.slim is not exists because Composer creates application.html.erb even though the selection was Slim or Haml.

edolix avatar Jan 03 '18 09:01 edolix

Getting the same error after selecting slim. 🤔

Bundled gems are installed into `./vendor/bundle` composer Updating gem paths. WARN: Unresolved specs during Gem::Specification.reset: minitest (~> 5.1) rake (>= 0.8.7) WARN: Clearing out unresolved specs. Please report a bug if this causes problems. composer Stage Two (running recipe 'stage_two' callbacks). composer importing html2haml and haml2slim conversion tools The template [https://raw.github.com/RailsApps/rails-composer/master/composer.rb] could not be loaded. Error: cannot load such file -- html2haml

bctoh avatar Jan 16 '18 09:01 bctoh

Are these different errors? Or should we whip up a PR that includes application.html.slim instead of application.html.erb on the slim selection? @bctoh @edolix

Schwad avatar Jan 17 '18 13:01 Schwad

@bctoh @edolix @rylanb

So here's what I've got so far.

The main file we should be concerned with: https://github.com/RailsApps/rails-composer/blob/3656989c76ae5f0dc0965dfeac615a401f708f1d/composer.rb

The setting for your preferences on slim is referenced within prefs[:templates] which is altered only in two places:

https://github.com/RailsApps/rails-composer/blob/3656989c76ae5f0dc0965dfeac615a401f708f1d/composer.rb#L473

https://github.com/RailsApps/rails-composer/blob/3656989c76ae5f0dc0965dfeac615a401f708f1d/composer.rb#L1228

The method to set application.html.erb to application.html.haml is copy_from_repo (see: https://github.com/RailsApps/rails-composer/blob/3656989c76ae5f0dc0965dfeac615a401f708f1d/composer.rb#L196)

So it appears to explicitly change that file under a couple recipes, but not under learn-rails where I think it is resetting prefs to erb?

I cannot find any other place where files would be changed to slim besides copy_from_repo, it even invokes an html_to_slim method https://github.com/RailsApps/rails-composer/blob/3656989c76ae5f0dc0965dfeac615a401f708f1d/composer.rb#L224

Gosh you guys, not really sure what to think here. Do not know if I'm any closer to having a clue. Maybe if you have a peek at the source code and let me know what you think?

Also, if those involved specify their Rails/Ruby versions again and their recipes they were trying to run? That would be really helpful. I've only ever used Haml and ERB with this and not had any issues but slim is a big component of the code and it'd be great to get it rocking and rolling again!

Schwad avatar Jan 17 '18 13:01 Schwad

@Schwad my starter application was rails-devise-roles so i think the issue is related with default template engine used by: rails new app-name.

I think it's like that because into this if statement i don't see any copy_from_repo https://github.com/RailsApps/rails-composer/blob/3656989c76ae5f0dc0965dfeac615a401f708f1d/composer.rb#L681

And then, in this case, it searchs the application.html.slim (or application.html.haml) file that does not exists.

https://github.com/RailsApps/rails-composer/blob/3656989c76ae5f0dc0965dfeac615a401f708f1d/composer.rb#L2603-L2610

edolix avatar Jan 17 '18 14:01 edolix

@edolix this should prove or disprove the theory, here's a repo where I've ripped out everything in that case statement except for line 2605.

https://github.com/Schwad/rails-composer

(commit: https://github.com/Schwad/rails-composer/commit/7518d85a79959f85cf71cf56e6ee51090447b8e5)

If you're right and run against that repo it should pass? Let me know what you find....

Schwad avatar Jan 17 '18 15:01 Schwad

@edolix reading over these errors I think we're on the right track with yours but now I'm suspicious of the others that certain recipes might be requiring and loading html2slim incorrectly somehow...

Schwad avatar Jan 17 '18 15:01 Schwad

@Schwad using your repo https://github.com/Schwad/rails-composer the composer ends correctly, obviously all layout files are ERB - such as application.html.erb.

Composer should call html_to_slim for each ERB file into the repo, only if prefs[:template] is different from 'erb'. Make sense?

edolix avatar Jan 17 '18 23:01 edolix

It seems 'copy from repo' can be used for 'conversion' as well as pulling in specific files from specific repos for specific recipes (and converting them along the way). (I think this is used a lot in the learn-rails recipe: https://github.com/RailsApps/rails-composer/blob/3656989c76ae5f0dc0965dfeac615a401f708f1d/composer.rb#L451)

I don't know if it would destroy everything but it may be worth having a method that iterates over everything in the root files folder and converts them over.... After preference is selected and before custom files are copied in from root.

However, cleanup would have to happen after this because there are a few random places where some of these files are copied over - such as stripe coupons: https://github.com/RailsApps/rails-composer/blob/3656989c76ae5f0dc0965dfeac615a401f708f1d/composer.rb#L1054

Well - anyway - this isn't a fix but I took a massive punt here at shoving in a method to attempt to copy all the files from the core repo.... And I am guessing the best place for it would be at the start of every single stage three (just before specific copy_from_repo's happen).

I have a bunch of "puts" debugging included so if it breaks it should be clear where and on what file it breaks.

Could you have a look at this and see if it gives you any success? (Success == all core files 'slimified')

Schwad avatar Jan 18 '18 11:01 Schwad

commit: https://github.com/Schwad/rails-composer/commit/23f07a27ce7aaf59fa094ea9b0565284353e75ae

repo: https://github.com/Schwad/rails-composer

Schwad avatar Jan 18 '18 11:01 Schwad

Just checking in. I see you've invested a lot of effort in sorting this out. I'll try to find some time soon to take a look.

DanielKehoe avatar Jan 18 '18 14:01 DanielKehoe

@DanielKehoe rails-composer is one of my favorite resources on the planet. Just trying to do my bit and having a look if I can help! 😃

Schwad avatar Jan 18 '18 14:01 Schwad

Glad you like it! You're not alone. I'm trying to keep up with maintenance but I'm no longer able to work fulltime on open source as I did a year ago. I'm job hunting right now (know anyone who is hiring who supports part-time open source work?). But I'll try to take a look at this issue soon.

DanielKehoe avatar Jan 18 '18 15:01 DanielKehoe

@DanielKehoe I remember @sgrif talking about this dilemma on a podcast a while back.... He may have some good thoughts about seeking out entities that have pro-open-source-work policies!

Schwad avatar Jan 18 '18 15:01 Schwad