Skip to content
This repository

Adding support for asset-pipeline (Rails >= 3.1). #77

Open
wants to merge 1 commit into from

1 participant

Ben Wiseley
Ben Wiseley

Add --use-asset-pipeline and assets will be copied to app/assets.

It would have been easy to just check for File.directory?("app/assets") and copy there if it exists - but I added to the --user-asset-pipeline to keep it backwards compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jul 24, 2012
wiseleyb Adding support for asset-pipeline. Add --use-asset-pipeline and asset…
…s will be copied to app/assets
65a5a8a
This page is out of date. Refresh to see the latest.
11 README.rdoc
Source Rendered
@@ -37,6 +37,16 @@ To generate the necessary static files AND the example below:
37 37
38 38 rails generate event_calendar
39 39
  40 +=== Rails >= 3.1
  41 +
  42 +Add this to your Gemfile:
  43 +
  44 + gem 'event-calendar', :require => 'event_calendar'
  45 +
  46 +To generate the necessary static files AND the example below:
  47 +
  48 + rails generate event_calendar --use-asset-pipeline
  49 +
40 50 === Generator Options
41 51
42 52 script/generate event_calendar --help
@@ -45,6 +55,7 @@ To generate the necessary static files AND the example below:
45 55 --use-jquery: Generate jQuery javascript
46 56 --use-mootools: Generate MooTools javascript
47 57 --use-all-day: Include an 'all_day' field on events, and display appropriately
  58 + --use-asset-pipeline: Place js/css in app/assets instead of public. If you're using Rails >= 3.1 you should include this
48 59
49 60 You can change the default event model name (Event) and controller/view name (Calendar) by passing in two name arguments:
50 61
8 generators/event_calendar/USAGE
... ... @@ -1,12 +1,16 @@
1 1 Usage:
2 2
  3 + Rails < 3.0
3 4 script/generate event_calendar [EVENT_MODEL VIEW_NAME]
4 5
  6 + Rails > 3.0
  7 + rails generate event_calendar
  8 +
5 9 This will create:
6 10
7 11 # static files
8   - public/stylesheets/event_calendar.css
9   - public/javascripts/event_calendar.js
  12 + (app/assets|public)/stylesheets/event_calendar.css
  13 + (app/assets|public)public/javascripts/event_calendar.js
10 14
11 15 # Unless --static-only option is given
12 16 # MVC and supporting files (depending on model and view name)
15 generators/event_calendar/event_calendar_generator.rb
@@ -4,7 +4,8 @@ class EventCalendarGenerator < Rails::Generator::Base
4 4 default_options :static_only => false,
5 5 :use_jquery => false,
6 6 :use_all_day => false,
7   - :use_mootools => false
  7 + :use_mootools => false,
  8 + :use_asset_pipeline => false
8 9
9 10 attr_reader :class_name, :view_name
10 11
@@ -18,10 +19,11 @@ def initialize(args, runtime_options = {})
18 19 def manifest
19 20 record do |m|
20 21 # static files
21   - m.file "stylesheet.css", "public/stylesheets/event_calendar.css"
  22 + raise public_folder
  23 + m.file "stylesheets.css", "#{public_folder}/stylesheets/event_calendar.css"
22 24
23 25 script = options[:use_jquery] ? 'jq_javascript.js' : (options[:use_mootools] ? 'mt_javascript.js' : 'javascript.js')
24   - m.file script, "public/javascripts/event_calendar.js"
  26 + m.file script, "#{public_folder}/javascripts/event_calendar.js"
25 27
26 28 # MVC and other supporting files
27 29 unless options[:static_only]
@@ -49,5 +51,12 @@ def add_options!(opt)
49 51 end
50 52 opt.on("--use-all-day",
51 53 "Include an 'all_day' field on events, and display appropriately.") { |v| options[:use_all_day] = v }
  54 + opt.on("--use-asset_pipeline",
  55 + "Place js/css in app/assets instead of public") { |v| options[:use_asset_pipeline] = v}
52 56 end
  57 +
  58 + def public_folder
  59 + options[:use_asset_pipeline] ? "app/assets" : "public"
  60 + end
  61 +
53 62 end
15 lib/generators/event_calendar/event_calendar_generator.rb
@@ -14,23 +14,24 @@ class EventCalendarGenerator < Rails::Generators::Base
14 14 end
15 15 class_option :use_all_day, :type => :boolean, :default => false, :desc => "Add an additional 'all_day' attribute"
16 16 class_option :use_color, :type => :boolean, :default => false, :desc => "Add an additional 'color' attribute"
  17 + class_option :use_asset_pipeline, :type => :boolean, :default => false, :desc => "Place assets in app/assets instead of public folder"
17 18
18 19 def do_it
19 20 say "Adding an all_day column", :yellow if options[:use_all_day]
20 21 say "Adding a color column", :yellow if options[:use_color]
21   -
  22 + say "Placing js/css in app/assets", :yellow if options[:use_asset_pipeline]
22 23 if options[:use_jquery]
23 24 say "Using jQuery for scripting", :yellow
24   - copy_file 'jq_javascript.js', "public/javascripts/event_calendar.js"
  25 + copy_file 'jq_javascript.js', "#{public_folder}/javascripts/event_calendar.js"
25 26 elsif options[:use_mootools]
26 27 say "Using MooTools for scripting", :yellow
27   - copy_file "mt_javascript.js", "public/javascripts/event_calendar.js"
  28 + copy_file "mt_javascript.js", "#{public_folder}/javascripts/event_calendar.js"
28 29 else
29 30 say "Using Prototype for scripting", :yellow
30   - copy_file 'javascript.js', "public/javascripts/event_calendar.js"
  31 + copy_file 'javascript.js', "#{public_folder}/javascripts/event_calendar.js"
31 32 end
32 33
33   - copy_file "stylesheet.css", "public/stylesheets/event_calendar.css"
  34 + copy_file "stylesheet.css", "#{public_folder}/stylesheets/event_calendar.css"
34 35
35 36 unless options.static_only?
36 37 template "model.rb.erb", "app/models/#{model_name}.rb"
@@ -44,6 +45,10 @@ def do_it
44 45
45 46 end
46 47
  48 + def public_folder
  49 + options[:use_asset_pipeline] ? "app/assets" : "public"
  50 + end
  51 +
47 52 def model_class_name
48 53 @model_name.classify
49 54 end

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.