gaku_helpers 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ View Helpers for Twitter Bootstrap
@@ -0,0 +1,19 @@
1
+ # encoding: UTF-8
2
+ Gem::Specification.new do |s|
3
+ s.platform = Gem::Platform::RUBY
4
+ s.name = 'gaku_helpers'
5
+ s.version = '0.0.1'
6
+ s.summary = 'Gaku View Helpers'
7
+ s.description = ''
8
+ s.required_ruby_version = '>= 1.8.7'
9
+
10
+ s.author = 'Vassil Kalkov'
11
+ s.email = 'vassilkalkov@gmail.com'
12
+ s.homepage = 'http://kalkov.github.io'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
16
+
17
+ s.require_path = 'lib'
18
+ s.requirements << 'none'
19
+ end
@@ -0,0 +1 @@
1
+ require 'gaku_helpers/railtie' if defined?(Rails::Railtie)
@@ -0,0 +1,13 @@
1
+ require 'gaku_helpers/view_helpers'
2
+ module GakuHelpers
3
+ class Railtie < Rails::Railtie
4
+ initializer "gaku_helpers" do
5
+ I18n.load_path << Dir[File.join(File.expand_path(File.dirname(__FILE__) + '/../../locales'), '*.yml')]
6
+ I18n.load_path.flatten!
7
+ end
8
+
9
+ initializer "gaku_helpers.view_helpers" do
10
+ ActionView::Base.send :include, ViewHelpers
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ require 'gaku_helpers/view_helpers/link_helper'
2
+
3
+ module GakuHelpers
4
+ module ViewHelpers
5
+ ActionView::Base.send :include, LinkHelper
6
+ end
7
+ end
@@ -0,0 +1,224 @@
1
+ module GakuHelpers
2
+ module ViewHelpers
3
+ module LinkHelper
4
+
5
+ def link_to_add_fields(name, f, association)
6
+ new_object = f.object.send(association).klass.new
7
+ id = new_object.object_id
8
+ fields = f.fields_for(association, new_object, child_index: id) do |builder|
9
+ render(association.to_s.singularize + "_fields", f: builder)
10
+ end
11
+ link_to(("<i class='icon-plus icon-white'></i> " + name).html_safe, '#', :class => "btn btn-primary add_fields", data: {id: id, fields: fields.gsub("\n", "")})
12
+ end
13
+
14
+ def button(text, resource, options = {})
15
+ attributes = {:class => "btn mr-s"}.merge(options)
16
+ link_to text, resource, attributes
17
+ end
18
+
19
+ def primary_button(text, resource, options = {})
20
+ attributes = {:class => "btn btn-primary mr-s"}.merge(options)
21
+ link_to text, resource, attributes
22
+ end
23
+
24
+ def link_to_file(text, resource, options = {})
25
+ name = ("<i class='icon-white icon-file'></i> " + text).html_safe
26
+ attributes = {:class => "btn btn-primary"}.merge(options)
27
+ link_to name, resource, attributes
28
+ end
29
+
30
+ def link_to_upload_image(resource, options = {})
31
+ name = ("<i class='icon-camera'></i> " + t(:'gaku_helpers.picture.change')).html_safe
32
+ attributes = {:class => "btn span12 mr-s"}.merge(options)
33
+ link_to name, resource, attributes
34
+ end
35
+
36
+ def link_to_upload(options = {})
37
+ text = ("<i class='icon-upload'></i> " + t(:'gaku_helpers.picture.upload')).html_safe
38
+ attributes = {:class => "btn span12 mr-s"}.merge(options)
39
+ button_tag(content_tag('span', text), attributes)
40
+ end
41
+
42
+ def link_to_import(text, resource, options = {})
43
+ name = ('<i class="icon-upload"></i> '+ text).html_safe
44
+ attributes = {:class => 'mr-s btn'}.merge(options)
45
+ link_to name, resource, attributes
46
+ end
47
+
48
+ def link_to_export(text, resource, options = {})
49
+ name = ('<i class="icon-download"></i> '+ text).html_safe
50
+ attributes = {:class => 'mr-s btn'}.merge(options)
51
+ link_to name, resource, attributes
52
+ end
53
+
54
+ #needs id, because it is unique
55
+ def ajax_link_to_new(text, resource, options = {})
56
+ name = ("<i class='icon-white icon-plus'></i> " + text).html_safe
57
+ attributes = {
58
+ :remote => true,
59
+ :class => "btn btn-primary mr-s"
60
+ }.merge(options)
61
+ link_to name, resource, attributes
62
+ end
63
+
64
+ #needs id
65
+ def link_to_new(text, resource, options = {})
66
+ name = ("<i class='icon-white icon-plus'></i> " + text).html_safe
67
+ attributes = {:class => "btn btn-primary"}.merge(options)
68
+ link_to name, resource, attributes
69
+ end
70
+
71
+ #needs id
72
+ def submit_button(text, options={})
73
+ attributes = {:type => 'submit'}.merge(options)
74
+ button_tag(content_tag('span', text), attributes)
75
+ end
76
+
77
+ def ajax_link_to_recovery(resource, options = {})
78
+ name = content_tag(:i, nil, :class => 'icon-white icon-repeat')
79
+ attributes = {
80
+ :remote => true,
81
+ :class => "mr-xs btn btn-mini btn-warning recovery-link"
82
+ }.merge(options)
83
+ link_to name, resource, attributes
84
+ end
85
+
86
+ def ajax_link_to_delete(resource, options = {})
87
+ name = ("<i class='icon-white icon-remove'></i>").html_safe
88
+ attributes = {
89
+ :remote => true,
90
+ :method => :delete,
91
+ :data => { :confirm => t(:'gaku_helpers.are_you_sure') },
92
+ :class => 'btn btn-mini btn-danger delete-link'
93
+ }.merge(options)
94
+ link_to name, resource, attributes
95
+ end
96
+
97
+ def link_to_modal_delete(resource, options = {})
98
+ name = ("<i class='icon-white icon-trash'></i>").html_safe
99
+ attributes = {
100
+ :class => 'btn btn-danger modal-delete-link span12'
101
+ }.merge(options)
102
+ link_to name, resource, attributes
103
+ end
104
+
105
+ def ajax_soft_delete(resource, options = {})
106
+ name = ("<i class='icon-white icon-remove'></i>").html_safe
107
+ attributes = {
108
+ :remote => true,
109
+ :data => { :confirm => t(:'gaku_helpers.are_you_sure') },
110
+ :class => 'btn btn-mini btn-danger delete-link'
111
+ }.merge(options)
112
+ link_to name, resource, attributes
113
+ end
114
+
115
+
116
+ def primary_checkbox
117
+ ("<i class='icon-white icon-ok'></i>").html_safe
118
+ end
119
+
120
+ def ajax_link_to_make_primary(resource, options = {})
121
+ attributes = {
122
+ :remote => true,
123
+ :method => :post,
124
+ :data => { :confirm => t(:'gaku_helpers.are_you_sure') },
125
+ }.merge(options)
126
+ link_to primary_checkbox, resource, attributes
127
+ end
128
+
129
+ def ajax_link_to_edit(resource, options = {})
130
+ name = ("<i class='icon-white icon-pencil'></i>").html_safe
131
+ attributes = {
132
+ :remote => true,
133
+ :class => "mr-xs btn btn-mini btn-warning edit-link"
134
+ }.merge(options)
135
+ link_to name, resource, attributes
136
+ end
137
+
138
+
139
+ # Edit button with only pencil image - without text
140
+ def link_to_edit(resource, options = {})
141
+ name = ("<i class='icon-white icon-edit'></i>").html_safe
142
+ attributes = {
143
+ :class => "mr-xs btn btn-mini btn-inverse edit-link",
144
+ }.merge(options)
145
+ link_to name, resource, attributes
146
+ end
147
+
148
+ # Edit button with text "Edit" and pencil image
149
+ def link_to_edit_with_text(resource, options = {})
150
+ name = ('<i class="icon-pencil"></i> '+t(:'gaku_helpers.edit')).html_safe
151
+ attributes = {:class => "span12 btn edit-link"}.merge(options)
152
+ link_to name, resource, attributes
153
+ end
154
+
155
+ def link_to_edit_with_custom_text(text, resource, options = {})
156
+ name = ('<i class="icon-pencil"></i> '+ text).html_safe
157
+ attributes = {:class => "span12 btn edit-link"}.merge(options)
158
+ link_to name, resource, attributes
159
+ end
160
+
161
+ def ajax_link_to_show(resource, options = {})
162
+ name = ("<i class='icon-white icon-eye-open'></i>").html_safe
163
+ attributes = {
164
+ :remote => true,
165
+ :class => "mr-xs btn btn-mini btn-info show-link"
166
+ }.merge(options)
167
+ link_to name, resource, attributes
168
+ end
169
+
170
+ def link_to_show(resource, options = {})
171
+ name = ("<i class='icon-white icon-eye-open'></i>").html_safe
172
+ attributes = {
173
+ :class => "mr-xs btn btn-mini btn-info show-link"
174
+ }.merge(options)
175
+ link_to name, resource, attributes
176
+ end
177
+
178
+ def link_to_cancel(options = {})
179
+ text = ('<i class="icon-white icon-ban-circle"></i> '+ t(:'gaku_helpers.cancel')).html_safe
180
+ attributes = {
181
+ :class => "span6 btn btn-warning cancel-link",
182
+ :'data-dismiss' => "modal"
183
+ }.merge(options)
184
+ link_to text, '#', attributes
185
+ end
186
+
187
+ def link_to_modal_cancel(options = {})
188
+ name = t(:'gaku_helpers.cancel')
189
+ attributes = {
190
+ :class => "span6 btn btn-warning cancel-link"
191
+ }.merge(options)
192
+ link_to name, '#', attributes
193
+ end
194
+
195
+ def ajax_link_to_back(resource, options = {})
196
+ name = ('<i class="icon-white icon-share-alt"></i> ' + t(:'gaku_helpers.back')).html_safe
197
+ attributes = {
198
+ :class => "span6 btn btn-warning back-link back-modal-link",
199
+ :remote => true
200
+ }.merge(options)
201
+
202
+ link_to name, resource, attributes
203
+ end
204
+
205
+ def link_to_back(resource, options = {})
206
+ name = ('<i class="icon-share-alt"></i> '+ t(:'gaku_helpers.back')).html_safe
207
+ attributes = {
208
+ :class => 'span6 btn back-link'
209
+ }.merge(options)
210
+ link_to name, resource, attributes
211
+ end
212
+
213
+ def submit_button(text, options={})
214
+ text = ('<i class="icon-white icon-ok-circle"></i> '+ text).html_safe
215
+ attributes = {
216
+ :type => 'submit',
217
+ :class => 'span6 btn btn-primary button'
218
+ }.merge(options)
219
+ button_tag(content_tag('span', text), attributes)
220
+ end
221
+
222
+ end
223
+ end
224
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,10 @@
1
+ en:
2
+ gaku_helpers:
3
+ cancel: "Cancel"
4
+ back: "Back"
5
+ picture:
6
+ change: "Change picture"
7
+ upload: "Upload picture"
8
+ are_you_sure: "Are you sure?"
9
+ edit: "Edit"
10
+
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gaku_helpers
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Vassil Kalkov
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-04-22 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: ""
22
+ email: vassilkalkov@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - README.md
31
+ - gaku_helpers.gemspec
32
+ - lib/gaku_helpers.rb
33
+ - lib/gaku_helpers/railtie.rb
34
+ - lib/gaku_helpers/view_helpers.rb
35
+ - lib/gaku_helpers/view_helpers/link_helper.rb
36
+ - locales/en.yml
37
+ homepage: http://kalkov.github.io
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ hash: 57
51
+ segments:
52
+ - 1
53
+ - 8
54
+ - 7
55
+ version: 1.8.7
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements:
66
+ - none
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.15
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Gaku View Helpers
72
+ test_files: []
73
+