Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define generators for Rails's assets pipeline #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions lib/generators/apotomo/widget_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,34 @@ module BasePathMethods
def base_path
File.join('app/widgets', class_path, file_name)
end

def js_path
File.join('app/assets/javascripts/widgets', class_path, file_name)
end

def css_path
File.join('app/assets/stylesheets/widgets', class_path, file_name)
end
end

class WidgetGenerator < ::Cells::Generators::Base
include BasePathMethods

source_root File.expand_path('../../templates', __FILE__)

hook_for(:template_engine)
hook_for(:test_framework) # TODO: implement rspec-apotomo.

check_class_collision :suffix => "Widget"



def create_cell_file
template 'widget.rb', "#{base_path}_widget.rb"
end

def create_assets_files
template 'widget.coffee', "#{js_path}_widget.coffee"
template 'widget.css', "#{css_path}_widget.css"
end
end
end
end
1 change: 1 addition & 0 deletions lib/generators/templates/widget.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Define your coffeescript code for the <%= class_name %> widget
1 change: 1 addition & 0 deletions lib/generators/templates/widget.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*Define your css code for the <%= class_name %> widget*/
23 changes: 15 additions & 8 deletions test/rails/widget_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ class WidgetGeneratorTest < Rails::Generators::TestCase
destination File.join(Rails.root, "tmp")
setup :prepare_destination
tests ::Apotomo::Generators::WidgetGenerator

context "Running rails g apotomo::widget" do
context "Gerbil squeak snuggle" do
should "create the standard assets" do

run_generator %w(Gerbil squeak snuggle -t test_unit)

assert_file "app/widgets/gerbil_widget.rb", /class GerbilWidget < Apotomo::Widget/
assert_file "app/widgets/gerbil_widget.rb", /def snuggle/
assert_file "app/widgets/gerbil_widget.rb", /def squeak/
Expand All @@ -22,10 +22,17 @@ class WidgetGeneratorTest < Rails::Generators::TestCase
assert_file "test/widgets/gerbil_widget_test.rb", %r(class GerbilWidgetTest < Apotomo::TestCase)
assert_file "test/widgets/gerbil_widget_test.rb", %r(widget\(:gerbil\))
end


should "create javascript and css assets" do
run_generator %w(Gerbil squeak snuggle -t test_unit)

assert_file "app/assets/javascripts/widgets/gerbil_widget.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*/
end

should "create haml assets with -e haml" do
run_generator %w(Gerbil squeak snuggle -e haml -t test_unit)

assert_file "app/widgets/gerbil_widget.rb", /class GerbilWidget < Apotomo::Widget/
assert_file "app/widgets/gerbil_widget.rb", /def snuggle/
assert_file "app/widgets/gerbil_widget.rb", /def squeak/
Expand All @@ -37,7 +44,7 @@ class WidgetGeneratorTest < Rails::Generators::TestCase

should "create slim assets with -e slim" do
run_generator %w(Gerbil squeak snuggle -e slim -t test_unit)

assert_file "app/widgets/gerbil_widget.rb", /class GerbilWidget < Apotomo::Widget/
assert_file "app/widgets/gerbil_widget.rb", /def snuggle/
assert_file "app/widgets/gerbil_widget.rb", /def squeak/
Expand All @@ -46,7 +53,7 @@ class WidgetGeneratorTest < Rails::Generators::TestCase
assert_file "app/widgets/gerbil/squeak.html.slim", %r(app/widgets/gerbil/squeak\.html\.slim)
assert_file "test/widgets/gerbil_widget_test.rb"
end

should "work with namespaces" do
run_generator %w(Gerbil::Mouse squeak -t test_unit)

Expand All @@ -55,7 +62,7 @@ class WidgetGeneratorTest < Rails::Generators::TestCase
assert_file "app/widgets/gerbil/mouse/squeak.html.erb", %r(app/widgets/gerbil/mouse/squeak\.html\.erb)
assert_file "test/widgets/gerbil/mouse_widget_test.rb"
end

end
end
end