Skip to content

Loading…

Update nifty_layout to be compatible with Rails 3.1 directory estructure and SCSS #109

Open
wants to merge 9 commits into from

5 participants

@PaBLoX-CL

This pull request has 3 main points:

  1. Rails 3.1 has a slightly different directory structure, being the most relevant the location of the stylesheets, now in app/assets and this fork reflect those changes.

  2. I added the corresponding cucumber scenarios and cleaned up a bit (hope for better).

  3. Now SASS a new syntax (SCSS), so I added an option (--scss) to the nifty:layout generator to made possible to chose between the three (erb + css, haml + sass and haml + scss). Please, be free to change the option for whatever you find it's better.

Regards,

PS.- I don't have too much experience in collaborating in other people projects so spare me if I did something wrong.

@ryanb
Owner

This looks really great, thank you! We should probably make this dynamic so it only happens when one is using Rails 3.1 that way it doesn't break Rails 3.0. What do you think?

@PaBLoX-CL
@ryanb
Owner

That should work, you can just check if it starts with "3.0". There may be better ways, haven't looked.

mlitwiniuk and others added some commits
@mlitwiniuk mlitwiniuk copies assets to Rails 3.1 specific directory (if on Rails 3.1), does…
… not overwrite application.css on Rails 3.1
3809969
@PaBLoX-CL PaBLoX-CL Add the corresponding feature to the change in the directory structure
I tried to keep both versions (3.0.x and 3.1.x) on different gemsets
using rvm, but for some reason I couldn't. They kept going back to the main
gemset and being installed there. So, if Rails >=3.1.0 isn't installed
the nifty_layout_3.1 feature is going to fail.
8ee7978
@PaBLoX-CL

Sorry to keep you waiting :P.

I've added the cucumber feature corresponding to the changes mlitwiniuk added.
I created a new file for it, although it's almost the same. I bet there's a way to have them bot on the same file, but the ways I could come up were too complex and would be against cucumber philosophy (afaik).

Since we're using two rails versions now, I tried that both versions (3.0.x and 3.1.x) would stay on different gemsets using rvm, but for some reason I couldn't. They kept going back to the main gemset and being installed there. So, if Rails >=3.1.0 isn't installed the nifty_layout_3.1 feature is going to fail.

Any suggestion, commentary would be welcome :)

@jatinganhotra

@PaBLoX-CL I downloaded your Git repository ,did bundle then rake.
I did so while keeping both versions(3.0.11 and 3.1.0) on different gemsets, but the feature would still fail. There were two cases:
1. When I set the development_dependency 'rails' to '~>3.0'
the nifty_layout_3.1.feature fails (line nos 13 and 21).
2. When I set the development_dependency 'rails' to '~>3.1'
the nifty_layout.feature fails(line nos. 13 and 21).

@ryanb @PaBLoX-CL How to tackle this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 12, 2011
  1. @PaBLoX-CL
  2. @PaBLoX-CL
Commits on Jun 18, 2011
  1. @PaBLoX-CL
  2. @PaBLoX-CL
Commits on Jun 19, 2011
  1. @PaBLoX-CL
Commits on Jun 24, 2011
  1. @igorbozato

    Just keep it readable

    igorbozato committed
Commits on Jun 25, 2011
  1. @PaBLoX-CL

    Merge pull request #1 from igorbozato/patch-1

    PaBLoX-CL committed
    More readable scss template
Commits on Jul 20, 2011
  1. @mlitwiniuk

    copies assets to Rails 3.1 specific directory (if on Rails 3.1), does…

    mlitwiniuk committed
    … not overwrite application.css on Rails 3.1
Commits on Sep 3, 2011
  1. @PaBLoX-CL

    Add the corresponding feature to the change in the directory structure

    PaBLoX-CL committed
    I tried to keep both versions (3.0.x and 3.1.x) on different gemsets
    using rvm, but for some reason I couldn't. They kept going back to the main
    gemset and being installed there. So, if Rails >=3.1.0 isn't installed
    the nifty_layout_3.1 feature is going to fail.
This page is out of date. Refresh to see the latest.
View
28 features/nifty_layout.feature
@@ -3,18 +3,28 @@ Feature: Nifty Layout Generator
As a rails developer
I want to generate a simple layout
+ Background: Create a new rails app
+ Given a new Rails 3.0.x app
+
Scenario: Generate normal application layout
- Given a new Rails app
When I run "rails g nifty:layout -f"
Then I should see "stylesheet_link_tag "application"" in file "app/views/layouts/application.html.erb"
Then I should see "h(page_title" in file "app/helpers/layout_helper.rb"
- And I should see file "app/helpers/layout_helper.rb"
- And I should see file "app/helpers/error_messages_helper.rb"
- And I should see file "public/stylesheets/application.css"
+ And I should see the following files
+ | app/helpers/layout_helper.rb |
+ | app/helpers/error_messages_helper.rb |
+ | public/stylesheets/application.css |
- Scenario: Generate named layout with haml and sass
- Given a new Rails app
- When I run "rails g nifty:layout FooBar --haml -f"
- Then I should see "stylesheet_link_tag "foo_bar"" in file "app/views/layouts/foo_bar.html.haml"
- And I should see file "public/stylesheets/sass/foo_bar.sass"
+ Scenario Outline: Generate named layout with haml...
+ When I run "rails g nifty:layout FooBar --<option> -f"
+ Then I should see "stylesheet_link_tag "foo_bar" in file "app/views/layouts/foo_bar.html.haml"
+ And I should see file "public/stylesheets/foo_bar.<sass_version>"
And I should see file "app/helpers/layout_helper.rb"
+
+ Scenarios: ...and sass
+ | option | sass_version |
+ | haml | sass |
+
+ Scenarios: ...and scss
+ | option | sass_version |
+ | scss | css.scss |
View
30 features/nifty_layout_3.1.feature
@@ -0,0 +1,30 @@
+Feature: Nifty Layout Generator
+ In order to have a layout
+ As a rails developer
+ I want to generate a simple layout
+
+ Background: Create a new rails app
+ Given a new Rails 3.1.x app
+
+ Scenario: Generate normal application layout
+ When I run "rails g nifty:layout -f"
+ Then I should see "stylesheet_link_tag "application"" in file "app/views/layouts/application.html.erb"
+ Then I should see "h(page_title" in file "app/helpers/layout_helper.rb"
+ And I should see the following files
+ | app/helpers/layout_helper.rb |
+ | app/helpers/error_messages_helper.rb |
+ | app/assets/stylesheets/application.css |
+
+ Scenario Outline: Generate named layout with haml...
+ When I run "rails g nifty:layout FooBar --<option> -f"
+ Then I should see "stylesheet_link_tag "foo_bar" in file "app/views/layouts/foo_bar.html.haml"
+ And I should see file "app/assets/stylesheets/foo_bar.<sass_version>"
+ And I should see file "app/helpers/layout_helper.rb"
+
+ Scenarios: ...and sass
+ | option | sass_version |
+ | haml | sass |
+
+ Scenarios: ...and scss
+ | option | sass_version |
+ | scss | css.scss |
View
15 features/step_definitions/rails_setup_steps.rb
@@ -1,6 +1,13 @@
Given /^a new Rails app$/ do
- FileUtils.mkdir_p("tmp")
- system("rails new tmp/rails_app").should be_true
- system("ln -s ../../../lib/generators tmp/rails_app/lib/generators").should be_true
- @current_directory = File.expand_path("tmp/rails_app")
+# FileUtils.mkdir_p("tmp")
+ system("rails new tmp/rails_app/any_version").should be_true
+ FileUtils.ln_s("../../../../lib/generators", "tmp/rails_app/any_version/lib/generators").should be_true
+ @current_directory = File.expand_path("tmp/rails_app/any_version")
+end
+
+Given /^a new Rails (\d+)\.(\d+)\.x app$/ do |major, minor|
+# FileUtils.mkdir_p("tmp")
+ system("rails _#{major}.#{minor}_ new tmp/rails_app/version_#{major}.#{minor}.x").should be_true
+ FileUtils.ln_s("../../../../lib/generators", "tmp/rails_app/version_#{major}.#{minor}.x/lib/generators").should be_true
+ @current_directory = File.expand_path("tmp/rails_app/version_#{major}.#{minor}.x")
end
View
8 lib/generators/nifty/layout/USAGE
@@ -3,8 +3,8 @@ Description:
helper which will give some structure to a starting Rails app.
The generator takes one argument which will be the name of the
- layout and stylesheet files. If no argument is passed then it defaults
- to "application".
+ layout and stylesheet files. If no argument is passed then it defaults
+ to "application".
The helper module includes some methods which can be called in any
template or partial to set variables to be used in the layout, such as
@@ -14,12 +14,12 @@ Examples:
rails generate nifty:layout
Layout: app/views/layouts/application.html.erb
- Stylesheet: public/stylesheets/application.css
+ Stylesheet: app/assets/stylesheets/application.css
Helper: app/helpers/layout_helper.rb
rails generate nifty:layout admin
Layout: app/views/layouts/admin.html.erb
- Stylesheet: public/stylesheets/admin.css
+ Stylesheet: app/assets/stylesheets/admin.css
Helper: app/helpers/layout_helper.rb
View
15 lib/generators/nifty/layout/layout_generator.rb
@@ -6,14 +6,25 @@ class LayoutGenerator < Base
argument :layout_name, :type => :string, :default => 'application', :banner => 'layout_name'
class_option :haml, :desc => 'Generate HAML for view, and SASS for stylesheet.', :type => :boolean
+ class_option :scss, :desc => 'Generate HAML for view, and SCSS for stylesheet.', :type => :boolean
def create_layout
+ style_name = file_name
+ style_path = 'public'
+ if (Rails.version =~ /^3\.1/) != nil
+ # For Rails 3.1 and its assets pipeline we don't want to overwrite application.css
+ style_name = 'nifty_layout' if file_name == 'application'
+ style_path = 'app/assets'
+ end
if options.haml?
template 'layout.html.haml', "app/views/layouts/#{file_name}.html.haml"
- copy_file 'stylesheet.sass', "public/stylesheets/sass/#{file_name}.sass"
+ copy_file 'stylesheet.sass', "#{style_path}/stylesheets/#{style_name}.sass"
+ elsif options.scss?
+ template 'layout.html.haml', "app/views/layouts/#{file_name}.html.haml"
+ copy_file 'stylesheet.css.scss', "#{style_path}/stylesheets/#{style_name}.css.scss"
else
template 'layout.html.erb', "app/views/layouts/#{file_name}.html.erb"
- copy_file 'stylesheet.css', "public/stylesheets/#{file_name}.css"
+ copy_file 'stylesheet.css', "#{style_path}/stylesheets/#{style_name}.css"
end
copy_file 'layout_helper.rb', 'app/helpers/layout_helper.rb'
copy_file 'error_messages_helper.rb', 'app/helpers/error_messages_helper.rb'
View
83 lib/generators/nifty/layout/templates/stylesheet.css.scss
@@ -0,0 +1,83 @@
+$primary_color: #4b7399;
+
+body {
+ background-color: $primary_color;
+ font: {
+ family: Verdana, Helvetica, Arial;
+ size: 14px;
+ };
+}
+
+a {
+ color: blue;
+ img {
+ border: none;
+ }
+}
+
+.clear {
+ clear: both;
+ height: 0;
+ overflow: hidden;
+}
+
+#container {
+ width: 75%;
+ margin: 0 auto;
+ background: white;
+ padding: 20px 40px;
+ border: solid 1px black;
+ margin-top: 20px;
+}
+
+#flash_notice,
+#flash_error {
+ padding: 5px 8px;
+ margin: 10px 0;
+}
+
+#flash_notice {
+ background-color: #ccffcc;
+ border: solid 1px #66cc66;
+}
+
+#flash_error {
+ background-color: #ffcccc;
+ border: solid 1px #cc6666;
+}
+
+.fieldWithErrors {
+ display: inline;
+}
+
+#errorExplanation {
+ width: 400px;
+ border: 2px solid #cf0000;
+ padding: 0;
+ padding-bottom: 12px;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ h2 {
+ text-align: left;
+ padding: 5px 5px 5px 15px;
+ margin: 0;
+ font: {
+ weight: bold;
+ size: 12px;
+ };
+ background-color: #cc0000;
+ color: white;
+ }
+ p {
+ color: #333333;
+ margin-bottom: 0;
+ padding: 8px;
+ }
+ ul {
+ margin: 2px 24px;
+ li {
+ font-size: 12px;
+ list-style: disc;
+ }
+ }
+}
Something went wrong with that request. Please try again.