Permalink
Browse files

allow stylesheet lang option on generator

  • Loading branch information...
1 parent 9a9b9cd commit 1607f5787fdac80579c3d9de074702b75eccebbf @kristianmandrup committed Sep 10, 2012
@@ -62,21 +62,27 @@ class WidgetGenerator < ::Cells::Generators::Base
check_class_collision :suffix => "Widget"
- class_option :js, :type => :boolean, :default => false, :desc => 'Generate javascript asset file'
+ class_option :js, :type => :boolean, :default => false, :desc => 'Generate javascript asset file'
+ class_option :style, :type => :string, :default => 'scss', :desc => 'Style language to use: css, scss or sass'
def create_cell_file
template 'widget.rb', File.join(base_path, "#{file_name}_widget.rb")
end
def create_stylesheet_file
- template 'widget.css', "#{css_path}_widget.css"
+ if scss?
+ template 'widget.scss', "#{css_path}_widget.css.scss"
+ elsif sass?
+ template 'widget.sass', "#{css_path}_widget.css.sass"
+ else
+ template 'widget.css', "#{css_path}_widget.css"
+ end
end
def create_script_file
puts "create_script_file"
- if !javascript?
- # raise "coffee: #{js_path}_widget.js.coffee"
- template 'widget.js.coffee', "#{js_path}_widget.js.coffee"
+ if coffee?
+ template 'widget.coffee', "#{js_path}_widget.js.coffee"
else
puts "js: #{js_path}_widget.js"
template 'widget.js', "#{js_path}_widget.js"
@@ -97,6 +103,26 @@ def js_camelize str
str.camelize.sub(/^\w/, str[0].downcase)
end
+ def style
+ options[:style].to_s.downcase
+ end
+
+ def sass?
+ style == 'sass'
+ end
+
+ def scss?
+ style == 'scss'
+ end
+
+ def css?
+ style == 'css'
+ end
+
+ def coffee?
+ !javascript?
+ end
+
def javascript?
options[:js] == true
end
@@ -1 +1 @@
-/* Define your css code for the <%= class_name %> widget */
+/* Define your CSS code for the <%= class_name %> widget */
@@ -0,0 +1 @@
+/* Define your SASS code for the <%= class_name %> widget */
@@ -0,0 +1 @@
+/* Define your SCSS code for the <%= class_name %> widget */
@@ -24,18 +24,24 @@ class WidgetGeneratorTest < Rails::Generators::TestCase
assert_file "test/widgets/gerbil/gerbil_widget_test.rb", %r(widget\(:gerbil\))
end
- should "create coffescript and css assets" do
+ should "create coffescript and scss assets" do
run_generator %w(Gerbil squeak snuggle -t test_unit)
assert_file "app/assets/javascripts/widgets/gerbil_widget.js.coffee", /Define your coffeescript code for the Gerbil widget*/
- assert_file "app/assets/stylesheets/widgets/gerbil_widget.css", /Define your css code for the Gerbil widget*/
+ assert_file "app/assets/stylesheets/widgets/gerbil_widget.css.scss", /Define your SCSS code for the Gerbil widget*/
end
should "create javascript and css assets" do
- run_generator %w(Gerbil squeak snuggle -t test_unit --js)
+ run_generator %w(Gerbil squeak snuggle -t test_unit --js --style css)
assert_file "app/assets/javascripts/widgets/gerbil_widget.js", /Define your javascript code for the Gerbil widget*/
- assert_file "app/assets/stylesheets/widgets/gerbil_widget.css", /Define your css code for the Gerbil widget*/
+ assert_file "app/assets/stylesheets/widgets/gerbil_widget.css", /Define your CSS code for the Gerbil widget*/
+ end
+
+ should "create javascript and sass assets" do
+ run_generator %w(Gerbil squeak snuggle -t test_unit --js --style sass)
+
+ assert_file "app/assets/stylesheets/widgets/gerbil_widget.css.sass", /Define your SASS code for the Gerbil widget*/
end
should "create haml assets with -e haml" do

0 comments on commit 1607f57

Please sign in to comment.