Permalink
Browse files

Generate more logically organized stylesheets directory

  • Loading branch information...
1 parent f6204c4 commit c88c196b9c317098d0d0687111e72b2cd9e6a120 @sporkd committed Apr 7, 2013
@@ -1,11 +1,14 @@
Description:
- Generates CSS assets with compass imports and partials.
+ Generates javascript and stylesheet assets for a named resource.
Example:
rails generate html5:assets admin
This will create:
- app/assets/stylesheets/admin.css.scss
- app/assets/stylesheets/_defaults.css.scss
- app/assets/stylesheets/admin/document.css.scss
+ app/assets/javascripts/admin.js
+ app/assets/javascripts/polyfills.js
+ app/assets/stylesheets/admin
+ app/assets/stylesheets/admin/index.css.scss
+ app/assets/stylesheets/admin/variables.css.scss
+ app/assets/stylesheets/admin/layout.css.scss
app/assets/stylesheets/admin/media_queries.css.scss
@@ -9,39 +9,40 @@ class AssetsGenerator < ::Rails::Generators::NamedBase
argument :name, :type => :string,
:required => false,
- :default => "application"
+ :default => 'application'
def generate_javascripts
- asset_path = "app/assets/javascripts/#{ asset_name }.js"
- if File.exist?(asset_path) && File.read(asset_path) =~ /require jquery_ujs$/
- inject_into_file asset_path, :after => "require jquery_ujs" do
+ prefix = File.join('app', 'assets', 'javascripts')
+ manifest = File.join(prefix, File.basename(asset_path) + '.js')
+
+ empty_directory File.join(prefix, File.dirname(asset_path))
+
+ if File.exist?(manifest) && File.read(manifest) =~ /require jquery_ujs$/
+ inject_into_file manifest, :after => "require jquery_ujs" do
"\n//= require h5bp"
end
- gsub_file asset_path, /^\/\/= require_tree \.(\\n)?/, ""
+ gsub_file manifest, /^\/\/= require_tree \.(\\n)?/, ''
else
- template "javascripts/application.js", asset_path
+ template "javascripts/application.js", manifest
end
- template "javascripts/polyfills.js", "app/assets/javascripts/polyfills.js"
+
+ template "javascripts/polyfills.js", File.join(prefix, 'polyfills.js')
end
def generate_stylesheets
- if file_path == "application"
- remove_file "app/assets/stylesheets/application.css"
- end
+ prefix = File.join('app', 'assets', 'stylesheets')
- file_ext = ".css.scss"
- copy_file "stylesheets/_variables#{ file_ext }", "app/assets/stylesheets/_variables#{ file_ext }"
- template "stylesheets/application#{ file_ext }", File.join("app/assets/stylesheets", asset_name + file_ext)
- end
+ if file_path == 'application'
+ remove_file File.join(prefix, 'application.css')
+ end
- def generate_stylesheet_partials
- if stylesheet_partials.any?
- empty_directory File.join("app/assets/stylesheets", asset_name)
+ if stylesheets.any?
+ empty_directory File.join(prefix, asset_path)
end
- file_ext = ".css.scss"
- stylesheet_partials.each do |partial|
- template File.join("stylesheets/application", partial + file_ext), File.join("app/assets/stylesheets", asset_name, partial + file_ext)
+ stylesheets.each do |stylesheet|
+ file_name = stylesheet + ".css.scss"
+ template "stylesheets/application/#{ file_name }", File.join(prefix, asset_path, file_name)
end
end
@@ -51,12 +52,12 @@ def generate_stylesheet_partials
protected
- def asset_name
- (class_path + [file_name]).join('_')
+ def asset_path
+ File.join(class_path + [file_name])
end
- def stylesheet_partials
- %w(document media_queries)
+ def stylesheets
+ %w(index variables layout media_queries)
end
end
end
@@ -1,11 +1,13 @@
// This file was generated by html5-rails
// https://github.com/sporkd/html5-rails
// Upgrade with: $ rails generate html5:install
+//
+// <%= file_path %> styles
//-----------------------------------------
// Variables
//-----------------------------------------
-@import "variables";
+@import 'variables';
//-----------------------------------------
// Vendor imports
@@ -23,5 +25,5 @@
//-----------------------------------------
// Custom imports
//-----------------------------------------
-@import '<%= file_path %>/document';
-@import '<%= file_path %>/media_queries';
+@import 'layout';
+@import 'media_queries';
@@ -7,3 +7,17 @@ Example:
This will create:
config/compass.rb
config/html5_rails.yml
+ app/views/layouts/application.html.(erb|haml|slim)
+ app/views/layouts/application.html.(erb|haml|slim)
+ app/views/application
+ app/views/application/_footer.html.(erb|haml|slim)
+ app/views/application/_head.html.(erb|haml|slim)
+ app/views/application/_header.html.(erb|haml|slim)
+ app/views/application/_chromeframe.html.(erb|haml|slim)
+ app/assets/javascripts/application.js
+ app/assets/javascripts/polyfills.js
+ app/assets/stylesheets/application
+ app/assets/stylesheets/application/index.css.scss
+ app/assets/stylesheets/application/variables.css.scss
+ app/assets/stylesheets/application/layout.css.scss
+ app/assets/stylesheets/application/media_queries.css.scss
@@ -1,6 +1,6 @@
===============================================================================
-You are now on html5-rails. Really, that's it for now.
+You've successfully installed html5-rails!
If want to genrate additional layouts, just run:
$ rails g html5:layout my_new_layout
@@ -1,8 +1,8 @@
Description:
- Removes Erb layout and installs a html5-rails Haml layout.
+ Installs a new html5-rails layout in /app/views/layouts
Example:
- rails generate html5:layout layout_name
+ rails generate html5:layout my_new_layout
This will create:
- app/views/layouts/layout_name.html.haml
+ app/views/layouts/my_new_layout.html.(erb|haml|slim)
@@ -9,21 +9,21 @@ class LayoutGenerator < ::Rails::Generators::NamedBase
argument :name, :type => :string,
:required => false,
- :default => "application"
+ :default => 'application'
class_option :all_partials, :type => :boolean,
:default => false,
- :desc => "Generate all partials for this layout"
+ :desc => 'Generate all partials for this layout'
class_option :minimal_partials, :type => :boolean,
:default => false,
- :desc => "Generate minimal partials for this layout"
+ :desc => 'Generate minimal partials for this layout'
class_option :template_engine
def generate_layout
- if file_path == "application" && options[:template_engine].to_s != "erb"
- remove_file File.join("app/views/layouts/application.html.erb")
+ if file_path == 'application' && options[:template_engine].to_s != 'erb'
+ remove_file "app/views/layouts/application.html.erb"
end
template filename_with_extensions("application"), File.join("app/views/layouts", class_path, filename_with_extensions(file_name))
end
@@ -1,8 +1,18 @@
Description:
- Generates a partial
+ Copies an existing html5-rails partial to the views folder so it can be editied.
Example:
- rails generate html5:partial _partial_name
+ rails generate html5:partial _javascripts
This will create:
- app/views/application/_partial_name.html.haml
+ app/views/application/_partial_name.html.(erb|haml|slim)
+
+ Choices include:
+ _head
+ _chromeframe
+ _flashes
+ _header
+ _footer
+ _javascripts
+ _stylesheets
+
@@ -9,27 +9,27 @@ class PartialGenerator < ::Rails::Generators::NamedBase
argument :name, :type => :string,
:required => false,
- :default => ""
+ :default => ''
class_option :all, :type => :boolean,
:default => false,
- :desc => "Generate all partials"
+ :desc => 'Generate all partials'
class_option :minimal, :type => :boolean,
:default => false,
- :desc => "Generate minimal partials (_head, _header, _footer)"
+ :desc => 'Generate minimal partials (_head, _header, _footer)'
class_option :path, :type => :string,
:default => nil,
:required => false,
- :desc => "resource path to generate partials in"
+ :desc => 'resource path to generate partials in'
class_option :template_engine
# def validate_name
# if options[:all] || options[:minimal]
# if partials.include?(file_name)
- # path = class_path.join("/")
+ # path = class_path.join('/')
# message = "Argument '#{ file_path }' not allowed with --all or --minimal options."
# message << " Try using '#{ path }' instead." if !path.blank?
# raise Error, message
@@ -39,7 +39,7 @@ class PartialGenerator < ::Rails::Generators::NamedBase
def generate_partials
if partials.any?
- empty_directory File.join("app/views", partial_path)
+ empty_directory File.join('app/views', partial_path)
end
partials.each do |partial|
generate_partial(partial)
@@ -64,13 +64,13 @@ def partial_path
if !options.path.blank?
path = options.path
else
- path = class_path.join("/")
+ path = File.join(class_path)
end
- path.blank? ? "application" : path
+ path.blank? ? 'application' : path
end
def generate_partial(partial_name)
- template filename_with_extensions(partial_name), File.join("app/views", partial_path, filename_with_extensions(partial_name))
+ template filename_with_extensions(partial_name), File.join('app/views', partial_path, filename_with_extensions(partial_name))
end
end
end
@@ -21,44 +21,44 @@ class AssetsGeneratorTest < Rails::Generators::TestCase
test "html5:assets" do
run_generator
- assert_file "app/assets/stylesheets/_variables.css.scss"
- assert_file "app/assets/stylesheets/application.css.scss", /@import 'application\/document';/
- assert_file "app/assets/stylesheets/application.css.scss", /@import 'application\/media_queries';/
- %w(document media_queries).each do |file|
+ assert_file "app/assets/stylesheets/application/index.css.scss", /@import 'variables';/
+ assert_file "app/assets/stylesheets/application/index.css.scss", /@import 'layout';/
+ assert_file "app/assets/stylesheets/application/index.css.scss", /@import 'media_queries';/
+ %w(variables layout media_queries).each do |file|
assert_file "app/assets/stylesheets/application/#{ file }.css.scss"
end
end
test "html5:assets application" do
run_generator %w(application)
- assert_file "app/assets/stylesheets/_variables.css.scss"
- assert_file "app/assets/stylesheets/application.css.scss", /@import 'application\/document';/
- assert_file "app/assets/stylesheets/application.css.scss", /@import 'application\/media_queries';/
- %w(document media_queries).each do |file|
+ assert_file "app/assets/stylesheets/application/index.css.scss", /@import 'variables';/
+ assert_file "app/assets/stylesheets/application/index.css.scss", /@import 'layout';/
+ assert_file "app/assets/stylesheets/application/index.css.scss", /@import 'media_queries';/
+ %w(variables layout media_queries).each do |file|
assert_file "app/assets/stylesheets/application/#{ file }.css.scss"
end
end
test "html5:assets pancakes" do
run_generator %w(pancakes)
- assert_file "app/assets/stylesheets/_variables.css.scss"
- assert_file "app/assets/stylesheets/pancakes.css.scss", /@import 'pancakes\/document';/
- assert_file "app/assets/stylesheets/pancakes.css.scss", /@import 'pancakes\/media_queries';/
- %w(document media_queries).each do |file|
+ assert_file "app/assets/stylesheets/pancakes/index.css.scss", /@import 'variables';/
+ assert_file "app/assets/stylesheets/pancakes/index.css.scss", /@import 'layout';/
+ assert_file "app/assets/stylesheets/pancakes/index.css.scss", /@import 'media_queries';/
+ %w(variables layout media_queries).each do |file|
assert_file "app/assets/stylesheets/pancakes/#{ file }.css.scss"
end
end
test "html5:assets admin/pancakes" do
run_generator %w(admin/pancakes)
- assert_file "app/assets/stylesheets/_variables.css.scss"
- assert_file "app/assets/stylesheets/admin_pancakes.css.scss", /@import 'admin\/pancakes\/document';/
- assert_file "app/assets/stylesheets/admin_pancakes.css.scss", /@import 'admin\/pancakes\/media_queries';/
- %w(document media_queries).each do |file|
- assert_file "app/assets/stylesheets/admin_pancakes/#{ file }.css.scss"
+ assert_file "app/assets/stylesheets/admin/pancakes/index.css.scss", /@import 'variables';/
+ assert_file "app/assets/stylesheets/admin/pancakes/index.css.scss", /@import 'layout';/
+ assert_file "app/assets/stylesheets/admin/pancakes/index.css.scss", /@import 'media_queries';/
+ %w(variables layout media_queries).each do |file|
+ assert_file "app/assets/stylesheets/admin/pancakes/#{ file }.css.scss"
end
end
end
@@ -45,10 +45,10 @@ class InstallGeneratorTest < Rails::Generators::TestCase
test "assets should be generated" do
run_generator
- assert_file "app/assets/stylesheets/_variables.css.scss"
- assert_file "app/assets/stylesheets/application.css.scss", /@import 'application\/document';/
- assert_file "app/assets/stylesheets/application.css.scss", /@import 'application\/media_queries';/
- %w(document media_queries).each do |file|
+ assert_file "app/assets/stylesheets/application/index.css.scss", /@import 'variables';/
+ assert_file "app/assets/stylesheets/application/index.css.scss", /@import 'layout';/
+ assert_file "app/assets/stylesheets/application/index.css.scss", /@import 'media_queries';/
+ %w(variables layout media_queries).each do |file|
assert_file "app/assets/stylesheets/application/#{ file }.css.scss"
end
end
@@ -67,5 +67,4 @@ class LayoutGeneratorTest < Rails::Generators::TestCase
end
end
end
-
end
@@ -71,5 +71,4 @@ class PartialGeneratorTest < Rails::Generators::TestCase
assert_file "app/views/application/_footer.html.#{ engine }", /Dummy, Copyright/
end
end
-
end

0 comments on commit c88c196

Please sign in to comment.