viewaide 0.3.2 → 0.4.0
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/viewaide/helpers.rb +0 -2
- data/lib/viewaide/helpers/message_helper.rb +1 -1
- data/lib/viewaide/helpers/table_helper.rb +4 -36
- data/test/message_helper_test.rb +1 -1
- data/test/table_helper_test.rb +0 -46
- data/viewaide.gemspec +2 -5
- metadata +2 -5
- data/lib/viewaide/helpers/navigation_helper.rb +0 -46
- data/test/navigation_helper_test.rb +0 -130
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/viewaide/helpers.rb
CHANGED
@@ -7,7 +7,6 @@ require "viewaide/helpers/grid_helper"
|
|
7
7
|
require "viewaide/helpers/message_helper"
|
8
8
|
require "viewaide/helpers/rjs_helper"
|
9
9
|
require "viewaide/helpers/jquery_helper"
|
10
|
-
require "viewaide/helpers/navigation_helper"
|
11
10
|
|
12
11
|
module Viewaide
|
13
12
|
module Helpers
|
@@ -20,7 +19,6 @@ module Viewaide
|
|
20
19
|
include MessageHelper
|
21
20
|
include RjsHelper
|
22
21
|
include JqueryHelper
|
23
|
-
include NavigationHelper
|
24
22
|
|
25
23
|
protected
|
26
24
|
|
@@ -30,22 +30,16 @@ module Viewaide
|
|
30
30
|
concat(html)
|
31
31
|
end
|
32
32
|
|
33
|
-
# Generates a <table>
|
33
|
+
# Generates a <table>
|
34
34
|
# @param [*Args]
|
35
35
|
# @return [String]
|
36
36
|
# @example
|
37
|
-
# <% recordset
|
37
|
+
# <% recordset do %>
|
38
38
|
# <tbody>
|
39
39
|
# </tbody>
|
40
40
|
# <% end %>
|
41
41
|
# generates
|
42
42
|
# <table class="recordset" cellspacing="0">
|
43
|
-
# <thead>
|
44
|
-
# <tr>
|
45
|
-
# <th class="first">First Column</th>
|
46
|
-
# <th class="last">Second Column</th>
|
47
|
-
# </tr>
|
48
|
-
# </thead>
|
49
43
|
# <tbody>
|
50
44
|
# </tbody>
|
51
45
|
# </table>
|
@@ -53,39 +47,13 @@ module Viewaide
|
|
53
47
|
options = args.extract_options!
|
54
48
|
options[:table] ||= {}
|
55
49
|
|
56
|
-
headers = []
|
57
|
-
(options[:headers] || []).each_with_index do |header, index|
|
58
|
-
head = [header].flatten
|
59
|
-
opts = head.extract_options!
|
60
|
-
|
61
|
-
css_classes = [] << opts.delete(:class) << case index
|
62
|
-
when 0 then "first"
|
63
|
-
when (options[:headers].size - 1) then "last"
|
64
|
-
end
|
65
|
-
|
66
|
-
headers << if head.first =~ /^\<th/
|
67
|
-
th = Hpricot(head.first)
|
68
|
-
th_classes = th.at("th")["class"].join
|
69
|
-
th_classes = clean_css_classes([th_classes, css_classes])
|
70
|
-
th.at("th")["class"] = th_classes
|
71
|
-
th.to_html
|
72
|
-
else
|
73
|
-
content_tag :th,
|
74
|
-
head.first,
|
75
|
-
opts.merge(:class => clean_css_classes(css_classes))
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
50
|
table_classes = ["recordset", args] << options[:table].delete(:class)
|
80
51
|
css_classes = clean_css_classes(table_classes, {"last" => last_column})
|
81
52
|
|
82
|
-
html =
|
53
|
+
html = clean_column(css_classes) do
|
83
54
|
table_options = options[:table]
|
84
55
|
table_options.merge!(:class => css_classes, :cellspacing => 0)
|
85
|
-
content_tag(:table,
|
86
|
-
content_tag(:thead, content_tag(:tr, headers.join)) + \
|
87
|
-
capture(&block),
|
88
|
-
table_options)
|
56
|
+
content_tag(:table, capture(&block), table_options)
|
89
57
|
end
|
90
58
|
|
91
59
|
reset_cycle
|
data/test/message_helper_test.rb
CHANGED
@@ -6,7 +6,7 @@ class MessageHelperTest < Viewaide::ViewTestCase
|
|
6
6
|
|
7
7
|
should "default with the correct structure" do
|
8
8
|
show_view %(<%= messages(:structure => "Flash message") %>) do
|
9
|
-
assert_select "p.structure.
|
9
|
+
assert_select "p.structure.single-line", "Flash message"
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
data/test/table_helper_test.rb
CHANGED
@@ -41,58 +41,12 @@ class TableHelperTest < Viewaide::ViewTestCase
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
should "allow headers be set" do
|
45
|
-
show_view %(<% recordset :headers => ["Header 1", "Header 2", "Header 3"] do %><tbody>rows</tbody><% end %>) do
|
46
|
-
assert_select "table.recordset[cellspacing=0]" do
|
47
|
-
assert_select "thead" do
|
48
|
-
assert_select "tr" do
|
49
|
-
assert_select "th.first", "Header 1"
|
50
|
-
assert_select "th", "Header 2"
|
51
|
-
assert_select "th.last", "Header 3"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
assert_select "tbody", "rows"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
should "allow headers to have attributes set" do
|
60
|
-
show_view %(
|
61
|
-
<% recordset :headers => [["Header 1", {:class => "mine", :id => "over"}]] do %>
|
62
|
-
<tbody>rows</tbody>
|
63
|
-
<% end %>
|
64
|
-
) do
|
65
|
-
assert_select "table.recordset[cellspacing=0]" do
|
66
|
-
assert_select "thead" do
|
67
|
-
assert_select "tr" do
|
68
|
-
assert_select "th#over.first.mine", "Header 1"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
assert_select "tbody", "rows"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
44
|
should "allow classes be assigned in a comma-delimited manner" do
|
77
45
|
show_view %(<% recordset "my-recordset", "car-list" do %><% end %>) do
|
78
46
|
assert_select "table.recordset.my-recordset.car-list[cellspacing=0]"
|
79
47
|
end
|
80
48
|
end
|
81
49
|
|
82
|
-
should "allow additional attributes be set on the recordset" do
|
83
|
-
show_view %(<% recordset :headers => %w(One Two Three), :table => {:id => "my-id", :class => "my-recordset"} do %><% end %>) do
|
84
|
-
assert_select "table#my-id.recordset.my-recordset[cellspacing=0]" do
|
85
|
-
assert_select "thead" do
|
86
|
-
assert_select "tr" do
|
87
|
-
assert_select "th", "One"
|
88
|
-
assert_select "th", "Two"
|
89
|
-
assert_select "th", "Three"
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
50
|
should "reset cycles for zebra_rows" do
|
97
51
|
show_view %(
|
98
52
|
<% recordset do %>
|
data/viewaide.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{viewaide}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Joshua Clayton"]
|
12
|
-
s.date = %q{2010-01-
|
12
|
+
s.date = %q{2010-01-31}
|
13
13
|
s.description = %q{Making your views easier}
|
14
14
|
s.email = %q{joshua.clayton@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -30,7 +30,6 @@ Gem::Specification.new do |s|
|
|
30
30
|
"lib/viewaide/helpers/jquery_helper.rb",
|
31
31
|
"lib/viewaide/helpers/link_helper.rb",
|
32
32
|
"lib/viewaide/helpers/message_helper.rb",
|
33
|
-
"lib/viewaide/helpers/navigation_helper.rb",
|
34
33
|
"lib/viewaide/helpers/rjs_helper.rb",
|
35
34
|
"lib/viewaide/helpers/structure_helper.rb",
|
36
35
|
"lib/viewaide/helpers/table_helper.rb",
|
@@ -43,7 +42,6 @@ Gem::Specification.new do |s|
|
|
43
42
|
"test/jquery_helper_test.rb",
|
44
43
|
"test/link_helper_test.rb",
|
45
44
|
"test/message_helper_test.rb",
|
46
|
-
"test/navigation_helper_test.rb",
|
47
45
|
"test/rjs_helper_test.rb",
|
48
46
|
"test/structure_helper_test.rb",
|
49
47
|
"test/table_helper_test.rb",
|
@@ -62,7 +60,6 @@ Gem::Specification.new do |s|
|
|
62
60
|
"test/jquery_helper_test.rb",
|
63
61
|
"test/link_helper_test.rb",
|
64
62
|
"test/message_helper_test.rb",
|
65
|
-
"test/navigation_helper_test.rb",
|
66
63
|
"test/rjs_helper_test.rb",
|
67
64
|
"test/structure_helper_test.rb",
|
68
65
|
"test/table_helper_test.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: viewaide
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Clayton
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-31 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -65,7 +65,6 @@ files:
|
|
65
65
|
- lib/viewaide/helpers/jquery_helper.rb
|
66
66
|
- lib/viewaide/helpers/link_helper.rb
|
67
67
|
- lib/viewaide/helpers/message_helper.rb
|
68
|
-
- lib/viewaide/helpers/navigation_helper.rb
|
69
68
|
- lib/viewaide/helpers/rjs_helper.rb
|
70
69
|
- lib/viewaide/helpers/structure_helper.rb
|
71
70
|
- lib/viewaide/helpers/table_helper.rb
|
@@ -78,7 +77,6 @@ files:
|
|
78
77
|
- test/jquery_helper_test.rb
|
79
78
|
- test/link_helper_test.rb
|
80
79
|
- test/message_helper_test.rb
|
81
|
-
- test/navigation_helper_test.rb
|
82
80
|
- test/rjs_helper_test.rb
|
83
81
|
- test/structure_helper_test.rb
|
84
82
|
- test/table_helper_test.rb
|
@@ -119,7 +117,6 @@ test_files:
|
|
119
117
|
- test/jquery_helper_test.rb
|
120
118
|
- test/link_helper_test.rb
|
121
119
|
- test/message_helper_test.rb
|
122
|
-
- test/navigation_helper_test.rb
|
123
120
|
- test/rjs_helper_test.rb
|
124
121
|
- test/structure_helper_test.rb
|
125
122
|
- test/table_helper_test.rb
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module Viewaide
|
2
|
-
module Helpers
|
3
|
-
module NavigationHelper
|
4
|
-
# Generates a <li> and <a> for site navigation
|
5
|
-
# @param [String] name the anchor text
|
6
|
-
# @param [String] path the URL of the anchor
|
7
|
-
# @param [Hash] options options hash for #link_to
|
8
|
-
# @param [Hash] li_options options hash for #content_tag
|
9
|
-
# @example
|
10
|
-
# <%= tab "Home", root_path %>
|
11
|
-
# generates
|
12
|
-
# <li><a href="/">Home</a></li>
|
13
|
-
#
|
14
|
-
# <%= tab "Home", root_path, :compare => (controller.action_name == "show") %>
|
15
|
-
# generates
|
16
|
-
# <li class="active"><a href="/">Home</a></li>
|
17
|
-
#
|
18
|
-
# <%= tab "Home", root_path, {:class => "a"}, {:class => "li"} %>
|
19
|
-
# generates
|
20
|
-
# <li class="li"><a href="/" class="a">Home</a></li>
|
21
|
-
def tab(name, path, options = {}, li_options = {})
|
22
|
-
opts = parse_tab_options(name, li_options)
|
23
|
-
|
24
|
-
active = "active" if (opts[:active] == opts[:comparison]) || opts[:compare]
|
25
|
-
css_classes = [] << opts[:li_classes] << active
|
26
|
-
css_classes = clean_css_classes(css_classes)
|
27
|
-
li_options.merge!(:class => css_classes) if css_classes.present?
|
28
|
-
|
29
|
-
content_tag :li,
|
30
|
-
link_to(name, path, options),
|
31
|
-
li_options
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def parse_tab_options(name, li_options = {})
|
37
|
-
returning({}) do |result|
|
38
|
-
result[:active] = li_options.delete(:active) || (name.gsub(/\s/, '').tableize || "")
|
39
|
-
result[:comparison] = li_options.delete(:active_compare) || controller.controller_name
|
40
|
-
result[:compare] = li_options.delete(:compare) || false
|
41
|
-
result[:li_classes] = li_options.delete(:class)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,130 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class NavigationHelperTest < ActiveSupport::TestCase
|
4
|
-
include Viewaide::Helpers::NavigationHelper
|
5
|
-
|
6
|
-
context "tab" do
|
7
|
-
should "parse tab options properly" do
|
8
|
-
expects(:parse_tab_options).with("test", {:b => 2}).returns({})
|
9
|
-
stubs(:link_to)
|
10
|
-
stubs(:content_tag)
|
11
|
-
stubs(:clean_css_classes)
|
12
|
-
tab("test", "/", {:a => 1}, {:b => 2})
|
13
|
-
end
|
14
|
-
|
15
|
-
should "call link_to properly" do
|
16
|
-
stubs(:content_tag)
|
17
|
-
stubs(:clean_css_classes)
|
18
|
-
stubs(:parse_tab_options).returns({})
|
19
|
-
expects(:link_to).with("test", "/path", {:a => 1, :b => 2})
|
20
|
-
tab("test", "/path", {:a => 1, :b => 2})
|
21
|
-
end
|
22
|
-
|
23
|
-
context "compiling li classes" do
|
24
|
-
setup do
|
25
|
-
@result_options = { :active => "1",
|
26
|
-
:comparison => "2",
|
27
|
-
:compare => false,
|
28
|
-
:li_classes => "one two three" }
|
29
|
-
stubs(:link_to).returns("link_to")
|
30
|
-
stubs(:content_tag)
|
31
|
-
end
|
32
|
-
|
33
|
-
should "properly use classes passed in the options" do
|
34
|
-
stubs(:parse_tab_options).returns(@result_options)
|
35
|
-
expects(:clean_css_classes).with(["one two three", nil])
|
36
|
-
tab("test", "/")
|
37
|
-
end
|
38
|
-
|
39
|
-
should "properly compare information" do
|
40
|
-
@result_options[:comparison] = "1"
|
41
|
-
stubs(:parse_tab_options).returns(@result_options)
|
42
|
-
expects(:clean_css_classes).with(["one two three", "active"])
|
43
|
-
tab("test", "/")
|
44
|
-
end
|
45
|
-
|
46
|
-
should "properly use compare value" do
|
47
|
-
@result_options[:compare] = true
|
48
|
-
stubs(:parse_tab_options).returns(@result_options)
|
49
|
-
expects(:clean_css_classes).with(["one two three", "active"])
|
50
|
-
tab("test", "/")
|
51
|
-
end
|
52
|
-
|
53
|
-
should "not assign class if css_classes is blank" do
|
54
|
-
@result_options[:li_classes] = nil
|
55
|
-
stubs(:parse_tab_options).returns({})
|
56
|
-
stubs(:clean_css_classes).returns("")
|
57
|
-
expects(:content_tag).with(:li, "link_to", {})
|
58
|
-
tab("test", "/")
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context "parse_tab_options" do
|
63
|
-
context "calculating :active" do
|
64
|
-
setup do
|
65
|
-
stubs(:controller).returns(stub_everything)
|
66
|
-
end
|
67
|
-
|
68
|
-
should "be based on option" do
|
69
|
-
result = send(:parse_tab_options, "name", {:active => "words"})
|
70
|
-
assert_equal "words", result[:active]
|
71
|
-
end
|
72
|
-
|
73
|
-
should "be based on name" do
|
74
|
-
name = tableized_name = stub
|
75
|
-
name.expects(:gsub).with(/\s/, '').returns(tableized_name)
|
76
|
-
tableized_name.expects(:tableize).returns("name")
|
77
|
-
|
78
|
-
result = send(:parse_tab_options, name, {})
|
79
|
-
assert_equal "name", result[:active]
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context "calculating :comparison" do
|
84
|
-
should "be based on option" do
|
85
|
-
result = send(:parse_tab_options, "name", {:active_compare => "active"})
|
86
|
-
assert_equal "active", result[:comparison]
|
87
|
-
end
|
88
|
-
|
89
|
-
should "be based on controller name" do
|
90
|
-
controller = stub(:controller_name => "controller-name")
|
91
|
-
expects(:controller).returns(controller)
|
92
|
-
result = send(:parse_tab_options, "name", {})
|
93
|
-
assert_equal "controller-name", result[:comparison]
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context "calculating :compare" do
|
98
|
-
setup do
|
99
|
-
stubs(:controller).returns(stub_everything)
|
100
|
-
end
|
101
|
-
|
102
|
-
should "be based on option" do
|
103
|
-
result = send(:parse_tab_options, "name", {:compare => true})
|
104
|
-
assert_equal true, result[:compare]
|
105
|
-
end
|
106
|
-
|
107
|
-
should "have a default value" do
|
108
|
-
result = send(:parse_tab_options, "name")
|
109
|
-
assert_equal false, result[:compare]
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context "calculating :li_classes" do
|
114
|
-
setup do
|
115
|
-
stubs(:controller).returns(stub_everything)
|
116
|
-
end
|
117
|
-
|
118
|
-
should "be based on option" do
|
119
|
-
result = send(:parse_tab_options, "name", {:class => "custom classes"})
|
120
|
-
assert_equal "custom classes", result[:li_classes]
|
121
|
-
end
|
122
|
-
|
123
|
-
should "be nil if no option is passed" do
|
124
|
-
result = send(:parse_tab_options, "name")
|
125
|
-
assert_nil result[:li_classes]
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|