lib/tiny-rails/actions.rb in tiny-rails-0.0.2 vs lib/tiny-rails/actions.rb in tiny-rails-0.1.0
- old
+ new
@@ -30,39 +30,56 @@
str = "\n" + str
append_file "Gemfile", str, :verbose => false
end
end
- # Adds a line inside the Application class on boot.rb.
+ # Appends a line inside the TinyRailsApp class on boot.rb.
#
# application do
# "config.assets.enabled = true"
# end
def application(data=nil, &block)
- sentinel = /class TinyRailsApp < Rails::Application/i
data = block.call if !data && block_given?
- inject_into_file 'boot.rb', "\n #{data}", :after => sentinel
+ data = "\n#{data}" unless data =~ /^\n/
+ data << "\n" unless data =~ /\n$/
+
+ inject_into_file 'boot.rb', data, :after => /^ config\.secret_token = .+\n/
end
def initializer(data)
+ data = open(data) { |io| io.read } if data =~ /https?:\/\//
+
if File.exists? 'initializers.rb'
append_file 'initializers.rb', "\n#{data}"
else
create_file 'initializers.rb', data
end
end
+ def migration(data)
+ data << "\n" unless data =~ /\n$/
+
+ inject_into_file 'migrate', data, :after => /^ActiveRecord::Schema\.define do\n/
+ end
+
+ def route(new_route)
+ new_route << "\n" unless new_route =~ /\n$/
+
+ inject_into_file 'boot.rb', new_route, :after => /TinyRailsApp\.routes\.draw do\n/
+ end
+
# Self explanatory :P
def enable_asset_pipeline!
return if File.read('boot.rb') =~ /^ config\.assets\.enabled = true$/
- code = <<-CONFIG
+ application <<-CONFIG
+ # Enable asset pipeline
config.assets.enabled = true
config.assets.debug = true
config.assets.paths << File.dirname(__FILE__)
CONFIG
- application "\n#{code}"
+ inject_into_file 'boot.rb', "\nrequire \"sprockets/railtie\"", :after => /require ['"]action_controller\/railtie['"]/
end
def addon(path)
path = if URI(path).is_a?(URI::HTTP)
path