showbuilder 0.0.2 → 0.0.3

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.
data/lib/showbuilder.rb CHANGED
@@ -17,21 +17,21 @@ module Showbuilder
17
17
  Showbuilder::ShowPaginateRenderer
18
18
  end
19
19
 
20
- def show_form_button(text_id = nil)
21
- text_id ||= 'commit'
22
- text = I18n.t("form_button.#{text_id}")
23
- text_loading = I18n.t("form_button.#{text_id}_loading")
24
- options = {}
25
- options['class'] = "form-button btn primary"
26
- options['data-loading-text'] = text_loading
27
- options['type'] = :button
20
+ def show_form_button(text_id = nil, options = {})
21
+ text_id ||= 'save'
22
+ text = show_itext("form_button.#{text_id}")
23
+ text_loading = show_itext("form_button.#{text_id}_loading")
24
+ options ||= {}
25
+ options[:class] = "form-button btn #{options[:class]}"
26
+ options[:'data-loading-text'] ||= text_loading
27
+ options[:type] ||= :submit
28
28
  self.content_tag(:button, text, options)
29
29
  end
30
30
 
31
31
  def show_page_title
32
32
  self.content_tag :div, :class => 'page-header' do
33
33
  self.content_tag :h1 do
34
- self.current_itext("title_#{self.action_name}")
34
+ self.show_current_itext("title_#{self.action_name}")
35
35
  end
36
36
  end
37
37
  end
@@ -47,7 +47,7 @@ module Showbuilder
47
47
  end
48
48
  end
49
49
 
50
- def current_text_group
50
+ def show_current_itext_base
51
51
  self.controller_name.to_s.singularize
52
52
  end
53
53
 
@@ -80,5 +80,13 @@ module Showbuilder
80
80
  end
81
81
  end
82
82
 
83
+ def show_model_link_to(name, object)
84
+ self.link_to name, object
85
+ end
86
+
83
87
  ::ActionView::Base.send :include, self
88
+
89
+ ::ActionView::Base.field_error_proc = proc do |html_tag, instance_tag|
90
+ html_tag
91
+ end
84
92
  end
@@ -11,7 +11,9 @@ module Showbuilder
11
11
  @template = template
12
12
  end
13
13
 
14
- def show_text_input(method)
14
+ def show_text_input(method, options = {})
15
+ options ||={}
16
+ html_options = options[:html]
15
17
  self.show_method_input(method) do
16
18
  self.text_field_tag(method, nil, :class => 'xlarge', :id => 'xlInput')
17
19
  end
@@ -34,7 +36,7 @@ module Showbuilder
34
36
 
35
37
  def show_method_input(method)
36
38
  self.contents_tag :div, :class => :clearfix do |contents|
37
- label_text = self.current_itext(method)
39
+ label_text = self.show_current_itext(method)
38
40
  contents << self.label(method, label_text)
39
41
  contents << self.content_tag(:div, :class => :input) do
40
42
  yield
@@ -42,7 +44,7 @@ module Showbuilder
42
44
  end
43
45
  end
44
46
 
45
- def current_text_group
47
+ def show_current_itext_base
46
48
  self.controller_name.to_s.singularize + '.form'
47
49
  end
48
50
  end
@@ -7,49 +7,66 @@ module Showbuilder
7
7
  include Showbuilder::Builders::TemplateMethods
8
8
  include Showbuilder::I18nText
9
9
 
10
- def show_text_input(method)
10
+ def show_text_input(method, options = {})
11
+ options ||= {}
12
+ html_options = options[:html] || {}
13
+ input_options = options[:input_options] || {}
14
+ self.show_method_input(method, html_options) do
15
+ self.text_field(method, input_options)
16
+ end
17
+ end
18
+
19
+ def show_text_field(method)
20
+ text = @object.send(method)
21
+
11
22
  self.show_method_input(method) do
12
- self.text_field(method, :class => 'xlarge', :id => 'xlInput')
23
+ self.content_tag(:span, text, :class => "uneditable-input")
13
24
  end
14
25
  end
15
26
 
16
27
  def show_email_input(method)
17
28
  self.show_method_input(method) do
18
- self.contents_tag(:div, :class => "input-append") do |contents|
19
- contents << self.email_field(method, :class => 'xlarge', :id => 'xlInput')
20
- contents << self.content_tag(:span, "@", :class => "add-on")
29
+ self.contents_tag(:div, :class => "input-append") do |contents|
30
+ contents << self.email_field(method, :class => :medium)
31
+ contents << self.content_tag(:span, content_tag(:i, '', :class =>"icon-envelope"), :class => "add-on")
21
32
  end
22
33
  end
23
34
  end
24
35
 
25
36
  def show_password_input(method)
26
37
  self.show_method_input(method) do
27
- self.password_field(method, :class => 'xlarge', :id => 'xlInput')
38
+ self.password_field(method, :class => 'input-large changes')
28
39
  end
29
40
  end
30
41
 
31
42
  def show_memo_input(method)
32
43
  self.show_method_input(method) do
33
- self.text_area(method, :class => 'xlarge', :id => 'xlInput', :rows => '5', :cols => '10')
44
+ self.text_area(method, :rows => 5)
34
45
  end
35
46
  end
36
47
 
37
- def show_method_input(method)
38
- self.contents_tag :div, :class => :clearfix do |contents|
39
- label_text = self.current_itext(method)
40
- contents << self.label(method, label_text)
41
- contents << self.content_tag(:div, :class => :input) do
48
+ def show_method_input(method, options = {})
49
+ label_text = options[:label_text] || self.show_current_itext(method)
50
+ div_options = options[:class] || ''
51
+
52
+ if object.errors.count > 0 and object.errors[method].count > 0
53
+ div_options = " error"
54
+ end
55
+
56
+ self.contents_tag :div, :class => "control-group #{div_options}" do |contents|
57
+ contents << self.label(method, label_text, :class => "control-label")
58
+ contents << self.content_tag(:div, :class => 'controls') do
42
59
  yield
43
60
  end
44
61
  end
45
62
  end
46
63
 
47
64
  protected
48
-
49
- def current_text_group
65
+
66
+ def show_current_itext_base
50
67
  self.object.class.to_s.underscore
51
68
  end
52
-
69
+
53
70
  end
54
71
  end
55
72
  end
@@ -18,6 +18,8 @@ module Showbuilder
18
18
  attr_reader :template
19
19
  attr_reader :text_group
20
20
  attr_accessor :columns
21
+ attr_accessor :table_options
22
+ attr_accessor :body_row_options
21
23
 
22
24
  def initialize(template, text_group)
23
25
  @template = template
@@ -26,9 +28,12 @@ module Showbuilder
26
28
  end
27
29
 
28
30
  def build_model_list(models, &block)
29
- block.call(self)
30
-
31
- contents_tag(:table, :class => 'bordered-table zebra-striped') do |contents|
31
+ block.call(self)
32
+ self.table_options ||= {}
33
+ self.table_options[:class] ||= ""
34
+ self.table_options[:class] += " table table-bordered table-striped"
35
+
36
+ contents_tag(:table, self.table_options) do |contents|
32
37
  contents << self.build_header
33
38
  contents << self.build_body(models)
34
39
  end
@@ -53,8 +58,9 @@ module Showbuilder
53
58
  self.content_tag(:th) do
54
59
  if column.methods
55
60
  methods = Array.wrap(column.methods)
61
+ methods = filter_method_option(methods)
56
62
  text_id = methods.join('.')
57
- self.current_itext(text_id)
63
+ self.show_current_itext(text_id)
58
64
  end
59
65
  end
60
66
  end
@@ -76,7 +82,7 @@ module Showbuilder
76
82
 
77
83
  def build_body_row(model)
78
84
  options = self.build_body_row_options
79
- contents_tag(:tr, options)do |contents|
85
+ contents_tag(:tr, :class => "#{options}")do |contents|
80
86
  self.columns.each do |column|
81
87
  contents << self.build_body_column(column, model)
82
88
  end
@@ -85,14 +91,16 @@ module Showbuilder
85
91
 
86
92
  def build_body_row_options
87
93
  even = self.cycle('', 'even')
88
- {:class => even}
94
+ self.body_row_options ||= {}
95
+ self.body_row_options[:class] ||= ""
96
+ self.body_row_options[:class] += " #{even}"
89
97
  end
90
98
 
91
99
  def build_body_row_for_no_record
92
100
  contents_tag :tr do |contents|
93
101
  self.columns.each_index do |index|
94
102
  contents << self.content_tag(:td) do
95
- itext('no_record') if index == 0
103
+ show_itext('no_record') if index == 0
96
104
  end
97
105
  end
98
106
  end
@@ -106,7 +114,7 @@ module Showbuilder
106
114
  end
107
115
  end
108
116
 
109
- def current_text_group
117
+ def show_current_itext_base
110
118
  @text_group || self.controller_name.to_s.singularize
111
119
  end
112
120
  end
@@ -13,6 +13,9 @@ module Showbuilder
13
13
 
14
14
  # show_text_link_column :number
15
15
  # show_text_link_column :member, :number
16
+ # show_text_link_column :member, :number, :link => :member
17
+ # show_text_link_column :member, :number, :link => [:member, :department]
18
+ # show_text_link_column :member, :number, :link => [:member, :department], :class => 'member_list'
16
19
  def show_text_link_column(*methods)
17
20
  self.show_method_link_column(*methods) do |value|
18
21
  self.safe_html_string(value)
@@ -25,6 +28,12 @@ module Showbuilder
25
28
  self.time_string(value)
26
29
  end
27
30
  end
31
+
32
+ def show_time_link_column(*methods)
33
+ self.show_method_link_column(*methods) do |value|
34
+ self.time_string(value)
35
+ end
36
+ end
28
37
 
29
38
  # show_date_column :created_at
30
39
  def show_date_column(*methods)
@@ -47,6 +56,12 @@ module Showbuilder
47
56
  end
48
57
  end
49
58
 
59
+ def show_currency_link_column(*methods)
60
+ self.show_method_link_column(*methods) do |value|
61
+ self.currency_string(value)
62
+ end
63
+ end
64
+
50
65
  # show_percent_column :percent
51
66
  def show_percent_column(*methods)
52
67
  self.show_method_column(methods) do |value|
@@ -56,7 +71,7 @@ module Showbuilder
56
71
 
57
72
  def show_method_column(methods, &block)
58
73
  self.show_column(methods) do |model|
59
- self.content_tag(:td) do
74
+ self.content_tag(:td, :class => find_option_form_methods(methods, :class)) do
60
75
  method_value = self.call_object_methods(model, methods)
61
76
  if block
62
77
  content = block.call(method_value)
@@ -74,24 +89,39 @@ module Showbuilder
74
89
  end
75
90
 
76
91
  self.show_column(methods) do |model|
77
- self.content_tag(:td) do
92
+ self.content_tag(:td, :class => find_option_form_methods(methods, :class)) do
78
93
  link_object = self.show_method_link_column__get_link_object(model, methods)
79
94
  link_name = self.show_method_link_column__get_link_name(model, methods, customize_link_name_block)
80
- self.link_to link_name, link_object
95
+ self.show_model_link_to link_name, link_object
81
96
  end
82
- end
97
+ end
83
98
  end
84
99
 
85
- def show_method_link_column__get_link_object(model, methods)
86
- case methods.count
87
- when 1
88
- model
100
+ def find_option_form_methods(methods, key)
101
+ last_item = methods.last
102
+ if last_item.is_a? Hash
103
+ return last_item[key]
89
104
  else
90
- self.call_object_methods(model, methods.first)
105
+ return nil
106
+ end
107
+ end
108
+
109
+ def show_method_link_column__get_link_object(model, methods)
110
+ if methods.count == 1
111
+ return model
112
+ end
113
+
114
+ link_methods = find_option_form_methods(methods, :link)
115
+ if link_methods
116
+ link_object = self.call_object_methods(model, link_methods)
117
+ return link_object
91
118
  end
119
+
120
+ return model
92
121
  end
93
122
 
94
123
  def show_method_link_column__get_link_name(model, methods, customize_link_name_block)
124
+ methods = filter_method_option(methods)
95
125
  method_value = self.call_object_methods(model, methods)
96
126
  if customize_link_name_block
97
127
  link_name = customize_link_name_block.call(method_value)
@@ -109,6 +139,13 @@ module Showbuilder
109
139
  self.columns << column
110
140
  end
111
141
 
142
+ def filter_method_option(methods)
143
+ if methods.last.is_a? Hash
144
+ methods[0..-2]
145
+ else
146
+ methods
147
+ end
148
+ end
112
149
  end
113
150
  end
114
151
  end
@@ -18,27 +18,27 @@ module Showbuilder
18
18
  unless @model
19
19
  return
20
20
  end
21
- self.content_tag(:table, :class => "bordered-table") do
21
+ self.content_tag(:table, :class => "table table-bordered nohead") do
22
22
  @template.capture(self, &block)
23
23
  end
24
24
  end
25
25
 
26
- def show_text(method)
27
- self.show_method_field(method) do |value|
26
+ def show_text(*methods)
27
+ self.show_method_field(*methods) do |value|
28
28
  self.safe_html_string(value)
29
29
  end
30
30
  end
31
31
 
32
32
  def show_text_link(link_method, text_method)
33
33
  methods = [link_method, text_method]
34
- method_label = self.current_itext(methods)
34
+ method_label = self.show_current_itext(methods)
35
35
  method_value = self.call_object_methods(model, methods)
36
36
  method_link = self.call_object_methods(model, link_method)
37
37
 
38
38
  self.contents_tag :tr do |contents|
39
- contents << self.content_tag(:td, method_label.to_s, :class => "span2")
40
- contents << self.content_tag(:td, :class => "span2") do
41
- link_to(method_value.to_s, method_link)
39
+ contents << self.content_tag(:td, method_label.to_s, :class => "span2 left")
40
+ contents << self.content_tag(:td, :class => "span2 right") do
41
+ self.show_model_link_to(method_value.to_s, method_link)
42
42
  end
43
43
  end
44
44
  end
@@ -67,22 +67,22 @@ module Showbuilder
67
67
  end
68
68
  end
69
69
 
70
- def show_method_field(method, &block)
71
- method_label = self.current_itext(method)
70
+ def show_method_field(*method, &block)
71
+ method_label = self.show_current_itext(method)
72
72
  method_value = self.call_object_methods(model, method)
73
73
  if block
74
74
  method_value = block.call(method_value)
75
75
  end
76
76
 
77
77
  self.contents_tag :tr do |contents|
78
- contents << self.content_tag(:td, method_label.to_s, :class => "span2")
79
- contents << self.content_tag(:td, method_value.to_s, :class => "span2")
78
+ contents << self.content_tag(:td, method_label.to_s, :class => "span2 left")
79
+ contents << self.content_tag(:td, method_value.to_s, :class => "span2 right")
80
80
  end
81
81
  end
82
-
82
+
83
83
  protected
84
84
 
85
- def current_text_group
85
+ def show_current_itext_base
86
86
  self.model.class.to_s.underscore
87
87
  end
88
88
  end
@@ -2,8 +2,12 @@ module Showbuilder
2
2
  module Corekit
3
3
  def html_contents
4
4
  contents = []
5
- yield contents
6
- contents.join(' ').html_safe
5
+ result = yield contents
6
+ if contents.count > 0
7
+ contents.join(' ').html_safe
8
+ else
9
+ result
10
+ end
7
11
  end
8
12
 
9
13
  def contents_tag(tag_name, options = {}, &block)
@@ -11,7 +15,11 @@ module Showbuilder
11
15
  self.html_contents(&block)
12
16
  end
13
17
  end
14
-
18
+
19
+ def divc(option_class, &block)
20
+ contents_tag :div, :class => option_class , &block
21
+ end
22
+
15
23
  def currency_string(number)
16
24
  if number
17
25
  number_to_currency(number)
@@ -1,25 +1,24 @@
1
1
  module Showbuilder
2
2
  module I18nText
3
-
4
- def current_itext(text_id, *args)
3
+ def show_current_itext(text_id, *args)
5
4
  case text_id
6
5
  when Array
7
6
  text_id = text_id.join('.')
8
7
  end
9
8
 
10
- if self.current_text_group
11
- crrent_text_id = "#{self.current_text_group}.#{text_id}"
9
+ if self.show_current_itext_base
10
+ current_text_id = "#{self.show_current_itext_base}.#{text_id}"
12
11
  else
13
- crrent_text_id = text_id
12
+ current_text_id = text_id
14
13
  end
15
14
 
16
- self.itext(crrent_text_id, *args)
15
+ self.show_itext(current_text_id, *args)
17
16
  end
18
17
 
19
- def current_text_group
18
+ def show_current_itext_base
20
19
  end
21
20
 
22
- def itext(id, *args)
21
+ def show_itext(id, *args)
23
22
  I18n.t(id, *args)
24
23
  end
25
24
  end
@@ -2,8 +2,10 @@ require 'showbuilder/builders/form_builder'
2
2
 
3
3
  module Showbuilder
4
4
  module ShowForm
5
- def show_form(url, &block)
6
- self.form_tag url do
5
+ def show_form(url, options = {}, &block)
6
+ options = options || {}
7
+ options[:class] = "#{options[:class]} form-horizontal"
8
+ self.form_tag url, options do
7
9
  builder = Showbuilder::Builders::FormBuilder.new(self)
8
10
  self.capture(builder, &block)
9
11
  end
@@ -16,38 +16,31 @@ module Showbuilder
16
16
  # I18n.t("customer.email')
17
17
  # I18n.t('customer.password')
18
18
  #
19
- def show_model_form(model, options ={}, &block)
20
- options.merge!(:builder => Showbuilder::Builders::ModelFormBuilder)
21
-
22
- self.html_contents do |contents|
23
- contents << self.error_messages_for(model)
24
- contents << self.form_for(model, options) do |form|
25
- capture(form, &block)
19
+ def show_model_form(models, options ={}, &block)
20
+ models = Array.wrap(models)
21
+ options = options || {}
22
+ options[:builder] = options[:builder] || Showbuilder::Builders::ModelFormBuilder
23
+ options[:html] = options[:html] || {}
24
+ options[:html][:class] = "#{options[:html][:class]} form-horizontal"
25
+
26
+ self.form_for(models, options) do |form|
27
+ self.html_contents do |contents|
28
+ contents << self.model_error_messages(models.last)
29
+ contents << capture(form, &block)
26
30
  end
27
31
  end
28
32
  end
29
-
30
- def error_messages_for(*objects)
31
- options = objects.extract_options!
32
- options[:header_message] ||= I18n.t(:"activerecord.errors.header", :default => "Invalid Fields")
33
- options[:message] ||= I18n.t(:"activerecord.errors.message", :default => "Correct the following errors and try again.")
34
-
35
- messages = objects.compact.map do |object|
36
- object.errors.messages.map do |key, value|
37
- value
38
- end
33
+
34
+ def model_error_messages(object)
35
+ messages = object.errors.messages.map do |key, value|
36
+ value
39
37
  end
40
38
  messages.flatten!
39
+ return if messages.empty?
41
40
 
42
- if messages.empty?
43
- return
44
- end
45
-
46
- contents_tag(:div, :class => "alert-message block-message error") do |contents|
47
- contents << content_tag(:a, 'x', :class=>'close', :href=>"#")
48
- contents << content_tag(:p) do
49
- content_tag(:strong, options[:header_message]) + options[:message]
50
- end
41
+ contents_tag(:div, :class => "alert alert-error") do |contents|
42
+ contents << content_tag(:a, '&times'.html_safe, :class=>'close' , "data-dismiss" => :alert)
43
+ contents << content_tag(:strong, flash[:error], :class => "alert-heading") if flash[:error]
51
44
  contents << content_tag(:ul) do
52
45
  list_items = messages.map do |msg|
53
46
  content_tag(:li, msg)
@@ -55,7 +48,6 @@ module Showbuilder
55
48
  list_items.join.html_safe
56
49
  end
57
50
  end
58
-
59
51
  end
60
52
  end
61
53
  end
@@ -4,17 +4,17 @@ module Showbuilder
4
4
  module ShowModelList
5
5
  #
6
6
  # show_model_list @products do |list|
7
- # list.show_column :x_field
8
- # list.show_text_column :x_field
9
- # list.show_currency_column :x_field
10
- # list.show_percent_column :x_field
11
- # list.show_date_column :x_field
12
- # list.show_time_column :x_field
13
- # list.show_text_link_column :x_field
14
- # list.show_currency_link_column :x_field
15
- # list.show_percent_link_column :x_field
16
- # list.show_date_link_column :x_field
17
- # list.show_time_link_column :x_field
7
+ # list.show_column :some_field
8
+ # list.show_text_column :some_field
9
+ # list.show_currency_column :some_field
10
+ # list.show_percent_column :some_field
11
+ # list.show_date_column :some_field
12
+ # list.show_time_column :some_field
13
+ # list.show_text_link_column :some_field
14
+ # list.show_currency_link_column :some_field
15
+ # list.show_percent_link_column :some_field
16
+ # list.show_date_link_column :some_field
17
+ # list.show_time_link_column :some_field
18
18
  # end
19
19
  #
20
20
  def show_model_list(models, text_group = nil, &block)
@@ -30,7 +30,8 @@ module Showbuilder
30
30
  end
31
31
  if page && page != current_page && page != :gap
32
32
  page_link(page, text, :class => span_class)
33
- else if page == current_page || page == :gap
33
+ else
34
+ if page == current_page || page == :gap
34
35
  page_span(page, text, :class => span_class)
35
36
  else
36
37
  previous_or_next_page(page)
metadata CHANGED
@@ -1,38 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: showbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Ery wang
8
+ - Ery Wang, Mario Du
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-07 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: actionpack
16
- requirement: &73874240 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '3.0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: *73874240
25
- - !ruby/object:Gem::Dependency
26
- name: will_paginate
27
- requirement: &73873910 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ~>
31
- - !ruby/object:Gem::Version
32
- version: '3.0'
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: *73873910
12
+ date: 2011-12-07 00:00:00.000000000 Z
13
+ dependencies: []
36
14
  description: A Rails View Helper. Show model/s as view, form, list.
37
15
  email: ery@baoleihang.com
38
16
  executables: []
@@ -73,8 +51,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
51
  version: '0'
74
52
  requirements: []
75
53
  rubyforge_project:
76
- rubygems_version: 1.8.13
54
+ rubygems_version: 1.8.10
77
55
  signing_key:
78
56
  specification_version: 3
79
57
  summary: A Rails View Helper.
80
58
  test_files: []
59
+ has_rdoc: