rapid-core 0.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile.lock +35 -2
  3. data/Rakefile +77 -48
  4. data/doc/server.txt +15 -0
  5. data/features/settings/double-nested/default.feature +2 -2
  6. data/features/settings/double-nested/validates/presence_of.feature +1 -1
  7. data/features/settings/nested/default.feature +1 -1
  8. data/features/settings/nested/validates/presence_of.feature +1 -1
  9. data/features/settings/not_found.feature +2 -2
  10. data/features/step_definitions/settings_steps.rb +7 -3
  11. data/features/step_definitions/template_steps.rb +3 -1
  12. data/lib/rapid/check.rb +30 -23
  13. data/lib/rapid/core.rb +12 -0
  14. data/lib/rapid/error.rb +1 -0
  15. data/lib/rapid/module.rb +10 -1
  16. data/lib/rapid/railtie.rb +6 -0
  17. data/lib/rapid/setting/base.rb +31 -8
  18. data/lib/rapid/setting/boolean_setting.rb +20 -1
  19. data/lib/rapid/setting/definer.rb +11 -47
  20. data/lib/rapid/setting/integer_setting.rb +7 -7
  21. data/lib/rapid/setting/module.rb +56 -0
  22. data/lib/rapid/setting/namespace/base.rb +35 -60
  23. data/lib/rapid/setting/namespace/instance.rb +195 -28
  24. data/lib/rapid/setting/string_setting.rb +7 -1
  25. data/lib/rapid/settings.rb +51 -65
  26. data/lib/rapid/skeleton/base.rb +39 -18
  27. data/lib/rapid/skeleton/helpers/directory.rb +5 -6
  28. data/lib/rapid/skeleton/helpers/files.rb +62 -0
  29. data/lib/rapid/skeleton/helpers/gem.rb +43 -32
  30. data/lib/rapid/skeleton/helpers/if_setting.rb +44 -0
  31. data/lib/rapid/skeleton/helpers/migration.rb +102 -32
  32. data/lib/rapid/skeleton/helpers/route.rb +8 -12
  33. data/lib/rapid/skeleton/helpers/script.rb +1 -2
  34. data/lib/rapid/skeleton/helpers/template.rb +23 -25
  35. data/lib/rapid/skeleton/helpers/view.rb +7 -7
  36. data/lib/rapid/spec/template.rb +1 -1
  37. data/lib/rapid/version.rb +1 -1
  38. data/lib/rapid/web/base.rb +35 -0
  39. data/lib/rapid/web/bootstrap.rb +98 -0
  40. data/lib/rapid/web/controller_helpers.rb +60 -0
  41. data/lib/rapid/web/navigator.rb +18 -0
  42. data/lib/rapid/web/select_helpers.rb +63 -0
  43. data/lib/rapid/web/settings_form_builder.rb +205 -0
  44. data/lib/rapid/web/static_helpers.rb +28 -0
  45. data/lib/rapid/web/tasks.rb +10 -0
  46. data/public/rapid/core/bootstrap-collapse.js +136 -0
  47. data/public/rapid/core/bootstrap-responsive.min.css +3 -0
  48. data/public/rapid/core/bootstrap.min.css +556 -0
  49. data/public/rapid/core/jquery-1.7.1.js +9253 -0
  50. data/public/rapid/core/prettify.css +30 -0
  51. data/public/rapid/core/prettify.js +28 -0
  52. data/rapid-core.gemspec +5 -0
  53. data/spec/rapid/check_spec.rb +11 -4
  54. data/spec/rapid/module_spec.rb +18 -0
  55. data/spec/rapid/setting/base_spec.rb +71 -0
  56. data/spec/rapid/setting/boolean_setting_spec.rb +95 -0
  57. data/spec/rapid/setting/definer_spec.rb +7 -13
  58. data/spec/rapid/setting/integer_setting_spec.rb +49 -0
  59. data/spec/rapid/setting/module_spec.rb +25 -0
  60. data/spec/rapid/setting/namespace/base_spec.rb +88 -54
  61. data/spec/rapid/setting/namespace/instance_spec.rb +308 -5
  62. data/spec/rapid/setting/string_setting_spec.rb +43 -0
  63. data/spec/rapid/settings_spec.rb +65 -17
  64. data/spec/rapid/skeleton/base_spec.rb +113 -7
  65. data/spec/rapid/skeleton/helpers/directory_spec.rb +8 -6
  66. data/spec/rapid/skeleton/helpers/files_spec.rb +93 -0
  67. data/spec/rapid/skeleton/helpers/gem_spec.rb +65 -36
  68. data/spec/rapid/skeleton/helpers/if_setting_spec.rb +110 -0
  69. data/spec/rapid/skeleton/helpers/migration_spec.rb +190 -1
  70. data/spec/rapid/skeleton/helpers/route_spec.rb +13 -12
  71. data/spec/rapid/skeleton/helpers/script_spec.rb +2 -1
  72. data/spec/rapid/skeleton/helpers/template_spec.rb +22 -35
  73. data/spec/rapid/spec/template_spec.rb +1 -1
  74. data/spec/rapid/web/base_spec.rb +33 -0
  75. data/spec/rapid/web/bootstrap_spec.rb +72 -0
  76. data/spec/rapid/web/controller_helpers_spec.rb +86 -0
  77. data/spec/rapid/web/navigator_spec.rb +17 -0
  78. data/spec/rapid/web/select_helpers_spec.rb +71 -0
  79. data/spec/rapid/web/settings_form_builder_spec.rb +255 -0
  80. data/spec/rapid/web/static_helpers_spec.rb +26 -0
  81. data/spec/spec_helper.rb +3 -0
  82. data/views/index.erb +11 -0
  83. data/views/layout.erb +9 -0
  84. metadata +107 -12
  85. data/lib/rapid.rb +0 -37
  86. data/lib/rapid/setting/class_hash.rb +0 -34
  87. data/lib/rapid/setting/instance_hash.rb +0 -132
  88. data/lib/rapid/setting/instance_root.rb +0 -107
  89. data/spec/rapid/setting/instance_root_spec.rb +0 -161
@@ -18,8 +18,7 @@ module Rapid
18
18
  push_template script_path, options
19
19
 
20
20
  output_path = options[:to] || script_path
21
- full_output_path = File.join project_path, output_path
22
- File.chmod 0755, full_output_path
21
+ chmod_project_file 0755, output_path if project_file_exists?(output_path)
23
22
  end
24
23
 
25
24
  def pull_script script_path, options = {}
@@ -15,54 +15,52 @@ module Rapid
15
15
  end
16
16
 
17
17
  def push_template template_path, options = {}
18
- if_setting = options[:if]
19
- return false if if_setting && !set?(if_setting)
20
-
21
- full_template_path = File.join templates_path, template_path
22
- template_content = File.open(full_template_path) { |f| f.read }
23
- template = Rapid::Template::Base.new template_content, :filename => template_path
24
-
25
18
  output_path = options[:to] || template_path
26
- full_output_path = File.join project_path, output_path
27
19
 
28
- output_content = template.push self
29
- FileUtils.mkdir_p File.dirname(full_output_path)
30
- File.open(full_output_path, 'w') { |f| f.write output_content }
20
+ if if_setting_off? options
21
+ delete_project_file output_path
22
+
23
+ else
24
+ template_content = read_template_file template_path
25
+ template = Rapid::Template::Base.new template_content, :filename => template_path
26
+
27
+ output_content = template.push self
28
+ write_project_file output_path, output_content
29
+ end
31
30
 
32
31
  true
33
-
34
- rescue Errno::ENOENT => e
35
- raise Rapid::TemplateNotFoundError.new(e.message)
36
32
  end
37
33
 
38
34
  def pull_template template_path, options = {}
39
- if_setting = options[:if]
40
-
41
- full_template_path = File.join templates_path, template_path
42
- template_content = File.open(full_template_path) { |f| f.read }
35
+ template_content = read_template_file template_path
43
36
  template = Rapid::Template::Base.new template_content, :filename => template_path
44
37
 
45
38
  output_path = options[:to] || template_path
46
- full_output_path = File.join project_path, output_path
47
39
 
48
- unless File.exists? full_output_path
49
- if if_setting
50
- self[if_setting] = false
40
+ unless project_file_exists?(output_path)
41
+ if has_if_setting? options
42
+ if_set! false, options
51
43
  else
52
44
  error output_path, "doesn't exist"
53
45
  end
54
46
  return
55
47
  end
56
48
 
57
- output_content = File.open(full_output_path) { |f| f.read }
49
+ output_content = read_project_file output_path
50
+ result = nil
58
51
  begin
59
- template.pull output_content
52
+ result = template.pull output_content
60
53
  rescue Rapid::NotMatchingTemplateError => e
61
54
  exception output_path, e
62
55
  return
63
56
  end
64
57
 
65
- self[if_setting] = true if if_setting
58
+ if_set! true, options
59
+
60
+ result.each do |key, value|
61
+ self[key] = value
62
+ end
63
+
66
64
  ok output_path, "is good"
67
65
  end
68
66
 
@@ -6,26 +6,26 @@ module Rapid
6
6
 
7
7
  protected
8
8
 
9
- def view view_path
9
+ def view view_path, options = {}
10
10
  if pushing?
11
- push_view view_path
11
+ push_view view_path, options
12
12
  elsif pulling?
13
- pull_view view_path
13
+ pull_view view_path, options
14
14
  end
15
15
  end
16
16
 
17
- def push_view view_path
17
+ def push_view view_path, options
18
18
  template_path = File.join 'app', 'views', view_path
19
19
  rapid_view_path = File.join 'lib', 'rapid', 'views', view_path
20
20
 
21
- push_template template_path, :to => rapid_view_path
21
+ push_template template_path, options.reverse_merge(:to => rapid_view_path)
22
22
  end
23
23
 
24
- def pull_view view_path
24
+ def pull_view view_path, options
25
25
  template_path = File.join 'app', 'views', view_path
26
26
  rapid_view_path = File.join 'lib', 'rapid', 'views', view_path
27
27
 
28
- pull_template template_path, :to => rapid_view_path
28
+ pull_template template_path, options.reverse_merge(:to => rapid_view_path)
29
29
  end
30
30
 
31
31
  end
@@ -35,7 +35,7 @@ module Rapid
35
35
  raise "please set define build_skeleton or set Rapid::Spec::Template.skeleton_class before running specs"
36
36
  end
37
37
 
38
- @skeleton.load_hash settings_hash if settings_hash
38
+ @skeleton.settings = settings_hash if settings_hash
39
39
  @template = Rapid::Template::Base.new template_content
40
40
  @result = @template.push @skeleton
41
41
  end
data/lib/rapid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rapid
2
- VERSION = "0.1"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -0,0 +1,35 @@
1
+ module Rapid
2
+ module Web
3
+
4
+ class Base < Sinatra::Base
5
+
6
+ register SinatraMore::MarkupPlugin
7
+ register Web::StaticHelpers
8
+ register Web::SelectHelpers
9
+ register Web::ControllerHelpers
10
+ helpers Web::Bootstrap
11
+
12
+ enable :sessions
13
+
14
+ configure :development do
15
+ register Sinatra::Reloader if defined? Sinatra::Reloader
16
+ end
17
+
18
+ protected
19
+
20
+ class << self
21
+
22
+ attr_accessor :rapid_name, :gem_path
23
+ attr_reader :file
24
+
25
+ def file= file
26
+ @gem_path = $` if file =~ /\/lib\//
27
+ @file = file
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,98 @@
1
+ module Rapid
2
+ module Web
3
+
4
+ module Bootstrap
5
+
6
+ def bootstrap_head
7
+ tags = ""
8
+ tags << tag(:meta, :charset => "UTF-8")
9
+ tags << tag(:meta, :name => "description", :content => @description) if @description
10
+ tags << tag(:meta, :name => "author", :content => @author) if @author
11
+ tags << tag(:title, :content => (@title.to_s if @title) || "Rapid Development")
12
+
13
+ tags << bootstrap_stylesheets
14
+
15
+ tags << %(<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
16
+ <!--[if lt IE 9]>
17
+ <script src='http://html5shim.googlecode.com/svn/trunk/html5.js'></script>
18
+ <![endif]-->)
19
+
20
+ tag :head, :content => tags
21
+ end
22
+
23
+ def bootstrap_body &block
24
+ tags = bootstrap_topnav
25
+ tags << capture_html(&block)
26
+ tags << bootstrap_scripts
27
+
28
+ body = tag :body, :content => tags, "data-spy" => "scroll", "data-target" => ".subnav", "data-offset" => "50"
29
+
30
+ concat_content body
31
+ end
32
+
33
+ def bootstrap_stylesheets
34
+ tags = ""
35
+
36
+ tags << tag(:link, :href => "/rapid/core/bootstrap.min.css", :rel => "stylesheet")
37
+ tags << tag(:link, :href => "/rapid/core/bootstrap-responsive.min.css", :rel => "stylesheet")
38
+ tags << tag(:link, :href => "/rapid/core/prettify.css", :rel => "stylesheet")
39
+
40
+ if public_path && File.exists?(File.join(public_path, 'application.css'))
41
+ tags << tag(:link, :href => "/rapid/#{rapid_name}/application.css", :rel => "stylesheet")
42
+ end
43
+
44
+ tags
45
+ end
46
+
47
+ def bootstrap_scripts
48
+ tags = ""
49
+
50
+ tags << tag(:script, :content => "", :src => '/rapid/core/jquery-1.7.1.js')
51
+ tags << tag(:script, :content => "", :src => '/rapid/core/prettify.js')
52
+ tags << tag(:script, :content => "", :src => '/rapid/core/bootstrap-collapse.js')
53
+
54
+ if public_path && File.exists?(File.join(public_path, 'application.js'))
55
+ tags << tag(:script, :content => "", :src => "/rapid/#{rapid_name}/application.js")
56
+ end
57
+
58
+ tags
59
+ end
60
+
61
+ def bootstrap_topnav
62
+ %(<div class="navbar">
63
+ <div class="navbar-inner">
64
+ <div class="container">
65
+ <a href="#" class="brand">Rapid</a>
66
+ <div class="nav-collapse">
67
+ <ul class="nav pull-right">
68
+ <li>
69
+ <a href="#">Link</a>
70
+ </li>
71
+ <li class="divider-vertical"></li>
72
+ </ul>
73
+ </div>
74
+ </div>
75
+ </div>
76
+ </div>)
77
+ end
78
+
79
+ def bootstrap_flash
80
+ tags = ""
81
+
82
+ notice = session.delete :notice
83
+ if notice
84
+ tags << tag(:div, :content => notice, :class => 'alert alert-success')
85
+ end
86
+
87
+ error = session.delete :error
88
+ if error
89
+ tags << tag(:div, :content => error, :class => 'alert alert-error')
90
+ end
91
+
92
+ tags
93
+ end
94
+
95
+ end
96
+
97
+ end
98
+ end
@@ -0,0 +1,60 @@
1
+ module Rapid
2
+ module Web
3
+
4
+ module ControllerHelpers
5
+
6
+ def self.registered(app)
7
+ app.helpers self
8
+ end
9
+
10
+ def application_path
11
+ ENV["APP"]
12
+ end
13
+
14
+ def public_path
15
+ File.join gem_path, 'public', 'rapid', rapid_name if gem_path && rapid_name
16
+ end
17
+
18
+ def rapid_name
19
+ self.class.rapid_name
20
+ end
21
+
22
+ def gem_path
23
+ self.class.gem_path
24
+ end
25
+
26
+ def setting_params options = {}
27
+ param_name = options[:param] || :settings
28
+ param = params[param_name]
29
+ return if param.nil?
30
+
31
+ setting_params_recurse param
32
+ end
33
+
34
+ def setting_params_recurse source, destination = {}
35
+ source.each do |key, value|
36
+ if value.is_a? Hash
37
+ is_on = value.delete "on"
38
+
39
+ if is_on == "0"
40
+ destination[key] = false
41
+ elsif is_on == "1" && value.empty?
42
+ destination[key] = true
43
+ else
44
+ destination[key] = setting_params_recurse(value)
45
+ end
46
+
47
+ elsif value.blank?
48
+ destination[key] = nil
49
+ else
50
+ destination[key] = value
51
+ end
52
+ end
53
+
54
+ destination
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,18 @@
1
+ module Rapid
2
+ module Web
3
+
4
+ class Navigator < Base
5
+
6
+ self.file = __FILE__
7
+
8
+ set :views, File.join(@gem_path, 'views')
9
+ set :public_folder, File.join(@gem_path, 'public')
10
+
11
+ get "/rapid" do
12
+ erb :index
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,63 @@
1
+ module Rapid
2
+ module Web
3
+
4
+ module SelectHelpers
5
+
6
+ def self.registered(app)
7
+ app.set :default_builder, 'Rapid::Web::SettingsFormBuilder'
8
+ app.helpers self
9
+ end
10
+
11
+ # Returns the options tags for a select based on the given option items
12
+ def options_for_select(option_items, selected_values=[])
13
+ return '' if option_items.blank?
14
+ selected_values = [selected_values].compact unless selected_values.is_a?(Array)
15
+ items = option_items.collect { |caption, value|
16
+ value ||= caption
17
+ selected = selected_values.find {|v| v.to_s =~ /^(#{Regexp.escape(value)}|#{Regexp.escape(caption)})$/}
18
+ content_tag(:option, caption, :value => value, :selected => !!selected)
19
+ }
20
+ items.join("\n")
21
+ end
22
+
23
+ def time_zone_select name, options = {}
24
+ options.reverse_merge!(:name => name)
25
+ collection, fields = options.delete(:collection), options.delete(:fields)
26
+ options[:options] = options_from_collection(collection, fields) if collection
27
+ # options[:options].unshift('') if options.delete(:include_blank)
28
+ select_options_html = time_zone_options_for_select(options)
29
+ options.merge!(:name => "#{options[:name]}[]") if options[:multiple]
30
+ content_tag(:select, select_options_html, options)
31
+ end
32
+
33
+ # File actionpack/lib/action_view/helpers/form_options_helper.rb, line 504
34
+ def time_zone_options_for_select(options = {})
35
+ selected = options.delete(:selected)
36
+ priority_zones = options.delete(:priority)
37
+ model = options.delete(:model) || ::ActiveSupport::TimeZone
38
+ include_blank = options.delete(:include_blank)
39
+
40
+ zone_options = ""
41
+ zone_options += %(<option value=""></option>) if include_blank
42
+
43
+ zones = model.all
44
+ convert_zones = lambda { |list| list.map { |z| [ z.to_s, z.name ] } }
45
+
46
+ if priority_zones
47
+ if priority_zones.is_a?(Regexp)
48
+ priority_zones = model.all.find_all {|z| z =~ priority_zones}
49
+ end
50
+ zone_options += options_for_select(convert_zones[priority_zones], selected)
51
+ zone_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
52
+
53
+ zones = zones.reject { |z| priority_zones.include?( z ) }
54
+ end
55
+
56
+ zone_options += options_for_select(convert_zones[zones], selected)
57
+ zone_options.html_safe
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,205 @@
1
+ module Rapid
2
+ module Web
3
+
4
+ class SettingsFormBuilder < StandardFormBuilder
5
+
6
+ attr_writer :object_name
7
+ attr_accessor :object_field_name
8
+
9
+ def label field, options = {}
10
+ if field.is_a?(String)
11
+ super field.split('.').last, options.reverse_merge(:for => setting_id(field))
12
+ else
13
+ super
14
+ end
15
+ end
16
+
17
+ def fields_for field, settings={}, &block
18
+ fields_html = builder_html_for(field, settings, &block)
19
+ @template.concat_content fields_html
20
+ end
21
+
22
+ def section name, options = {}, &block
23
+ body = @template.capture_html(&block)
24
+
25
+ title = options[:label] || name.to_s.titleize
26
+ a = @template.tag(:a, :href => '#', :class => 'toggle-section', :content => title)
27
+ legend = @template.tag(:legend, :content => a)
28
+
29
+ content = legend << body
30
+ fieldset = @template.tag(:fieldset, :id => "section_#{name}", :class => "minimize", :content => content)
31
+ @template.concat_content fieldset
32
+ fieldset
33
+ end
34
+
35
+ def settings name, &block
36
+ id = "#{name.gsub('.', '_')}_settings"
37
+ content = @template.capture_html &block
38
+
39
+ namespace = object[name]
40
+ if !namespace.respond_to?(:on?)
41
+ off = true
42
+ else
43
+ off = !namespace.on?
44
+ end
45
+
46
+ css_class = off ? 'subsettings settings-off' : 'subsettings'
47
+
48
+ html = @template.tag :div, :id => id, :class => css_class, :content => content
49
+ @template.concat_content html
50
+ end
51
+
52
+ def control_group field, options = {}, &block
53
+ label_text = options.delete(:label) || field.to_s.split('.').last.titleize
54
+
55
+ label_html = label(field, :caption => label_text)
56
+ field_html = @template.capture_html(&block)
57
+
58
+ id = setting_id(field) + "_group"
59
+
60
+ html = control_group_html id, label_html, field_html, options
61
+ @template.concat_content html
62
+ html
63
+ end
64
+
65
+ def text_field field, options = {}
66
+ super field, options.reverse_merge(:id => setting_id(field), :name => setting_name(field), :value => object[field])
67
+ end
68
+
69
+ def text_area field, options = {}
70
+ super field, options.reverse_merge(:id => setting_id(field), :name => setting_name(field), :value => object[field])
71
+ end
72
+
73
+ def password_field field, options = {}
74
+ super field, options.reverse_merge(:id => setting_id(field), :name => setting_name(field), :value => object[field])
75
+ end
76
+
77
+ def select field, options = {}
78
+ super field, options.reverse_merge(:id => setting_id(field), :name => setting_name(field), :selected => object[field])
79
+ end
80
+
81
+ def check_box field, options = {}
82
+ if field.is_a?(String) && field =~ /\.on\Z/ && !options.key?(:checked)
83
+ options[:checked] = object[$`].on?
84
+ end
85
+
86
+ patched_check_box field, options.reverse_merge(:id => setting_id(field), :name => setting_name(field), :checked => object[field])
87
+ end
88
+
89
+ def radio_button field, options = {}
90
+ super field, options.reverse_merge(:id => setting_id(field), :name => setting_name(field), :selected => object[field])
91
+ end
92
+
93
+ def file_field field, options = {}
94
+ super field, options.reverse_merge(:id => setting_id(field), :name => setting_name(field), :value => object[field])
95
+ end
96
+
97
+ def time_zone_select field, options = {}
98
+ options.reverse_merge!(:id => setting_id(field), :value => object[field], :selected => field_value(field))
99
+ @template.send :time_zone_select, setting_name(field), options
100
+ end
101
+
102
+ def control_group_text_field field, options = {}
103
+ control_group_field :text_field, field, options
104
+ end
105
+
106
+ def control_group_text_area field, options = {}
107
+ control_group_field :text_area, field, options
108
+ end
109
+
110
+ def control_group_password_field field, options = {}
111
+ control_group_field :password_field, field, options
112
+ end
113
+
114
+ def control_group_select field, options = {}
115
+ control_group_field :select, field, options
116
+ end
117
+
118
+ def control_group_check_box field, options = {}
119
+ control_group_field :check_box, field, options
120
+ end
121
+
122
+ def control_group_radio_button field, options = {}
123
+ control_group_field :radio_button, field, options
124
+ end
125
+
126
+ def control_group_file_field field, options = {}
127
+ control_group_field :file_field, field, options
128
+ end
129
+
130
+ def control_group_time_zone_select field, options = {}
131
+ control_group_field :time_zone_select, field, options
132
+ end
133
+
134
+ protected
135
+
136
+ def object_name
137
+ @object_name || super
138
+ end
139
+
140
+ def field_id field, value=nil
141
+ id = super
142
+ id.gsub! "]", ""
143
+ id.gsub! "[", "_"
144
+ id
145
+ end
146
+
147
+ def builder_html_for field, settings = {}, &block
148
+ field_object = object.send field
149
+
150
+ builder_class = @template.send :configured_form_builder_class, settings[:builder] || self.class
151
+ builder = builder_class.new(@template, field_object)
152
+ builder.try :object_name=, "#{object_name}[#{field}]"
153
+ builder.try :object_field_name=, field
154
+
155
+ @template.capture_html(builder, &block)
156
+ end
157
+
158
+ def control_group_field field_type, field, options = {}
159
+ label_text = options.delete(:label) || field.to_s.split('.').last.titleize
160
+
161
+ css_classes = options[:class] || "input"
162
+ field_size = options[:size]
163
+ if field_size && field_size.is_a?(Symbol)
164
+ options.delete :size
165
+ css_classes += " input-#{field_size}"
166
+ end
167
+
168
+ label_html = label(field, :caption => label_text)
169
+
170
+ field_html = send field_type, field, options.merge(:class => css_classes)
171
+
172
+ id = setting_id(field) + "_group"
173
+ control_group_html id, label_html, field_html, options
174
+ end
175
+
176
+ def control_group_html id, label_html, field_html, options = {}
177
+ hidden = options[:hidden]
178
+ content = label_html + @template.tag(:div, :content => field_html, :class => 'controls')
179
+ @template.tag(:div, :id => id, :class => 'control-group', :content => content, :style => ("display:none" if hidden))
180
+ end
181
+
182
+ def setting_id setting
183
+ if setting.is_a? Symbol
184
+ field_id setting
185
+ else
186
+ "#{object_field_name || "settings"}_#{setting.gsub('.', '_')}"
187
+ end
188
+ end
189
+
190
+ def setting_name setting
191
+ "#{object_name}[#{setting.gsub('.', '][')}]"
192
+ end
193
+
194
+ def patched_check_box field, options = {}
195
+ unchecked_value = options.delete(:uncheck_value) || '0'
196
+ options.reverse_merge!(:id => field_id(field), :value => '1')
197
+ options.merge!(:checked => true) if values_matches_field?(field, options[:value])
198
+ html = hidden_field(field, :value => unchecked_value, :id => nil, :name => options[:name])
199
+ html << @template.check_box_tag(field_name(field), options)
200
+ end
201
+
202
+ end
203
+
204
+ end
205
+ end