sugar 0.0.31 → 0.0.32
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/VERSION +1 -1
- data/lib/sugar/actionview/forms.rb +110 -0
- data/lib/sugar/actionview/structure.rb +60 -0
- data/lib/sugar/actionview.rb +5 -157
- data/sugar.gemspec +4 -2
- metadata +4 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.32
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module Sugar
|
2
|
+
module Actionview
|
3
|
+
module Forms
|
4
|
+
# Put submit with proper text
|
5
|
+
def submit(form, title = nil)
|
6
|
+
title ||= t("#{form.object.class.name.tableize}.#{form.object.new_record? ? :new : :edit}.submit",
|
7
|
+
:default => Rails.env.production? ?
|
8
|
+
(form.object.new_record? ?
|
9
|
+
"#{t('krasivotokak.sugar.create', :default => 'Add')} #{form.object.class.human_name}" :
|
10
|
+
"#{t('krasivotokak.sugar.update', :default => 'Save')} #{form.object.class.human_name}") :
|
11
|
+
nil
|
12
|
+
)
|
13
|
+
form.submit(title)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Build image submit
|
17
|
+
def image_to(src, name, options = {}, html_options = {})
|
18
|
+
html_options = html_options.stringify_keys
|
19
|
+
convert_boolean_attributes!(html_options, %w( disabled ))
|
20
|
+
|
21
|
+
method_tag = ''
|
22
|
+
if (method = html_options.delete('method')) && %w{put delete}.include?(method.to_s)
|
23
|
+
method_tag = tag('input', :type => 'hidden', :name => '_method', :value => method.to_s)
|
24
|
+
end
|
25
|
+
|
26
|
+
form_method = method.to_s == 'get' ? 'get' : 'post'
|
27
|
+
|
28
|
+
request_token_tag = ''
|
29
|
+
if form_method == 'post' && protect_against_forgery?
|
30
|
+
request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token)
|
31
|
+
end
|
32
|
+
|
33
|
+
if confirm = html_options.delete("confirm")
|
34
|
+
html_options["onclick"] = "return #{confirm_javascript_function(confirm)};"
|
35
|
+
end
|
36
|
+
|
37
|
+
url = options.is_a?(String) ? options : self.url_for(options)
|
38
|
+
|
39
|
+
html_options.merge!("type" => "image", "src" => image_path(src), :alt => name, :title => name)
|
40
|
+
|
41
|
+
"<form method=\"#{form_method}\" action=\"#{escape_once url}\" class=\"button-to action\"><div class=\"b_input b_input-imagebutton\">" +
|
42
|
+
method_tag + tag("input", html_options) + request_token_tag + "</div></form>"
|
43
|
+
end
|
44
|
+
|
45
|
+
def button_to_delete(something, title = nil)
|
46
|
+
title ||= t('.delete',
|
47
|
+
:default => %(Delete #{(something.is_a?(Array) ? something.last : something).class.human_name}))
|
48
|
+
button_to(title,
|
49
|
+
polymorphic_path(something),
|
50
|
+
:class => 'delete action',
|
51
|
+
:method => :delete,
|
52
|
+
:confirm => t('sure', :default => 'Are you sure?'))
|
53
|
+
end
|
54
|
+
|
55
|
+
def image_button_to_delete(something)
|
56
|
+
image_to('icons/delete.png',
|
57
|
+
t('.delete', :default => 'Delete'),
|
58
|
+
polymorphic_path(something),
|
59
|
+
:class => 'delete action',
|
60
|
+
:method => :delete,
|
61
|
+
:confirm => t('sure'))
|
62
|
+
end
|
63
|
+
|
64
|
+
def link_to_edit(something)
|
65
|
+
text = t('.edit', :default => [:'krasivotokak.sugar.edit', 'Edit'])
|
66
|
+
link_to(image_tag('icons/edit.png',
|
67
|
+
:alt => text,
|
68
|
+
:title => text),
|
69
|
+
edit_polymorphic_path(something),
|
70
|
+
:class => 'ajax edit action')
|
71
|
+
end
|
72
|
+
|
73
|
+
def link_to_delete(something)
|
74
|
+
link_to(image_tag('icons/delete.png',
|
75
|
+
:alt => t('.delete', :default => 'Delete'),
|
76
|
+
:title => t('.delete', :default => 'Delete')),
|
77
|
+
polymorphic_path(something),
|
78
|
+
:class => 'ajax action delete')
|
79
|
+
end
|
80
|
+
|
81
|
+
def default_new_link_options
|
82
|
+
@default_new_link_options ||= {
|
83
|
+
:image => 'icons/add.png',
|
84
|
+
:alt => t('.add', :default => 'Add'),
|
85
|
+
:title => t('.add', :default => 'Add')
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
def link_to_new(options = {})
|
90
|
+
options = default_new_link_options.merge(options || {})
|
91
|
+
url = options.has_key?(:url) ? options.delete(:url) : {:action => 'new'}
|
92
|
+
link_to(image_tag(options.delete(:image),
|
93
|
+
options),
|
94
|
+
url, :class => 'action')
|
95
|
+
end
|
96
|
+
|
97
|
+
def period_field(form, field)
|
98
|
+
content_tag :div, :class => 'b_input b_input-period' do
|
99
|
+
returning '' do |content|
|
100
|
+
content << form.label(:"#{field}_min")
|
101
|
+
content << form.text_field(:"#{field}_min")
|
102
|
+
content << form.label(:"#{field}_max", '—', :class => 'period')
|
103
|
+
content << form.text_field(:"#{field}_max")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Sugar
|
2
|
+
module Actionview
|
3
|
+
module Structure
|
4
|
+
VIEW_PLACEHOLDERS = {
|
5
|
+
'create' => 'new',
|
6
|
+
'update' => 'edit'
|
7
|
+
}
|
8
|
+
|
9
|
+
def view_name
|
10
|
+
action_name = controller.action_name
|
11
|
+
VIEW_PLACEHOLDERS[action_name] || action_name
|
12
|
+
end
|
13
|
+
|
14
|
+
def default_page_title
|
15
|
+
text = case action_name
|
16
|
+
when 'index'
|
17
|
+
controller_name.camelize
|
18
|
+
when 'new', 'create'
|
19
|
+
"#{t('krasivotokak.sugar.new', :default => 'New')} #{controller_name.classify.constantize.human_name}"
|
20
|
+
when 'edit', 'update'
|
21
|
+
"#{t('krasivotokak.sugar.edit', :default => 'Editing')} #{controller_name.classify.constantize.human_name}"
|
22
|
+
else
|
23
|
+
t("#{controller_name}.#{view_name}.title")
|
24
|
+
end
|
25
|
+
%(<span class="trasnlation_missing">#{text}</span>)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Return page title for use in layout
|
29
|
+
def page_title(title = nil)
|
30
|
+
@page_title = if title
|
31
|
+
title
|
32
|
+
else
|
33
|
+
@page_title || t("#{controller_name}.#{view_name}.title", :default => Rails.env.production? ? default_page_title : nil)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def html_page_title(default = false, separator = ' | ')
|
38
|
+
default ||= t('application.title')
|
39
|
+
[page_title, default].compat.join(separator)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Build simple navigation list
|
43
|
+
def navigation_list(menu)
|
44
|
+
returning '' do |result|
|
45
|
+
menu.each do |item|
|
46
|
+
path = "/#{item}"
|
47
|
+
uri = request.request_uri
|
48
|
+
title = t("#{item}.index.title", :default => item.to_s.camelize)
|
49
|
+
result << content_tag(:li, :class => uri.starts_with?(path) ? 'selected' : nil) do
|
50
|
+
link_to_unless_current(title, path) {
|
51
|
+
content_tag(:strong, title)
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/sugar/actionview.rb
CHANGED
@@ -1,162 +1,10 @@
|
|
1
|
+
require 'sugar/actionview/forms'
|
2
|
+
require 'sugar/actionview/structure'
|
3
|
+
|
1
4
|
module Sugar
|
2
5
|
module Actionview
|
3
|
-
|
4
|
-
|
5
|
-
'update' => 'edit'
|
6
|
-
}
|
7
|
-
|
8
|
-
def view_name
|
9
|
-
action_name = controller.action_name
|
10
|
-
VIEW_PLACEHOLDERS[action_name] || action_name
|
11
|
-
end
|
12
|
-
|
13
|
-
def default_page_title
|
14
|
-
text = case action_name
|
15
|
-
when 'index'
|
16
|
-
controller_name.camelize
|
17
|
-
when 'new', 'create'
|
18
|
-
"#{t('krasivotokak.sugar.new', :default => 'New')} #{controller_name.classify.constantize.human_name}"
|
19
|
-
when 'edit', 'update'
|
20
|
-
"#{t('krasivotokak.sugar.edit', :default => 'Editing')} #{controller_name.classify.constantize.human_name}"
|
21
|
-
else
|
22
|
-
t("#{controller_name}.#{view_name}.title")
|
23
|
-
end
|
24
|
-
%(<span class="trasnlation_missing">#{text}</span>)
|
25
|
-
end
|
26
|
-
|
27
|
-
# Return page title for use in layout
|
28
|
-
def page_title(title = nil)
|
29
|
-
@page_title = if title
|
30
|
-
title
|
31
|
-
else
|
32
|
-
@page_title || t("#{controller_name}.#{view_name}.title", :default => Rails.env.production? ? default_page_title : nil)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def html_page_title(default = false, separator = ' | ')
|
37
|
-
default ||= t('application.title')
|
38
|
-
[page_title, default].compat.join(separator)
|
39
|
-
end
|
40
|
-
|
41
|
-
# Put submit with proper text
|
42
|
-
def submit(form, title = nil)
|
43
|
-
title ||= t("#{form.object.class.name.tableize}.#{form.object.new_record? ? :new : :edit}.submit",
|
44
|
-
:default => Rails.env.production? ?
|
45
|
-
(form.object.new_record? ?
|
46
|
-
"#{t('krasivotokak.sugar.create', :default => 'Add')} #{form.object.class.human_name}" :
|
47
|
-
"#{t('krasivotokak.sugar.update', :default => 'Save')} #{form.object.class.human_name}") :
|
48
|
-
nil
|
49
|
-
)
|
50
|
-
form.submit(title)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Build simple navigation list
|
54
|
-
def navigation_list(menu)
|
55
|
-
returning '' do |result|
|
56
|
-
menu.each do |item|
|
57
|
-
path = "/#{item}"
|
58
|
-
uri = request.request_uri
|
59
|
-
title = t("#{item}.index.title", :default => item.to_s.camelize)
|
60
|
-
result << content_tag(:li, :class => uri.starts_with?(path) ? 'selected' : nil) do
|
61
|
-
link_to_unless_current(title, path) {
|
62
|
-
content_tag(:strong, title)
|
63
|
-
}
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# Build image submit
|
70
|
-
def image_to(src, name, options = {}, html_options = {})
|
71
|
-
html_options = html_options.stringify_keys
|
72
|
-
convert_boolean_attributes!(html_options, %w( disabled ))
|
73
|
-
|
74
|
-
method_tag = ''
|
75
|
-
if (method = html_options.delete('method')) && %w{put delete}.include?(method.to_s)
|
76
|
-
method_tag = tag('input', :type => 'hidden', :name => '_method', :value => method.to_s)
|
77
|
-
end
|
78
|
-
|
79
|
-
form_method = method.to_s == 'get' ? 'get' : 'post'
|
80
|
-
|
81
|
-
request_token_tag = ''
|
82
|
-
if form_method == 'post' && protect_against_forgery?
|
83
|
-
request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token)
|
84
|
-
end
|
85
|
-
|
86
|
-
if confirm = html_options.delete("confirm")
|
87
|
-
html_options["onclick"] = "return #{confirm_javascript_function(confirm)};"
|
88
|
-
end
|
89
|
-
|
90
|
-
url = options.is_a?(String) ? options : self.url_for(options)
|
91
|
-
|
92
|
-
html_options.merge!("type" => "image", "src" => image_path(src), :alt => name, :title => name)
|
93
|
-
|
94
|
-
"<form method=\"#{form_method}\" action=\"#{escape_once url}\" class=\"button-to action\"><div class=\"b_input b_input-imagebutton\">" +
|
95
|
-
method_tag + tag("input", html_options) + request_token_tag + "</div></form>"
|
96
|
-
end
|
97
|
-
|
98
|
-
def link_to_edit(something)
|
99
|
-
text = t('.edit', :default => [:'krasivotokak.sugar.edit', 'Edit'])
|
100
|
-
link_to(image_tag('icons/edit.png',
|
101
|
-
:alt => text,
|
102
|
-
:title => text),
|
103
|
-
edit_polymorphic_path(something),
|
104
|
-
:class => 'ajax edit action')
|
105
|
-
end
|
106
|
-
|
107
|
-
def button_to_delete(something, title = nil)
|
108
|
-
title ||= t('.delete',
|
109
|
-
:default => %(Delete #{(something.is_a?(Array) ? something.last : something).class.human_name}))
|
110
|
-
button_to(title,
|
111
|
-
polymorphic_path(something),
|
112
|
-
:class => 'delete action',
|
113
|
-
:method => :delete,
|
114
|
-
:confirm => t('sure', :default => 'Are you sure?'))
|
115
|
-
end
|
116
|
-
|
117
|
-
def image_button_to_delete(something)
|
118
|
-
image_to('icons/delete.png',
|
119
|
-
t('.delete', :default => 'Delete'),
|
120
|
-
polymorphic_path(something),
|
121
|
-
:class => 'delete action',
|
122
|
-
:method => :delete,
|
123
|
-
:confirm => t('sure'))
|
124
|
-
end
|
125
|
-
|
126
|
-
def link_to_delete(something)
|
127
|
-
link_to(image_tag('icons/delete.png',
|
128
|
-
:alt => t('.delete', :default => 'Delete'),
|
129
|
-
:title => t('.delete', :default => 'Delete')),
|
130
|
-
polymorphic_path(something),
|
131
|
-
:class => 'ajax action delete')
|
132
|
-
end
|
133
|
-
|
134
|
-
def default_new_link_options
|
135
|
-
@default_new_link_options ||= {
|
136
|
-
:image => 'icons/add.png',
|
137
|
-
:alt => t('.add', :default => 'Add'),
|
138
|
-
:title => t('.add', :default => 'Add')
|
139
|
-
}
|
140
|
-
end
|
141
|
-
|
142
|
-
def link_to_new(options = {})
|
143
|
-
options = default_new_link_options.merge(options || {})
|
144
|
-
url = options.has_key?(:url) ? options.delete(:url) : {:action => 'new'}
|
145
|
-
link_to(image_tag(options.delete(:image),
|
146
|
-
options),
|
147
|
-
url, :class => 'action')
|
148
|
-
end
|
149
|
-
|
150
|
-
def period_field(form, field)
|
151
|
-
content_tag :div, :class => 'b_input b_input-period' do
|
152
|
-
returning '' do |content|
|
153
|
-
content << form.label(:"#{field}_min")
|
154
|
-
content << form.text_field(:"#{field}_min")
|
155
|
-
content << form.label(:"#{field}_max", '—', :class => 'period')
|
156
|
-
content << form.text_field(:"#{field}_max")
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
6
|
+
include Sugar::Actionview::Structure
|
7
|
+
include Sugar::Actionview::Forms
|
160
8
|
|
161
9
|
def human(*args)
|
162
10
|
if args.size == 2
|
data/sugar.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sugar}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.32"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Alexander Semyonov"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-10-11}
|
13
13
|
s.email = %q{rotuka@tokak.ru}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
@@ -26,6 +26,8 @@ Gem::Specification.new do |s|
|
|
26
26
|
"lib/sugar.rb",
|
27
27
|
"lib/sugar/actioncontroller.rb",
|
28
28
|
"lib/sugar/actionview.rb",
|
29
|
+
"lib/sugar/actionview/forms.rb",
|
30
|
+
"lib/sugar/actionview/structure.rb",
|
29
31
|
"lib/sugar/activerecord.rb",
|
30
32
|
"lib/sugar/locales/en.yml",
|
31
33
|
"lib/sugar/locales/ru.yml",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sugar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.32
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Semyonov
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-10-11 00:00:00 +04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -33,6 +33,8 @@ files:
|
|
33
33
|
- lib/sugar.rb
|
34
34
|
- lib/sugar/actioncontroller.rb
|
35
35
|
- lib/sugar/actionview.rb
|
36
|
+
- lib/sugar/actionview/forms.rb
|
37
|
+
- lib/sugar/actionview/structure.rb
|
36
38
|
- lib/sugar/activerecord.rb
|
37
39
|
- lib/sugar/locales/en.yml
|
38
40
|
- lib/sugar/locales/ru.yml
|