Kristian Mandrup
2010-Jan-30 20:25 UTC
Request: newline missing in emfile when using gem statement in Rails 3 templates
When I use the Rails templates features and use the gem statemtent, the gems in the Gemfile end up being appended without a newline like the following: mytemplate.rb -- gem "rspec" gem "cucumber" gem "cucumber-rails" --> Gemfile gem "rspec"gem "cucumber"gem "cucumber-rails" -- Not very pretty! Where can I help improve Rails templates? I''m currently working on some templates myself... http://github.com/kristianmandrup/rails3-templates -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Kristian Mandrup
2010-Jan-30 20:57 UTC
Re: Request: newline missing in emfile when using gem statement in Rails 3 templates
Found it in rails/railties/lib/rails/generators/actions.rb
def gem(..)
...
in_root do
append_file "Gemfile", "gem #{parts.join(",
")}", :verbose =>
false
end
Should add a newline!
append_file "Gemfile", "gem #{parts.join(",
")}\n", :verbose => false
Or perhaps extend with a new utility function:
def append_line_file(file, txt, *args)
append_file file, "#{txt}\n", args
end
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-core+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.
Kristian Mandrup
2010-Jan-30 21:02 UTC
Re: Request: newline missing in emfile when using gem statement in Rails 3 templates
I propose the following fix:
module Thor
class Actions
def append_line_file(file, txt, *args)
append_file file, "#{txt}\n", args
end
end
end
module Rails
module Generators
module Actions
def gem(*args)
options = args.extract_options!
name, version = args
# Deal with deprecated options
{ :env => :only, :lib => :require_as }.each do |old, new|
next unless options[old]
options[new] = options.delete(old)
ActiveSupport::Deprecation.warn "#{old.inspect} option in
gem is deprecated, use #{new.inspect} instead"
end
# Deal with deprecated source
if source = options.delete(:source)
ActiveSupport::Deprecation.warn ":source option in gem is
deprecated, use add_source method instead"
add_source(source)
end
# Set the message to be shown in logs. Uses the git repo if
one is given,
# otherwise use name (version).
parts, message = [ name.inspect ], name
if version ||= options.delete(:version)
parts << version
message << " (#{version})"
end
message = options[:git] if options[:git]
log :gemfile, message
options.each do |option, value|
parts << ":#{option} => #{value.inspect}"
end
in_root do
append_line_file "Gemfile", "gem #{parts.join(",
")}", :verbose => false
end
end
end
end
end
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-core+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.