showbuilder 0.0.2
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 +84 -0
- data/lib/showbuilder/builders/form_builder.rb +50 -0
- data/lib/showbuilder/builders/model_form_builder.rb +55 -0
- data/lib/showbuilder/builders/model_list_builder.rb +114 -0
- data/lib/showbuilder/builders/model_list_builder/show_columns.rb +115 -0
- data/lib/showbuilder/builders/model_view_builder.rb +90 -0
- data/lib/showbuilder/builders/template_methods.rb +15 -0
- data/lib/showbuilder/corekit.rb +61 -0
- data/lib/showbuilder/i18n_text.rb +27 -0
- data/lib/showbuilder/show_form.rb +13 -0
- data/lib/showbuilder/show_model_form.rb +61 -0
- data/lib/showbuilder/show_model_list.rb +25 -0
- data/lib/showbuilder/show_model_view.rb +25 -0
- data/lib/showbuilder/show_paginate_renderer.rb +67 -0
- metadata +80 -0
data/lib/showbuilder.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'showbuilder/corekit'
|
2
|
+
require 'showbuilder/show_model_view'
|
3
|
+
require 'showbuilder/show_model_form'
|
4
|
+
require 'showbuilder/show_model_list'
|
5
|
+
require 'showbuilder/show_form'
|
6
|
+
require 'showbuilder/show_paginate_renderer'
|
7
|
+
|
8
|
+
module Showbuilder
|
9
|
+
include Showbuilder::Corekit
|
10
|
+
include Showbuilder::I18nText
|
11
|
+
include Showbuilder::ShowModelView
|
12
|
+
include Showbuilder::ShowModelForm
|
13
|
+
include Showbuilder::ShowModelList
|
14
|
+
include Showbuilder::ShowForm
|
15
|
+
|
16
|
+
def show_paginate_renderer
|
17
|
+
Showbuilder::ShowPaginateRenderer
|
18
|
+
end
|
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
|
28
|
+
self.content_tag(:button, text, options)
|
29
|
+
end
|
30
|
+
|
31
|
+
def show_page_title
|
32
|
+
self.content_tag :div, :class => 'page-header' do
|
33
|
+
self.content_tag :h1 do
|
34
|
+
self.current_itext("title_#{self.action_name}")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def show_alerts
|
40
|
+
self.html_contents do |contents|
|
41
|
+
self.flash.each do |name, message|
|
42
|
+
contents << self.contents_tag(:div, :class => 'alert-message error') do |contents|
|
43
|
+
contents << self.content_tag(:a, "x", :href => '#', :class => 'close')
|
44
|
+
contents << self.content_tag(:p, message)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def current_text_group
|
51
|
+
self.controller_name.to_s.singularize
|
52
|
+
end
|
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
|
+
::ActionView::Base.send :include, self
|
84
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'showbuilder/builders/template_methods'
|
2
|
+
require 'showbuilder/i18n_text'
|
3
|
+
|
4
|
+
module Showbuilder
|
5
|
+
module Builders
|
6
|
+
class FormBuilder
|
7
|
+
include Showbuilder::Builders::TemplateMethods
|
8
|
+
include Showbuilder::I18nText
|
9
|
+
|
10
|
+
def initialize(template)
|
11
|
+
@template = template
|
12
|
+
end
|
13
|
+
|
14
|
+
def show_text_input(method)
|
15
|
+
self.show_method_input(method) do
|
16
|
+
self.text_field_tag(method, nil, :class => 'xlarge', :id => 'xlInput')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def show_email_input(method)
|
21
|
+
self.show_method_input(method) do
|
22
|
+
self.contents_tag(:div, :class => "input-append") do |contents|
|
23
|
+
contents << self.email_field_tag(method, nil, :class => 'xlarge', :id => 'xlInput')
|
24
|
+
contents << self.content_tag(:span, "@", :class => "add-on")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def show_password_input(method)
|
30
|
+
self.show_method_input(method) do
|
31
|
+
self.password_field_tag(method, nil, :class => 'xlarge', :id => 'xlInput')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def show_method_input(method)
|
36
|
+
self.contents_tag :div, :class => :clearfix do |contents|
|
37
|
+
label_text = self.current_itext(method)
|
38
|
+
contents << self.label(method, label_text)
|
39
|
+
contents << self.content_tag(:div, :class => :input) do
|
40
|
+
yield
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def current_text_group
|
46
|
+
self.controller_name.to_s.singularize + '.form'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'showbuilder/builders/template_methods'
|
2
|
+
require 'showbuilder/i18n_text'
|
3
|
+
|
4
|
+
module Showbuilder
|
5
|
+
module Builders
|
6
|
+
class ModelFormBuilder < ActionView::Helpers::FormBuilder
|
7
|
+
include Showbuilder::Builders::TemplateMethods
|
8
|
+
include Showbuilder::I18nText
|
9
|
+
|
10
|
+
def show_text_input(method)
|
11
|
+
self.show_method_input(method) do
|
12
|
+
self.text_field(method, :class => 'xlarge', :id => 'xlInput')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def show_email_input(method)
|
17
|
+
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")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def show_password_input(method)
|
26
|
+
self.show_method_input(method) do
|
27
|
+
self.password_field(method, :class => 'xlarge', :id => 'xlInput')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def show_memo_input(method)
|
32
|
+
self.show_method_input(method) do
|
33
|
+
self.text_area(method, :class => 'xlarge', :id => 'xlInput', :rows => '5', :cols => '10')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
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
|
42
|
+
yield
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
protected
|
48
|
+
|
49
|
+
def current_text_group
|
50
|
+
self.object.class.to_s.underscore
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'showbuilder/builders/template_methods'
|
2
|
+
require 'showbuilder/builders/model_list_builder/show_columns'
|
3
|
+
require 'showbuilder/i18n_text'
|
4
|
+
|
5
|
+
module Showbuilder
|
6
|
+
module Builders
|
7
|
+
class ModelListBuilder
|
8
|
+
include Showbuilder::I18nText
|
9
|
+
include Showbuilder::Builders::TemplateMethods
|
10
|
+
include Showbuilder::Builders::ModelListBuilder::ShowColumns
|
11
|
+
|
12
|
+
class Column
|
13
|
+
attr_accessor :methods
|
14
|
+
attr_accessor :build_body_column_method
|
15
|
+
attr_accessor :build_header_column_method
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :template
|
19
|
+
attr_reader :text_group
|
20
|
+
attr_accessor :columns
|
21
|
+
|
22
|
+
def initialize(template, text_group)
|
23
|
+
@template = template
|
24
|
+
@text_group = text_group
|
25
|
+
self.columns = []
|
26
|
+
end
|
27
|
+
|
28
|
+
def build_model_list(models, &block)
|
29
|
+
block.call(self)
|
30
|
+
|
31
|
+
contents_tag(:table, :class => 'bordered-table zebra-striped') do |contents|
|
32
|
+
contents << self.build_header
|
33
|
+
contents << self.build_body(models)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
def build_header
|
40
|
+
self.content_tag :thead do
|
41
|
+
self.contents_tag :tr do |contents|
|
42
|
+
self.columns.each do |column|
|
43
|
+
contents << self.build_header_column(column)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def build_header_column(column)
|
50
|
+
if column.build_header_column_method
|
51
|
+
column.build_header_column_method.call(column)
|
52
|
+
else
|
53
|
+
self.content_tag(:th) do
|
54
|
+
if column.methods
|
55
|
+
methods = Array.wrap(column.methods)
|
56
|
+
text_id = methods.join('.')
|
57
|
+
self.current_itext(text_id)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def build_body(models)
|
64
|
+
models ||= []
|
65
|
+
|
66
|
+
contents_tag :tbody do |contents|
|
67
|
+
if models.count == 0
|
68
|
+
contents << build_body_row_for_no_record
|
69
|
+
else
|
70
|
+
models.each do |model|
|
71
|
+
contents << build_body_row(model)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def build_body_row(model)
|
78
|
+
options = self.build_body_row_options
|
79
|
+
contents_tag(:tr, options)do |contents|
|
80
|
+
self.columns.each do |column|
|
81
|
+
contents << self.build_body_column(column, model)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def build_body_row_options
|
87
|
+
even = self.cycle('', 'even')
|
88
|
+
{:class => even}
|
89
|
+
end
|
90
|
+
|
91
|
+
def build_body_row_for_no_record
|
92
|
+
contents_tag :tr do |contents|
|
93
|
+
self.columns.each_index do |index|
|
94
|
+
contents << self.content_tag(:td) do
|
95
|
+
itext('no_record') if index == 0
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def build_body_column(column, model)
|
102
|
+
if column.build_body_column_method
|
103
|
+
column.build_body_column_method.call(model)
|
104
|
+
else
|
105
|
+
self.tag(:td)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def current_text_group
|
110
|
+
@text_group || self.controller_name.to_s.singularize
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
module Showbuilder
|
2
|
+
module Builders
|
3
|
+
class ModelListBuilder
|
4
|
+
module ShowColumns
|
5
|
+
|
6
|
+
# show_text_column :number
|
7
|
+
# show_text_column :member, :number
|
8
|
+
def show_text_column(*methods)
|
9
|
+
self.show_method_column(methods) do |value|
|
10
|
+
self.safe_html_string(value)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# show_text_link_column :number
|
15
|
+
# show_text_link_column :member, :number
|
16
|
+
def show_text_link_column(*methods)
|
17
|
+
self.show_method_link_column(*methods) do |value|
|
18
|
+
self.safe_html_string(value)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# show_time_column :created_at
|
23
|
+
def show_time_column(*methods)
|
24
|
+
self.show_method_column(methods) do |value|
|
25
|
+
self.time_string(value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# show_date_column :created_at
|
30
|
+
def show_date_column(*methods)
|
31
|
+
self.show_method_column(methods) do |value|
|
32
|
+
self.date_string(value)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# show_date_link_column :created_at
|
37
|
+
def show_date_link_column(*methods)
|
38
|
+
self.show_method_link_column(*methods) do |value|
|
39
|
+
self.date_string(value)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# show_currency_column :total
|
44
|
+
def show_currency_column(*methods)
|
45
|
+
self.show_method_column(methods) do |value|
|
46
|
+
self.currency_string(value)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# show_percent_column :percent
|
51
|
+
def show_percent_column(*methods)
|
52
|
+
self.show_method_column(methods) do |value|
|
53
|
+
self.percent_string(value)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def show_method_column(methods, &block)
|
58
|
+
self.show_column(methods) do |model|
|
59
|
+
self.content_tag(:td) do
|
60
|
+
method_value = self.call_object_methods(model, methods)
|
61
|
+
if block
|
62
|
+
content = block.call(method_value)
|
63
|
+
else
|
64
|
+
content = method_value
|
65
|
+
end
|
66
|
+
content.to_s
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def show_method_link_column(*methods, &customize_link_name_block)
|
72
|
+
if methods.count == 0
|
73
|
+
raise 'show_method_link_column need a argument!'
|
74
|
+
end
|
75
|
+
|
76
|
+
self.show_column(methods) do |model|
|
77
|
+
self.content_tag(:td) do
|
78
|
+
link_object = self.show_method_link_column__get_link_object(model, methods)
|
79
|
+
link_name = self.show_method_link_column__get_link_name(model, methods, customize_link_name_block)
|
80
|
+
self.link_to link_name, link_object
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def show_method_link_column__get_link_object(model, methods)
|
86
|
+
case methods.count
|
87
|
+
when 1
|
88
|
+
model
|
89
|
+
else
|
90
|
+
self.call_object_methods(model, methods.first)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def show_method_link_column__get_link_name(model, methods, customize_link_name_block)
|
95
|
+
method_value = self.call_object_methods(model, methods)
|
96
|
+
if customize_link_name_block
|
97
|
+
link_name = customize_link_name_block.call(method_value)
|
98
|
+
else
|
99
|
+
link_name = method_value
|
100
|
+
end
|
101
|
+
link_name.to_s
|
102
|
+
end
|
103
|
+
|
104
|
+
def show_column(methods = nil, build_header_column_method = nil, &build_body_column_method)
|
105
|
+
column = ModelListBuilder::Column.new
|
106
|
+
column.methods = methods
|
107
|
+
column.build_header_column_method = build_header_column_method
|
108
|
+
column.build_body_column_method = build_body_column_method
|
109
|
+
self.columns << column
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'showbuilder/builders/template_methods'
|
2
|
+
require 'showbuilder/i18n_text'
|
3
|
+
|
4
|
+
module Showbuilder
|
5
|
+
module Builders
|
6
|
+
class ModelViewBuilder
|
7
|
+
include Showbuilder::Builders::TemplateMethods
|
8
|
+
include Showbuilder::I18nText
|
9
|
+
|
10
|
+
attr_reader :model
|
11
|
+
|
12
|
+
def initialize(model, template)
|
13
|
+
@model = model
|
14
|
+
@template = template
|
15
|
+
end
|
16
|
+
|
17
|
+
def build_model_view(&block)
|
18
|
+
unless @model
|
19
|
+
return
|
20
|
+
end
|
21
|
+
self.content_tag(:table, :class => "bordered-table") do
|
22
|
+
@template.capture(self, &block)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def show_text(method)
|
27
|
+
self.show_method_field(method) do |value|
|
28
|
+
self.safe_html_string(value)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def show_text_link(link_method, text_method)
|
33
|
+
methods = [link_method, text_method]
|
34
|
+
method_label = self.current_itext(methods)
|
35
|
+
method_value = self.call_object_methods(model, methods)
|
36
|
+
method_link = self.call_object_methods(model, link_method)
|
37
|
+
|
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)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def show_time(method)
|
47
|
+
self.show_method_field(method) do |value|
|
48
|
+
self.time_string(value)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def show_date(method)
|
53
|
+
self.show_method_field(method) do |value|
|
54
|
+
self.date_string(value)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def show_currency(method)
|
59
|
+
self.show_method_field(method) do |value|
|
60
|
+
self.currency_string(value)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def show_percent(method)
|
65
|
+
self.show_method_field(method) do |value|
|
66
|
+
self.percent_string(value)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def show_method_field(method, &block)
|
71
|
+
method_label = self.current_itext(method)
|
72
|
+
method_value = self.call_object_methods(model, method)
|
73
|
+
if block
|
74
|
+
method_value = block.call(method_value)
|
75
|
+
end
|
76
|
+
|
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")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
protected
|
84
|
+
|
85
|
+
def current_text_group
|
86
|
+
self.model.class.to_s.underscore
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Showbuilder
|
2
|
+
module Builders
|
3
|
+
module TemplateMethods
|
4
|
+
attr_reader :template
|
5
|
+
|
6
|
+
def method_missing(method_name, *args, &block)
|
7
|
+
if self.template.respond_to?(method_name)
|
8
|
+
self.template.send(method_name, *args, &block)
|
9
|
+
else
|
10
|
+
raise NoMethodError.new("#{self} not has a method, that is #{method_name}.", method_name, args)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Showbuilder
|
2
|
+
module Corekit
|
3
|
+
def html_contents
|
4
|
+
contents = []
|
5
|
+
yield contents
|
6
|
+
contents.join(' ').html_safe
|
7
|
+
end
|
8
|
+
|
9
|
+
def contents_tag(tag_name, options = {}, &block)
|
10
|
+
self.content_tag tag_name, options do
|
11
|
+
self.html_contents(&block)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def currency_string(number)
|
16
|
+
if number
|
17
|
+
number_to_currency(number)
|
18
|
+
else
|
19
|
+
''
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def date_string(date)
|
24
|
+
case date
|
25
|
+
when Date
|
26
|
+
I18n.l(date)
|
27
|
+
when Time
|
28
|
+
time = date
|
29
|
+
date = time.to_date
|
30
|
+
I18n.l(date)
|
31
|
+
else
|
32
|
+
date.to_s
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def percent_string(number)
|
37
|
+
if number
|
38
|
+
number_to_percentage(number, :precision => 2)
|
39
|
+
else
|
40
|
+
''
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def time_string(time)
|
45
|
+
if time
|
46
|
+
I18n.l(time)
|
47
|
+
else
|
48
|
+
''
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def safe_html_string(text)
|
53
|
+
if text.is_a?(String)
|
54
|
+
text.gsub(/\n/, "<br/>").html_safe
|
55
|
+
else
|
56
|
+
text.to_s
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Showbuilder
|
2
|
+
module I18nText
|
3
|
+
|
4
|
+
def current_itext(text_id, *args)
|
5
|
+
case text_id
|
6
|
+
when Array
|
7
|
+
text_id = text_id.join('.')
|
8
|
+
end
|
9
|
+
|
10
|
+
if self.current_text_group
|
11
|
+
crrent_text_id = "#{self.current_text_group}.#{text_id}"
|
12
|
+
else
|
13
|
+
crrent_text_id = text_id
|
14
|
+
end
|
15
|
+
|
16
|
+
self.itext(crrent_text_id, *args)
|
17
|
+
end
|
18
|
+
|
19
|
+
def current_text_group
|
20
|
+
end
|
21
|
+
|
22
|
+
def itext(id, *args)
|
23
|
+
I18n.t(id, *args)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'showbuilder/builders/form_builder'
|
2
|
+
|
3
|
+
module Showbuilder
|
4
|
+
module ShowForm
|
5
|
+
def show_form(url, &block)
|
6
|
+
self.form_tag url do
|
7
|
+
builder = Showbuilder::Builders::FormBuilder.new(self)
|
8
|
+
self.capture(builder, &block)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'showbuilder/builders/model_form_builder'
|
2
|
+
|
3
|
+
module Showbuilder
|
4
|
+
module ShowModelForm
|
5
|
+
|
6
|
+
#
|
7
|
+
# show_model_form @customer do |form|
|
8
|
+
# form.show_text_input :name
|
9
|
+
# form.show_email_input :email
|
10
|
+
# form.show_password_input :password
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# dependents:
|
14
|
+
# puts @customer.class.to_s.underscore # customer
|
15
|
+
# I18n.t('customer.name')
|
16
|
+
# I18n.t("customer.email')
|
17
|
+
# I18n.t('customer.password')
|
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)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
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
|
39
|
+
end
|
40
|
+
messages.flatten!
|
41
|
+
|
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
|
51
|
+
contents << content_tag(:ul) do
|
52
|
+
list_items = messages.map do |msg|
|
53
|
+
content_tag(:li, msg)
|
54
|
+
end
|
55
|
+
list_items.join.html_safe
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'showbuilder/builders/model_list_builder'
|
2
|
+
|
3
|
+
module Showbuilder
|
4
|
+
module ShowModelList
|
5
|
+
#
|
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
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
def show_model_list(models, text_group = nil, &block)
|
21
|
+
builder = Showbuilder::Builders::ModelListBuilder.new(self, text_group)
|
22
|
+
builder.build_model_list(models, &block)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'showbuilder/builders/model_view_builder'
|
2
|
+
|
3
|
+
module Showbuilder
|
4
|
+
module ShowModelView
|
5
|
+
#
|
6
|
+
# show_model_view @product do |view|
|
7
|
+
# view.show_text :name
|
8
|
+
# view.show_time :last_update
|
9
|
+
# view.show_currency :price
|
10
|
+
# view.show_percent :discount
|
11
|
+
# view.show_text_link :vendor, :name
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# dependents:
|
15
|
+
# text_group = @product.class.to_s.underscore
|
16
|
+
# I18n.t("#{text_group}.number")
|
17
|
+
# I18n.t("#{text_group}.name")
|
18
|
+
# I18n.t("#{text_group}.price")
|
19
|
+
#
|
20
|
+
def show_model_view(model, &block)
|
21
|
+
builder = Showbuilder::Builders::ModelViewBuilder.new(model, self)
|
22
|
+
builder.build_model_view(&block)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'will_paginate'
|
2
|
+
require 'will_paginate/view_helpers/action_view'
|
3
|
+
|
4
|
+
module Showbuilder
|
5
|
+
class ShowPaginateRenderer < WillPaginate::ActionView::LinkRenderer
|
6
|
+
def to_html
|
7
|
+
links = @options[:page_links] ? windowed_links : []
|
8
|
+
|
9
|
+
links.unshift(page_link_or_span(@collection.previous_page, 'prev', @options[:previous_label]))
|
10
|
+
links.push(page_link_or_span(@collection.next_page, 'next', @options[:next_label]))
|
11
|
+
|
12
|
+
html = links.join(@options[:link_separator])
|
13
|
+
|
14
|
+
html_content = @template.content_tag(:div, :class => :pagination) do
|
15
|
+
@template.content_tag(:ul, html.html_safe)
|
16
|
+
end
|
17
|
+
@options[:container] ? html_content : html
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def windowed_links
|
23
|
+
windowed_page_numbers.map { |n| page_link_or_span(n, (n == current_page ? 'active' : nil)) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def page_link_or_span(page, span_class, text = nil)
|
27
|
+
text ||= page.to_s
|
28
|
+
if page == :gap
|
29
|
+
text = gap_marker
|
30
|
+
end
|
31
|
+
if page && page != current_page && page != :gap
|
32
|
+
page_link(page, text, :class => span_class)
|
33
|
+
else if page == current_page || page == :gap
|
34
|
+
page_span(page, text, :class => span_class)
|
35
|
+
else
|
36
|
+
previous_or_next_page(page)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def page_link(page, text, attributes = {})
|
42
|
+
@template.content_tag(:li, attributes) do
|
43
|
+
@template.link_to(text, url(page)).html_safe
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def page_span(page, text, attributes = {})
|
48
|
+
@template.content_tag :li, attributes do
|
49
|
+
@template.content_tag(:a, text)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def gap_marker
|
54
|
+
@template.will_paginate_translate(:page_gap) { '…' }
|
55
|
+
end
|
56
|
+
|
57
|
+
def previous_or_next_page(page)
|
58
|
+
if @collection.current_page <= 1 && @collection.current_page - 1 <= 0
|
59
|
+
return page_span(page, @options[:previous_label], :class => "prev disabled")
|
60
|
+
end
|
61
|
+
|
62
|
+
if @collection.current_page <= @collection.total_pages && @collection.current_page + 1 >= @collection.total_pages
|
63
|
+
return page_span(page, @options[:next_label], :class => "next disabled")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: showbuilder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ery wang
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
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
|
36
|
+
description: A Rails View Helper. Show model/s as view, form, list.
|
37
|
+
email: ery@baoleihang.com
|
38
|
+
executables: []
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- lib/showbuilder.rb
|
43
|
+
- lib/showbuilder/show_model_view.rb
|
44
|
+
- lib/showbuilder/i18n_text.rb
|
45
|
+
- lib/showbuilder/corekit.rb
|
46
|
+
- lib/showbuilder/show_paginate_renderer.rb
|
47
|
+
- lib/showbuilder/show_model_list.rb
|
48
|
+
- lib/showbuilder/builders/template_methods.rb
|
49
|
+
- lib/showbuilder/builders/model_list_builder.rb
|
50
|
+
- lib/showbuilder/builders/form_builder.rb
|
51
|
+
- lib/showbuilder/builders/model_form_builder.rb
|
52
|
+
- lib/showbuilder/builders/model_view_builder.rb
|
53
|
+
- lib/showbuilder/builders/model_list_builder/show_columns.rb
|
54
|
+
- lib/showbuilder/show_model_form.rb
|
55
|
+
- lib/showbuilder/show_form.rb
|
56
|
+
homepage: https://github.com/ery/showbuilder
|
57
|
+
licenses: []
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 1.8.13
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: A Rails View Helper.
|
80
|
+
test_files: []
|