gaku_helpers 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/gaku_helpers.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |s|
3
3
  s.platform = Gem::Platform::RUBY
4
4
  s.name = 'gaku_helpers'
5
- s.version = '0.0.3'
5
+ s.version = '0.0.4'
6
6
  s.summary = 'Gaku View Helpers'
7
7
  s.description = ''
8
8
  s.required_ruby_version = '>= 1.8.7'
@@ -0,0 +1,37 @@
1
+ module GakuHelpers
2
+ module ViewHelpers
3
+ module HtmlHelper
4
+
5
+ def hr
6
+ content_tag :div, class: "row-fluid" do
7
+ content_tag :div, class: "span12" do
8
+ content_tag :hr
9
+ end
10
+ end
11
+ end
12
+
13
+ def well_div(&block)
14
+ content_tag :div, class: "row-fluid" do
15
+ content_tag :div, class: "span12 well" do
16
+ block.call
17
+ end
18
+ end
19
+ end
20
+
21
+ def index_body(&block)
22
+ content_tag :div, class: "row-fluid" do
23
+ content_tag :div, class: "span12" do
24
+ block.call
25
+ end
26
+ end
27
+ end
28
+
29
+ def index_header(&block)
30
+ content_tag :div, class: "row-fluid" do
31
+ block.call
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -219,6 +219,36 @@ module GakuHelpers
219
219
  button_tag(content_tag('span', text), attributes)
220
220
  end
221
221
 
222
+ def manage_buttons_for(resource, options = {})
223
+ id = extract_id(resource)
224
+ concat link_to_show(resource, :id => "show-#{id}-link") unless except?(:show, options)
225
+ concat link_to_edit [:edit] + [resource].flatten, :id => "edit-#{id}-link", :remote => true unless except?(:edit, options)
226
+ ajax_link_to_delete resource, :id => "delete-#{id}-link" unless except?(:delete, options)
227
+ end
228
+
229
+ private
230
+
231
+ def except?(button_symbol, options)
232
+ [options[:except]].flatten.include?(button_symbol)
233
+ end
234
+
235
+ def extract_id(resource)
236
+ if resource.kind_of?(Array)
237
+ resource_id = String.new
238
+ resource.each_with_index do |r, index|
239
+ resource_id << '-' unless index == 0
240
+ resource_id << proper_id(r)
241
+ end
242
+ resource_id
243
+ else
244
+ proper_id(resource)
245
+ end
246
+ end
247
+
248
+ def proper_id(resource)
249
+ resource.class.to_s.underscore.split('/')[1].dasherize
250
+ end
251
+
222
252
  end
223
253
  end
224
254
  end
@@ -0,0 +1,63 @@
1
+ module GakuHelpers
2
+ module ViewHelpers
3
+ module TableHelper
4
+
5
+ def table_for(id, &block)
6
+ content_tag :div, class: "row-fluid" do
7
+ content_tag :table, class: "table table-striped table-bordered table-condensed", id: id do
8
+ block.call
9
+ end
10
+ end
11
+ end
12
+
13
+ def table(&block)
14
+ content_tag :table, class: "table table-striped table-bordered table-condensed" do
15
+ block.call
16
+ end
17
+ end
18
+
19
+ def show_table_for(id, &block)
20
+ content_tag :div, class: "row-fluid" do
21
+ content_tag :table, class: "table table-hover table-condensed", id: id do
22
+ block.call
23
+ end
24
+ end
25
+ end
26
+
27
+ def show_table(&block)
28
+ content_tag :table, class: "table table-hover table-condensed" do
29
+ block.call
30
+ end
31
+ end
32
+
33
+ def sortable_table_for(id, &block)
34
+ content_tag :table, class: "table table-striped table-bordered table-condensed tablesorter", id: id do
35
+ block.call
36
+ end
37
+ end
38
+
39
+ def th(text)
40
+ content_tag(:th, class: "btn-inverse") { text }
41
+ end
42
+
43
+ def th_icon(icon)
44
+ content_tag :th, class: "btn-inverse", style: "width:24px;" do
45
+ content_tag :i, nil, class: "icon-#{icon} icon-white"
46
+ end
47
+ end
48
+
49
+ def th_actions(num)
50
+ size = case num
51
+ when 1 then 40
52
+ when 2 then 62
53
+ when 3 then 99
54
+ else num
55
+ end
56
+ content_tag :th, class: "btn-inverse", style:"width:#{size}px" do
57
+ content_tag :i, nil, class: "icon-edit icon-white"
58
+ end
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -1,9 +1,13 @@
1
1
  require 'gaku_helpers/view_helpers/link_helper'
2
2
  require 'gaku_helpers/view_helpers/modal_helper'
3
+ require 'gaku_helpers/view_helpers/table_helper'
4
+ require 'gaku_helpers/view_helpers/html_helper'
3
5
 
4
6
  module GakuHelpers
5
7
  module ViewHelpers
6
8
  ActionView::Base.send :include, LinkHelper
7
9
  ActionView::Base.send :include, ModalHelper
10
+ ActionView::Base.send :include, TableHelper
11
+ ActionView::Base.send :include, HtmlHelper
8
12
  end
9
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gaku_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -23,8 +23,10 @@ files:
23
23
  - lib/gaku_helpers.rb
24
24
  - lib/gaku_helpers/railtie.rb
25
25
  - lib/gaku_helpers/view_helpers.rb
26
+ - lib/gaku_helpers/view_helpers/html_helper.rb
26
27
  - lib/gaku_helpers/view_helpers/link_helper.rb
27
28
  - lib/gaku_helpers/view_helpers/modal_helper.rb
29
+ - lib/gaku_helpers/view_helpers/table_helper.rb
28
30
  - locales/en.yml
29
31
  homepage: http://kalkov.github.io
30
32
  licenses: []