phantom_helpers 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7313e37159e507d586110b2bf57125ba2b920ad0
4
+ data.tar.gz: 30a4574583813152b82733843e1f6d9719bb172e
5
+ SHA512:
6
+ metadata.gz: 657c83eeb8f308d862790c6933f31ac4302bb2c6e2101f9105f50a5ad586d23360a659a833b8f5fac0721f354896fd9626315171581f8248ac2b11dc3017af40
7
+ data.tar.gz: b3b6ddcb066d409c47c61d3ec3b5f58b09c8c5420e89e94d3696ebd50db8c538152f41ff899c5b43ab25be6af0bdf1d7d4e347215bf3597191d3ca1113aff391
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/LICENSE.md ADDED
@@ -0,0 +1,15 @@
1
+ GAKU Engine is Copyright 2012 Genshin Souzou Kabushiki Kaisha of Aichi Japan
2
+ All rights reserved.
3
+
4
+ This software is dual licensed under the GNU GPL version 3 and the AGPL version 3.
5
+ The full text of these licenses can be found here:
6
+ https://gnu.org/licenses/gpl.html
7
+ https://gnu.org/licenses/agpl.html
8
+
9
+ Alternative licenses can be granted upon consultation.
10
+ Please contact info@genshin.org for details.
11
+
12
+ Some of the included sources were derived from the Spree project.
13
+ These portions are Copyright Spree Commerce Inc as per the following statement:
14
+ Copyright (c) 2007-2012, Spree Commerce, Inc. and other contributors
15
+ Copyright 2013 Genshin Souzou Kabushiki Kaisha; All Rights Reserved
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ What does it do?
2
+ ----------------
3
+ View Helpers for Twitter Bootstrap v3 :
4
+ ### [link_helper](https://github.com/Genshin/phantom_helpers/blob/master/lib/phantom_helpers/view_helpers/link_helper.rb)
5
+ ### [modal_helper] (https://github.com/Genshin/phantom_helpers/blob/master/lib/phantom_helpers/view_helpers/modal_helper.rb)
6
+ ### [table_helper] (https://github.com/Genshin/phantom_helpers/blob/master/lib/phantom_helpers/view_helpers/table_helper.rb)
7
+ ### [html_helper] (https://github.com/Genshin/phantom_helpers/blob/master/lib/phantom_helpers/view_helpers/html_helper.rb)
8
+
9
+ Instalation
10
+ -----------
11
+ Add to your `Gemfile`
12
+ ```ruby
13
+ gem 'phantom_helpers'
14
+ ```
15
+ Run bundle
16
+ ```shell
17
+ bundle
18
+ ```
@@ -0,0 +1,13 @@
1
+ require 'phantom_helpers/view_helpers'
2
+ module PhantomHelpers
3
+ class Railtie < Rails::Railtie
4
+ initializer "phantom_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 "phantom_helpers.view_helpers" do
10
+ ActionView::Base.send :include, ViewHelpers
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,65 @@
1
+ module PhantomHelpers
2
+ module ViewHelpers
3
+ module HtmlHelper
4
+
5
+ def hr
6
+ content_tag :div, class: "row" do
7
+ content_tag :div, class: "col-md-12" do
8
+ content_tag :hr
9
+ end
10
+ end
11
+ end
12
+
13
+ def well_div(&block)
14
+ content_tag :div, class: "row" do
15
+ content_tag :div, class: "col-md-12" do
16
+ content_tag :div, class: "well" do
17
+ block.call
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ def panel_div(color = 'default', title = nil, footer = nil, &block)
24
+ content_tag :div, class: "row" do
25
+ content_tag :div, class: "col-md-12" do
26
+ content_tag :div, class: "panel panel-#{color}" do
27
+ [
28
+ if title
29
+ content_tag :div, class: "panel-heading" do
30
+ content_tag :h3, class: "panel-title" do
31
+ title
32
+ end
33
+ end
34
+ end,
35
+ content_tag(:div, class: "panel-body") do
36
+ block.call
37
+ end,
38
+ if footer
39
+ content_tag :div, class: "panel-footer" do
40
+ footer
41
+ end
42
+ end
43
+ ].join.html_safe
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ def index_body(&block)
50
+ content_tag :div, class: "row" do
51
+ content_tag :div, class: "col-md-12" do
52
+ block.call
53
+ end
54
+ end
55
+ end
56
+
57
+ def index_header(&block)
58
+ content_tag :div, class: "row" do
59
+ block.call
60
+ end
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,264 @@
1
+ module PhantomHelpers
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(("<span class='glyphicon glyphicon-plus glyphicon-white'></span> " + 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 btn-default"}.merge(options)
16
+ link_to text, resource, attributes
17
+ end
18
+
19
+ def primary_button(text, resource, options = {})
20
+ attributes = {:class => "btn btn-primary"}.merge(options)
21
+ link_to text, resource, attributes
22
+ end
23
+
24
+ def link_to_file(text, resource, options = {})
25
+ name = ("<span class='glyphicon glyphicon-file'></span> " + 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 = ("<span class='glyphicon glyphicon-camera'></span> " + t(:'phantom_helpers.picture.change')).html_safe
32
+ attributes = {:class => "btn btn-default span12"}.merge(options)
33
+ link_to name, resource, attributes
34
+ end
35
+
36
+ def link_to_upload(options = {})
37
+ text = ("<span class='glyphicon glyphicon-upload'></span> " + t(:'phantom_helpers.picture.upload')).html_safe
38
+ attributes = {:class => "btn btn-default"}.merge(options)
39
+ button_tag(content_tag('span', text), attributes)
40
+ end
41
+
42
+ def link_to_import(text, resource, options = {})
43
+ name = ('<span class="glyphicon glyphicon-upload"></span> '+ text).html_safe
44
+ attributes = {:class => 'btn btn-default'}.merge(options)
45
+ link_to name, resource, attributes
46
+ end
47
+
48
+ def link_to_export(text, resource, options = {})
49
+ name = ('<span class="glyphicon glyphicon-download"></span> '+ text).html_safe
50
+ attributes = {:class => 'btn btn-default'}.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 = ("<span class='glyphicon glyphicon-plus'></span> " + text).html_safe
57
+ attributes = {
58
+ :remote => true,
59
+ :class => "btn btn-primary"
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 = ("<span class='glyphicon glyphicon-plus'></span> " + 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 => 'glyphicon-repeat')
79
+ attributes = {
80
+ :remote => true,
81
+ :class => "btn btn-xs btn-warning recovery-link"
82
+ }.merge(options)
83
+ link_to name, resource, attributes
84
+ end
85
+
86
+ def link_to_delete(resource, options = {})
87
+ name = ("<span class='glyphicon glyphicon-remove'></span>").html_safe
88
+ attributes = {
89
+ :method => :delete,
90
+ :class => 'btn btn-xs btn-danger delete-link'
91
+ }.merge(options)
92
+ link_to name, resource, attributes
93
+ end
94
+
95
+ def ajax_link_to_delete(resource, options = {})
96
+ name = ("<span class='glyphicon glyphicon-remove'></span>").html_safe
97
+ attributes = {
98
+ :remote => true,
99
+ :method => :delete,
100
+ :data => { :confirm => t(:'phantom_helpers.are_you_sure') },
101
+ :class => 'btn btn-xs btn-danger delete-link'
102
+ }.merge(options)
103
+ link_to name, resource, attributes
104
+ end
105
+
106
+ def link_to_modal_delete(resource, options = {})
107
+ name = ("<span class='glyphicon glyphicon-trash'></span>").html_safe
108
+ attributes = {
109
+ :class => 'btn btn-danger modal-delete-link span12'
110
+ }.merge(options)
111
+ link_to name, resource, attributes
112
+ end
113
+
114
+ def ajax_soft_delete(resource, options = {})
115
+ name = ("<span class='glyphicon glyphicon-remove'></span>").html_safe
116
+ attributes = {
117
+ :remote => true,
118
+ :data => { :confirm => t(:'phantom_helpers.are_you_sure') },
119
+ :class => 'btn btn-xs btn-danger delete-link'
120
+ }.merge(options)
121
+ link_to name, resource, attributes
122
+ end
123
+
124
+
125
+ def primary_checkbox
126
+ ("<span class='glyphicon glyphicon-ok'></span>").html_safe
127
+ end
128
+
129
+ def ajax_link_to_make_primary(resource, options = {})
130
+ attributes = {
131
+ :remote => true,
132
+ :method => :post,
133
+ :data => { :confirm => t(:'phantom_helpers.are_you_sure') },
134
+ }.merge(options)
135
+ link_to primary_checkbox, resource, attributes
136
+ end
137
+
138
+ def ajax_link_to_edit(resource, options = {})
139
+ name = ("<span class='glyphicon glyphicon-pencil'></span>").html_safe
140
+ attributes = {
141
+ :remote => true,
142
+ :class => "btn btn-xs btn-warning edit-link"
143
+ }.merge(options)
144
+ link_to name, resource, attributes
145
+ end
146
+
147
+
148
+ # Edit button with only pencil image - without text
149
+ def link_to_edit(resource, options = {})
150
+ name = ("<span class='glyphicon glyphicon-edit'></span>").html_safe
151
+ attributes = {
152
+ :class => "btn btn-xs btn-inverse edit-link",
153
+ }.merge(options)
154
+ link_to name, resource, attributes
155
+ end
156
+
157
+ # Edit button with text "Edit" and pencil image
158
+ def link_to_edit_with_text(resource, options = {})
159
+ name = ('<span class="glyphicon glyphicon-pencil"></span> '+t(:'phantom_helpers.edit')).html_safe
160
+ attributes = {:class => "span12 btn edit-link"}.merge(options)
161
+ link_to name, resource, attributes
162
+ end
163
+
164
+ def link_to_edit_with_custom_text(text, resource, options = {})
165
+ name = ('<span class="glyphicon glyphicon-pencil"></span> '+ text).html_safe
166
+ attributes = {:class => "span12 btn edit-link"}.merge(options)
167
+ link_to name, resource, attributes
168
+ end
169
+
170
+ def ajax_link_to_show(resource, options = {})
171
+ name = ("<span class='glyphicon glyphicon-eye-open'></span>").html_safe
172
+ attributes = {
173
+ :remote => true,
174
+ :class => "btn btn-xs btn-info show-link"
175
+ }.merge(options)
176
+ link_to name, resource, attributes
177
+ end
178
+
179
+ def link_to_show(resource, options = {})
180
+ name = ("<span class='glyphicon glyphicon-eye-open'></span>").html_safe
181
+ attributes = {
182
+ :class => "btn btn-xs btn-info show-link"
183
+ }.merge(options)
184
+ link_to name, resource, attributes
185
+ end
186
+
187
+ def link_to_cancel(options = {})
188
+ text = ('<span class="glyphicon glyphicon-ban-circle"></span> '+ t(:'phantom_helpers.cancel')).html_safe
189
+ attributes = {
190
+ :class => "col-md-12 btn btn-warning cancel-link",
191
+ :'data-dismiss' => "modal"
192
+ }.merge(options)
193
+ link_to text, '#', attributes
194
+ end
195
+
196
+ def link_to_modal_cancel(options = {})
197
+ name = t(:'phantom_helpers.cancel')
198
+ attributes = {
199
+ :class => "col-md-12 btn btn-warning modal-cancel-link",
200
+ :'data-dismiss' => "modal"
201
+ }.merge(options)
202
+ link_to name, '#', attributes
203
+ end
204
+
205
+ def ajax_link_to_back(resource, options = {})
206
+ name = ('<span class="glyphicon glyphicon-share-alt"></span> ' + t(:'phantom_helpers.back')).html_safe
207
+ attributes = {
208
+ :class => "col-md-6 btn btn-warning back-link back-modal-link",
209
+ :remote => true
210
+ }.merge(options)
211
+
212
+ link_to name, resource, attributes
213
+ end
214
+
215
+ def link_to_back(resource, options = {})
216
+ name = ('<span class="glyphicon glyphicon-share-alt"></span> '+ t(:'phantom_helpers.back')).html_safe
217
+ attributes = {
218
+ :class => 'col-md-6 btn back-link'
219
+ }.merge(options)
220
+ link_to name, resource, attributes
221
+ end
222
+
223
+ def submit_button(text, options={})
224
+ text = ('<span class="glyphicon glyphicon-ok-circle"></span> '+ text).html_safe
225
+ attributes = {
226
+ :type => 'submit',
227
+ :class => 'col-md-12 btn btn-success button'
228
+ }.merge(options)
229
+ button_tag(content_tag('span', text), attributes)
230
+ end
231
+
232
+ def manage_buttons_for(resource, options = {})
233
+ id = extract_id(resource)
234
+ concat link_to_show(resource, :id => "show-#{id}-link") unless except?(:show, options)
235
+ concat link_to_edit [:edit] + [resource].flatten, :id => "edit-#{id}-link", :remote => true unless except?(:edit, options)
236
+ ajax_link_to_delete resource, :id => "delete-#{id}-link" unless except?(:delete, options)
237
+ end
238
+
239
+ private
240
+
241
+ def except?(button_symbol, options)
242
+ [options[:except]].flatten.include?(button_symbol)
243
+ end
244
+
245
+ def extract_id(resource)
246
+ if resource.kind_of?(Array)
247
+ resource_id = String.new
248
+ resource.each_with_index do |r, index|
249
+ resource_id << '-' unless index == 0
250
+ resource_id << proper_id(r)
251
+ end
252
+ resource_id
253
+ else
254
+ proper_id(resource)
255
+ end
256
+ end
257
+
258
+ def proper_id(resource)
259
+ resource.class.to_s.underscore.split('/')[1].dasherize
260
+ end
261
+
262
+ end
263
+ end
264
+ end
@@ -0,0 +1,42 @@
1
+ module PhantomHelpers
2
+ module ViewHelpers
3
+ module ModalHelper
4
+
5
+ def close_button
6
+ content_tag :button, :class => 'close', :'data-dismiss' => 'modal' do
7
+ "&times".html_safe
8
+ end
9
+ end
10
+
11
+ def modal_for(id, &block)
12
+ content_tag :div, class: "modal hide", id: id, wmode: "opaque" do
13
+ block.call
14
+ end
15
+ end
16
+
17
+ def modal_body(&block)
18
+ content_tag :div, class: "modal-body" do
19
+ content_tag :div, class: "row" do
20
+ content_tag :div, class: "col-md-12" do
21
+ content_tag :div, class: "well" do
22
+ block.call
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ def modal_header(text)
30
+ content_tag :div, class: "modal-header" do
31
+ concat close_button
32
+ concat content_tag(:h3) { text }
33
+ end
34
+ end
35
+
36
+ def modal_form_error(id)
37
+ content_tag :div, nil, :id => id
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,67 @@
1
+ module PhantomHelpers
2
+ module ViewHelpers
3
+ module TableHelper
4
+
5
+ def table_for(id, &block)
6
+ content_tag :div, class: "row" do
7
+ content_tag :div, class: "col-md-12" do
8
+ content_tag :table, class: "table table-striped table-bordered table-condensed", id: id do
9
+ block.call
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ def table(&block)
16
+ content_tag :table, class: "table table-striped table-bordered table-condensed" do
17
+ block.call
18
+ end
19
+ end
20
+
21
+ def show_table_for(id, &block)
22
+ content_tag :div, class: "row" do
23
+ content_tag :div, class: "col-md-12" do
24
+ content_tag :table, class: "table", id: id do
25
+ block.call
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ def show_table(&block)
32
+ content_tag :table, class: "table table-hover table-condensed" do
33
+ block.call
34
+ end
35
+ end
36
+
37
+ def sortable_table_for(id, &block)
38
+ content_tag :table, class: "table table-striped table-bordered table-condensed", id: id do
39
+ block.call
40
+ end
41
+ end
42
+
43
+ def th(text)
44
+ content_tag(:th, class: "btn-inverse") { text }
45
+ end
46
+
47
+ def th_icon(icon)
48
+ content_tag :th, class: "btn-inverse", style: "width:24px;" do
49
+ content_tag :span, nil, class: "glyphicon glyphicon-#{icon}"
50
+ end
51
+ end
52
+
53
+ def th_actions(num)
54
+ size = case num
55
+ when 1 then 35
56
+ when 2 then 77
57
+ when 3 then 93
58
+ else num
59
+ end
60
+ content_tag :th, class: "btn-inverse", style:"width:#{size}px" do
61
+ content_tag :span, nil, class: "glyphicon glyphicon-edit"
62
+ end
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,13 @@
1
+ require 'phantom_helpers/view_helpers/link_helper'
2
+ require 'phantom_helpers/view_helpers/modal_helper'
3
+ require 'phantom_helpers/view_helpers/table_helper'
4
+ require 'phantom_helpers/view_helpers/html_helper'
5
+
6
+ module PhantomHelpers
7
+ module ViewHelpers
8
+ ActionView::Base.send :include, LinkHelper
9
+ ActionView::Base.send :include, ModalHelper
10
+ ActionView::Base.send :include, TableHelper
11
+ ActionView::Base.send :include, HtmlHelper
12
+ end
13
+ end
@@ -0,0 +1 @@
1
+ require 'phantom_helpers/railtie' if defined?(Rails::Railtie)
data/locales/en.yml ADDED
@@ -0,0 +1,10 @@
1
+ en:
2
+ phantom_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
+
data/locales/ja.yml ADDED
@@ -0,0 +1,10 @@
1
+ ja:
2
+ phantom_helpers:
3
+ cancel: "キャンセル"
4
+ back: "戻る"
5
+ picture:
6
+ change: "画像を変更"
7
+ upload: "画像をアップロード"
8
+ are_you_sure: "これで宜しいですか?"
9
+ edit: "編集"
10
+
@@ -0,0 +1,20 @@
1
+ # encoding: UTF-8
2
+ Gem::Specification.new do |s|
3
+ s.platform = Gem::Platform::RUBY
4
+ s.name = 'phantom_helpers'
5
+ s.version = '0.0.6'
6
+ s.summary = 'Phantom View Helpers'
7
+ s.description = 'rails helpers for bootstrap 3'
8
+ s.licenses = ['GNU GPL-3', 'AGPL-3']
9
+ s.required_ruby_version = '>= 1.8.7'
10
+
11
+ s.author = ['Vassil Kalkov', 'Rei Kagetsuki', 'Nakaya Yukiharu']
12
+ s.email = 'info@genshin.org'
13
+ s.homepage = 'http://github.com/Genshin/phantom_helpers'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
17
+
18
+ s.require_path = 'lib'
19
+ s.requirements << 'none'
20
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phantom_helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Vassil Kalkov
8
+ - Rei Kagetsuki
9
+ - Nakaya Yukiharu
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-09-23 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: rails helpers for bootstrap 3
16
+ email: info@genshin.org
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - LICENSE.md
23
+ - README.md
24
+ - lib/phantom_helpers.rb
25
+ - lib/phantom_helpers/railtie.rb
26
+ - lib/phantom_helpers/view_helpers.rb
27
+ - lib/phantom_helpers/view_helpers/html_helper.rb
28
+ - lib/phantom_helpers/view_helpers/link_helper.rb
29
+ - lib/phantom_helpers/view_helpers/modal_helper.rb
30
+ - lib/phantom_helpers/view_helpers/table_helper.rb
31
+ - locales/en.yml
32
+ - locales/ja.yml
33
+ - phantom_helpers.gemspec
34
+ homepage: http://github.com/Genshin/phantom_helpers
35
+ licenses:
36
+ - GNU GPL-3
37
+ - AGPL-3
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.8.7
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements:
54
+ - none
55
+ rubyforge_project:
56
+ rubygems_version: 2.0.3
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Phantom View Helpers
60
+ test_files: []