Skip to content

Commit

Permalink
shifted Formtastic::LayoutHelper to Formtastic::Helpers::LayoutHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfrench committed Jan 19, 2011
1 parent 899ce96 commit 56d6558
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 19 deletions.
4 changes: 2 additions & 2 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# encoding: utf-8
require 'formtastic'
require 'formtastic/layout_helper'
require 'formtastic/helpers/layout_helper'
ActionView::Base.send :include, Formtastic::SemanticFormHelper
ActionView::Base.send :include, Formtastic::LayoutHelper
ActionView::Base.send :include, Formtastic::Helpers::LayoutHelper
14 changes: 14 additions & 0 deletions lib/formtastic/helpers/layout_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# encoding: utf-8

module Formtastic
module Helpers
module LayoutHelper

def formtastic_stylesheet_link_tag
stylesheet_link_tag("formtastic") +
stylesheet_link_tag("formtastic_changes")
end

end
end
end
52 changes: 52 additions & 0 deletions lib/formtastic/helpers/support/fieldset_wrapper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module Formtastic
module Helpers
module Support
module FieldsetWrapper

protected

# Generates a fieldset and wraps the content in an ordered list. When working
# with nested attributes, it allows %i as interpolation option in :name. So you can do:
#
# f.inputs :name => 'Task #%i', :for => :tasks
#
# or the shorter equivalent:
#
# f.inputs 'Task #%i', :for => :tasks
#
# And it will generate a fieldset for each task with legend 'Task #1', 'Task #2',
# 'Task #3' and so on.
#
# Note: Special case for the inline inputs (non-block):
# f.inputs "My little legend", :title, :body, :author # Explicit legend string => "My little legend"
# f.inputs :my_little_legend, :title, :body, :author # Localized (118n) legend with I18n key => I18n.t(:my_little_legend, ...)
# f.inputs :title, :body, :author # First argument is a column => (no legend)
def field_set_and_list_wrapping(*args, &block) #:nodoc:
contents = args.last.is_a?(::Hash) ? '' : args.pop.flatten
html_options = args.extract_options!

legend = html_options.dup.delete(:name).to_s
legend %= parent_child_index(html_options[:parent]) if html_options[:parent]
legend = template.content_tag(:legend, template.content_tag(:span, Formtastic::Util.html_safe(legend))) unless legend.blank?

if block_given?
contents = if template.respond_to?(:is_haml?) && template.is_haml?
template.capture_haml(&block)
else
template.capture(&block)
end
end

# Ruby 1.9: String#to_s behavior changed, need to make an explicit join.
contents = contents.join if contents.respond_to?(:join)
fieldset = template.content_tag(:fieldset,
Formtastic::Util.html_safe(legend) << template.content_tag(:ol, Formtastic::Util.html_safe(contents)),
html_options.except(:builder, :parent)
)

fieldset
end
end
end
end
end
12 changes: 0 additions & 12 deletions lib/formtastic/layout_helper.rb

This file was deleted.

4 changes: 2 additions & 2 deletions lib/formtastic/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# encoding: utf-8

require 'formtastic'
require 'formtastic/layout_helper'
require 'formtastic/helpers/layout_helper'
require 'rails'

module Formtastic
class Railtie < Rails::Railtie
initializer 'formtastic.initialize', :after => :after_initialize do
ActionView::Base.send :include, Formtastic::SemanticFormHelper
ActionView::Base.send(:include, Formtastic::LayoutHelper)
ActionView::Base.send(:include, Formtastic::Helpers::LayoutHelper)
end
end
end
4 changes: 2 additions & 2 deletions spec/helpers/layout_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# encoding: utf-8
require 'spec_helper'

describe Formtastic::LayoutHelper do
describe Formtastic::Helpers::LayoutHelper do

include FormtasticSpecHelper
include Formtastic::LayoutHelper
include Formtastic::Helpers::LayoutHelper

describe '#formtastic_stylesheet_link_tag' do

Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

require File.expand_path(File.join(File.dirname(__FILE__), '../lib/formtastic/util'))
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/formtastic'))
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/formtastic/layout_helper'))
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/formtastic/helpers/layout_helper'))

# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories in alphabetic order.
Expand Down

0 comments on commit 56d6558

Please sign in to comment.