Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
28 changes: 19 additions & 9 deletions features/nifty_layout.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
30 changes: 30 additions & 0 deletions features/nifty_layout_3.1.feature
Original file line number Diff line number Diff line change
@@ -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 |
15 changes: 11 additions & 4 deletions features/step_definitions/rails_setup_steps.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions lib/generators/nifty/layout/USAGE
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
15 changes: 13 additions & 2 deletions lib/generators/nifty/layout/layout_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
83 changes: 83 additions & 0 deletions lib/generators/nifty/layout/templates/stylesheet.css.scss
Original file line number Diff line number Diff line change
@@ -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;
}
}
}