showbuilder 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -51,35 +51,6 @@ module Showbuilder
51
51
  self.controller_name.to_s.singularize
52
52
  end
53
53
 
54
- def call_object_methods(object, methods)
55
- unless object
56
- return
57
- end
58
-
59
- methods = Array.wrap(methods)
60
- if methods.count == 0
61
- return
62
- end
63
-
64
- first_method = methods.first
65
- unless first_method
66
- return
67
- end
68
-
69
- unless object.respond_to?(first_method)
70
- return
71
- end
72
-
73
- method_result = object.send(first_method)
74
- if methods.count <= 1
75
- return method_result
76
- else
77
- remaining_methods = methods.clone
78
- remaining_methods.shift
79
- return call_object_methods(method_result, remaining_methods)
80
- end
81
- end
82
-
83
54
  def show_model_link_to(name, object)
84
55
  self.link_to name, object
85
56
  end
@@ -14,13 +14,13 @@ module Showbuilder
14
14
  def show_text_input(method, options = {})
15
15
  options ||={}
16
16
  html_options = options[:html]
17
- self.show_method_input(method) do
17
+ self.show_method_shell(method) do
18
18
  self.text_field_tag(method, nil, :class => 'xlarge', :id => 'xlInput')
19
19
  end
20
20
  end
21
21
 
22
22
  def show_email_input(method)
23
- self.show_method_input(method) do
23
+ self.show_method_shell(method) do
24
24
  self.contents_tag(:div, :class => "input-append") do |contents|
25
25
  contents << self.email_field_tag(method, nil, :class => 'xlarge', :id => 'xlInput')
26
26
  contents << self.content_tag(:span, "@", :class => "add-on")
@@ -29,12 +29,12 @@ module Showbuilder
29
29
  end
30
30
 
31
31
  def show_password_input(method)
32
- self.show_method_input(method) do
32
+ self.show_method_shell(method) do
33
33
  self.password_field_tag(method, nil, :class => 'xlarge', :id => 'xlInput')
34
34
  end
35
35
  end
36
36
 
37
- def show_method_input(method)
37
+ def show_method_shell(method)
38
38
  self.contents_tag :div, :class => :clearfix do |contents|
39
39
  label_text = self.show_current_itext(method)
40
40
  contents << self.label(method, label_text)
@@ -9,9 +9,9 @@ module Showbuilder
9
9
 
10
10
  def show_text_input(method, options = {})
11
11
  options ||= {}
12
- html_options = options[:html] || {}
13
- input_options = options[:input_options] || {}
14
- self.show_method_input(method, html_options) do
12
+ input_options = options[:input] || {}
13
+
14
+ self.show_method_shell(method, options) do
15
15
  self.text_field(method, input_options)
16
16
  end
17
17
  end
@@ -19,13 +19,13 @@ module Showbuilder
19
19
  def show_text_field(method)
20
20
  text = @object.send(method)
21
21
 
22
- self.show_method_input(method) do
22
+ self.show_method_shell(method) do
23
23
  self.content_tag(:span, text, :class => "uneditable-input")
24
24
  end
25
25
  end
26
26
 
27
27
  def show_email_input(method)
28
- self.show_method_input(method) do
28
+ self.show_method_shell(method) do
29
29
  self.contents_tag(:div, :class => "input-append") do |contents|
30
30
  contents << self.email_field(method)
31
31
  contents << self.content_tag(:span, :class => "add-on") do
@@ -36,45 +36,65 @@ module Showbuilder
36
36
  end
37
37
 
38
38
  def show_password_input(method)
39
- self.show_method_input(method) do
39
+ self.show_method_shell(method) do
40
40
  self.password_field(method)
41
41
  end
42
42
  end
43
43
 
44
44
  def show_memo_input(method)
45
- self.show_method_input(method) do
45
+ self.show_method_shell(method) do
46
46
  self.text_area(method, :rows => 5)
47
47
  end
48
48
  end
49
49
 
50
- def show_select_input(method, choices, lable, options = {}, html_options = {})
51
- self.show_method_input(method, :label_text => lable) do
52
- self.select(method, choices, options, html_options)
50
+ def show_select_input(method, choices, options = {})
51
+ options ||= {}
52
+
53
+ select_options = options[:select] || {}
54
+ select_html_options = options[:select_html] || {}
55
+
56
+ show_method_shell method, options do
57
+ select method, choices, select_options, select_html_options
53
58
  end
54
59
  end
55
60
 
56
- def show_method_input(method, options = {})
57
- label_text = options[:label_text] || self.show_current_itext(method)
58
- div_options = options[:class] || ''
61
+ def show_method_shell(method, options = {}, &block)
62
+ options ||= {}
59
63
 
60
- if object.errors.count > 0 and object.errors[method].count > 0
61
- div_options = " error"
62
- end
64
+ shell_options = options[:shell] || {}
65
+ label_options = options[:shell_label] || {}
66
+ label_content = options[:shell_title] || show_current_itext(method)
67
+ control_options = options[:shell_control] || {}
63
68
 
64
- self.contents_tag :div, :class => "control-group #{div_options}" do |contents|
65
- contents << self.label(method, label_text, :class => "control-label")
66
- contents << self.content_tag(:div, :class => 'controls') do
67
- yield
68
- end
69
+ shell_options[:class] = merge_class_option(shell_options[:class], 'control-group')
70
+ shell_options[:class] = merge_class_option(shell_options[:class], 'error') if is_object_method_error(method)
71
+ label_options[:class] = merge_class_option(label_options[:class], 'control-label')
72
+ control_options[:class] = merge_class_option(control_options[:class], 'controls')
73
+
74
+ contents_tag :div, shell_options do |contents|
75
+ contents << label(method, label_content, label_options)
76
+ contents << contents_tag(:div, control_options, &block)
69
77
  end
70
78
  end
71
79
 
72
- protected
80
+ private
73
81
 
74
82
  def show_current_itext_base
75
- self.object.class.to_s.underscore
83
+ object.class.to_s.underscore
84
+ end
85
+
86
+ def is_object_method_error(method)
87
+ if object.errors.count == 0
88
+ return false
89
+ end
90
+
91
+ if object.errors[method].count > 0
92
+ return true
93
+ else
94
+ return false
95
+ end
76
96
  end
77
97
 
78
98
  end
79
99
  end
80
- end
100
+ end
@@ -1,6 +1,39 @@
1
1
  module Showbuilder
2
2
  module Corekit
3
3
 
4
+ def call_object_methods(object, methods)
5
+ unless object
6
+ return
7
+ end
8
+
9
+ methods = Array.wrap(methods)
10
+ if methods.count == 0
11
+ return
12
+ end
13
+
14
+ first_method = methods.first
15
+ unless first_method
16
+ return
17
+ end
18
+
19
+ unless object.respond_to?(first_method)
20
+ return
21
+ end
22
+
23
+ method_result = object.send(first_method)
24
+ if methods.count <= 1
25
+ return method_result
26
+ else
27
+ remaining_methods = methods.clone
28
+ remaining_methods.shift
29
+ return call_object_methods(method_result, remaining_methods)
30
+ end
31
+ end
32
+
33
+ def merge_class_option(original, another)
34
+ "#{original} #{another}".strip
35
+ end
36
+
4
37
  def html_contents
5
38
  contents = []
6
39
  result = yield contents
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: showbuilder
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 10
10
- version: 0.0.10
9
+ - 11
10
+ version: 0.0.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ery Wang, Mario Du