Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

separate configs #548

Merged
merged 1 commit into from

4 participants

@nashby
Collaborator

closes #544

@travisbot

This pull request passes (merged dc73dc58 into 767dfae).

@rafaelfranca

@nashby I guess you get the @carlosantoniodasilva idea wrong. He want to split the config in two files. But in the bootstrap file he want to put only the bootstrap config. So when you install with the bootstrap option it will copy both files to your application,

@carlosantoniodasilva
Collaborator

@nashby great and fast, thanks :).

I just think I may have not made myself clear enough while trying to explain the two possibilities, sorry about that. The second option, at least in my mind, was to create a separate file, ie simple_form_bootstrap.rb, which would contain only bootstrap specific configs, and we'd stick with the default configs in simple_form.rb, which means we'd have to copy both config files to the app - the default, and the overrides. As they're loaded in order, the bootstrap one would override the defaults.

What do you think about that approach? And thanks for your quick work on that :)

ps: omg you have no beard :D

@carlosantoniodasilva
Collaborator

@rafaelfranca ops, faster than me bro :P

@rafaelfranca

hahahhaha. I win. BTW. Thanks so much to work on it. And remember guys, lets wait the minor release before merge this PR.

@nashby
Collaborator

@carlosantoniodasilva aaah, I see. So about 'loaded in order'. How do we now this order? Or is it just alphabetic order?
ps. yeah, no beard :(

@carlosantoniodasilva
Collaborator

@nashby initializers inside config/initializers are loaded in alphabetical order, so we can take advantage of that in this case.

@nashby
Collaborator

@carlosantoniodasilva I've updated PR.
BTW, according to the documentation on Thor template method should work like

template "config/initializers/simple_form.rb.tt"

but it doesn't. Do somebody know what the problem is?

test/generators/simple_form_generator_test.rb
@@ -19,7 +19,7 @@ class SimpleFormGeneratorTest < Rails::Generators::TestCase
test 'generates the simple_form initializer with the bootstrap wrappers' do
run_generator %w(--bootstrap)
- assert_file 'config/initializers/simple_form.rb', /config\.wrappers :bootstrap/,
+ assert_file 'config/initializers/simple_form_bootstrap.rb', /config\.wrappers :bootstrap/,
@rafaelfranca Owner

Can we assert both files?

@nashby Collaborator
nashby added a note

Sure thing!

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

@nashby I think that it works but if the destination and the source will have the same name. Look the code of the method.

def template(source, *args, &block)
  config = args.last.is_a?(Hash) ? args.pop : {}
  destination = args.first || source

  source  = File.expand_path(find_in_source_paths(source.to_s))
  context = instance_eval('binding')

  create_file destination, nil, config do
    content = ERB.new(::File.binread(source), nil, '-', '@output_buffer').result(context)
    content = block.call(content) if block
    content
  end
end
@nashby
Collaborator

@rafaelfranca according to the doc:

If the destination is not given it’s assumed to be equal to the source removing .tt from the filename.

so

template "config/initializers/simple_form.rb.tt"

should copy simple_form.rb to config/initializers right? But it doesn't. :sweat:

@rafaelfranca

@nashby maybe the in version that we are using this method is bugged. I saw the master branch and it seems to move the .tt files.

def template(source, *args, &block)
      config = args.last.is_a?(Hash) ? args.pop : {}
      destination = args.first || source.sub(/\.tt$/, '')

      source  = File.expand_path(find_in_source_paths(source.to_s))
      context = instance_eval('binding')

      create_file destination, nil, config do
        content = ERB.new(::File.binread(source), nil, '-', '@output_buffer').result(context)
        content = block.call(content) if block
        content
      end
    end
@nashby
Collaborator
@carlosantoniodasilva
Collaborator

@nashby what happens if your source template does not contain the .tt? Like:

template "config/initalizers/simple_form.rb"

Perhaps that's the idea ^^

@nashby
Collaborator

@carlosantoniodasilva yes, without .tt it works. So should I rename configs?

@carlosantoniodasilva
Collaborator

For it to work you just removed the .tt from the template call, or you had to rename the file as well? I wonder if that just works with the template call change, so no need to rename.

@nashby
Collaborator

@carlosantoniodasilva no, I need to rename templates too to make it work.

@carlosantoniodasilva
Collaborator

I think it's fine, if all works well :).. @rafaelfranca ok?

@rafaelfranca
@carlosantoniodasilva
Collaborator

@nashby awesome, thanks :)

Now, we just have to wait for the minor release to merge it.

@rafaelfranca rafaelfranca merged commit 63a29bc into plataformatec:master
@rafaelfranca
Owner

Merged. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 24, 2012
  1. @nashby

    separate configs, closes #544

    nashby authored
This page is out of date. Refresh to see the latest.
View
8 lib/generators/simple_form/install_generator.rb
@@ -14,7 +14,13 @@ def info_bootstrap
end
def copy_config
- directory 'config'
+ template "config/initializers/simple_form.rb"
+
+ if options[:bootstrap]
+ template "config/initializers/simple_form_bootstrap.rb"
+ end
+
+ directory 'config/locales'
end
def copy_scaffold_template
View
45 ...m/templates/config/initializers/simple_form.rb.tt → ...form/templates/config/initializers/simple_form.rb
@@ -44,53 +44,10 @@
b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
b.use :error, :wrap_with => { :tag => :span, :class => :error }
end
-<% if options.bootstrap? %>
- config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
- b.use :html5
- b.use :placeholder
- b.use :label
- b.wrapper :tag => 'div', :class => 'controls' do |ba|
- ba.use :input
- ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
- ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' }
- end
- end
-
- config.wrappers :prepend, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
- b.use :html5
- b.use :placeholder
- b.use :label
- b.wrapper :tag => 'div', :class => 'controls' do |input|
- input.wrapper :tag => 'div', :class => 'input-prepend' do |prepend|
- prepend.use :input
- end
- input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
- input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
- end
- end
-
- config.wrappers :append, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
- b.use :html5
- b.use :placeholder
- b.use :label
- b.wrapper :tag => 'div', :class => 'controls' do |input|
- input.wrapper :tag => 'div', :class => 'input-append' do |append|
- append.use :input
- end
- input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
- input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
- end
- end
- # Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
- # Check the Bootstrap docs (http://twitter.github.com/bootstrap)
- # to learn about the different styles for forms and inputs,
- # buttons and other elements.
- config.default_wrapper = :bootstrap
-<% else %>
# The default wrapper to be used by the FormBuilder.
config.default_wrapper = :default
-<% end %>
+
# Define the way to render check boxes / radio buttons with labels.
# Defaults to :nested for bootstrap config.
# :inline => input + label
View
45 lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb
@@ -0,0 +1,45 @@
+# Use this setup block to configure all options available in SimpleForm.
+SimpleForm.setup do |config|
+ config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
+ b.use :html5
+ b.use :placeholder
+ b.use :label
+ b.wrapper :tag => 'div', :class => 'controls' do |ba|
+ ba.use :input
+ ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
+ ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' }
+ end
+ end
+
+ config.wrappers :prepend, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
+ b.use :html5
+ b.use :placeholder
+ b.use :label
+ b.wrapper :tag => 'div', :class => 'controls' do |input|
+ input.wrapper :tag => 'div', :class => 'input-prepend' do |prepend|
+ prepend.use :input
+ end
+ input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
+ input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
+ end
+ end
+
+ config.wrappers :append, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
+ b.use :html5
+ b.use :placeholder
+ b.use :label
+ b.wrapper :tag => 'div', :class => 'controls' do |input|
+ input.wrapper :tag => 'div', :class => 'input-append' do |append|
+ append.use :input
+ end
+ input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
+ input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
+ end
+ end
+
+ # Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
+ # Check the Bootstrap docs (http://twitter.github.com/bootstrap)
+ # to learn about the different styles for forms and inputs,
+ # buttons and other elements.
+ config.default_wrapper = :bootstrap
+end
View
4 test/generators/simple_form_generator_test.rb
@@ -19,7 +19,9 @@ class SimpleFormGeneratorTest < Rails::Generators::TestCase
test 'generates the simple_form initializer with the bootstrap wrappers' do
run_generator %w(--bootstrap)
- assert_file 'config/initializers/simple_form.rb', /config\.wrappers :bootstrap/,
+ assert_file 'config/initializers/simple_form.rb',
+ /config\.default_wrapper = :default/, /config\.boolean_style = :nested/
+ assert_file 'config/initializers/simple_form_bootstrap.rb', /config\.wrappers :bootstrap/,
/config\.default_wrapper = :bootstrap/
end
Something went wrong with that request. Please try again.