viewaide 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ begin
11
11
  gemspec.email = "joshua.clayton@gmail.com"
12
12
  gemspec.homepage = "http://github.com/joshuaclayton/viewaide"
13
13
  gemspec.authors = ["Joshua Clayton"]
14
- gemspec.add_dependency("actionview", ">= 2.1.0")
14
+ gemspec.add_dependency("actionpack", ">= 2.1.0")
15
15
  gemspec.add_dependency("activesupport", ">= 2.1.0")
16
16
  gemspec.add_dependency("hpricot", ">= 0.8.1")
17
17
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -1,11 +1,22 @@
1
1
  module Viewaide
2
2
  module Helpers
3
3
  module DateHelper
4
-
4
+ # Converts a date or time object to a formatted time
5
+ #
6
+ # @param [Date, Time, or DateTime] dt the date to convert
7
+ # @param [String] default_text default text if the date is nil
8
+ # @param [Symbol] format_string the time format
9
+ # @return [String]
5
10
  def datetime(dt = nil, default_text = "", format_string = :long)
6
11
  dt ? dt.to_time.to_s(format_string) : default_text
7
12
  end
8
13
 
14
+ # Converts a date or time object to a formatted date
15
+ #
16
+ # @param [Date, Time, or DateTime] dt the date to convert
17
+ # @param [String] default_text default text if the date is nil
18
+ # @param [Symbol] format_string the date format
19
+ # @return [String]
9
20
  def date(dt = nil, default_text = "", format_string = :long)
10
21
  dt ? dt.to_date.to_s(format_string) : default_text
11
22
  end
@@ -2,6 +2,38 @@ module Viewaide
2
2
  module Helpers
3
3
  module FormHelper
4
4
 
5
+ # Generates a submit button for forms
6
+ #
7
+ # @param [String] value the text for the button
8
+ # @param [*Args]
9
+ # @return [String]
10
+ # @example
11
+ # <%= submit_button "Create" %>
12
+ # generates
13
+ # <button class="btn" type="submit" value="Create">
14
+ # <span>Create</span>
15
+ # </button>
16
+ #
17
+ # @example
18
+ # <%= submit_button "Create", :class1, :class2, "another-class" %>
19
+ # generates
20
+ # <button class="btn class1 class2 another-class" type="submit" value="Create">
21
+ # <span>Create</span>
22
+ # </button>
23
+ #
24
+ # @example
25
+ # <%= submit_button "Create", :class1, :id => "custom", :type => "image" %>
26
+ # generates
27
+ # <button class="btn class1" type="image" id="custom" value="Create">
28
+ # <span>Create</span>
29
+ # </button>
30
+ #
31
+ # @example
32
+ # <%= submit_button "Create", :class1, :value => "override" %>
33
+ # generates
34
+ # <button class="btn class1" type="submit" value="override">
35
+ # <span>Create</span>
36
+ # </button>
5
37
  def submit_button(value, *args)
6
38
  options = args.extract_options!
7
39
  css_classes = ["btn"] << options.delete(:class) << args
@@ -15,6 +47,29 @@ module Viewaide
15
47
  }.merge(options)
16
48
  end
17
49
 
50
+ # Generates a wrapper set for form inputs and labels
51
+ #
52
+ # @param [*Args]
53
+ # @return [String]
54
+ # @example
55
+ # <% set do %>words<% end %>
56
+ # generates
57
+ # <div class="text">words</div>
58
+ #
59
+ # @example
60
+ # <% set :checkbox do %>words<% end %>
61
+ # generates
62
+ # <div class="checkbox">words</div>
63
+ #
64
+ # @example
65
+ # <% set :id => "custom-id" do %>words<% end %>
66
+ # generates
67
+ # <div class="text" id="custom-id">words</div>
68
+ #
69
+ # @example
70
+ # <% set :half do %>words<% end %>
71
+ # generates
72
+ # <div class="text span-12">words</div>
18
73
  def set(*args, &block)
19
74
  options = args.extract_options!
20
75
  css_classes = [] << options.delete(:class) << args
@@ -38,6 +93,48 @@ module Viewaide
38
93
  concat(html)
39
94
  end
40
95
 
96
+ # Generates a fieldset with legend
97
+ #
98
+ # @param [*Args]
99
+ # @return [String]
100
+ # @example
101
+ # <% fieldset do %>words<% end %>
102
+ # generates
103
+ # <fieldset>words</fieldset>
104
+ #
105
+ # @example
106
+ # <% fieldset "User Information" do %>words<% end %>
107
+ # generates
108
+ # <fieldset>
109
+ # <h3 class="legend">User Information</h3>
110
+ # </fieldset>
111
+ #
112
+ # @example
113
+ # <% fieldset "User Information", :hform do %>words<% end %>
114
+ # generates
115
+ # <fieldset class="hform">
116
+ # <h3 class="legend">User Information</h3>
117
+ # </fieldset>
118
+ #
119
+ # @example
120
+ # <% fieldset "User Information", :hform, :legend => {:class => "lgnd", :id => "legend-id"} do %>
121
+ # words
122
+ # <% end %>
123
+ # generates
124
+ # <fieldset class="hform">
125
+ # <h3 class="legend lgnd" id="legend-id">User Information</h3>
126
+ # words
127
+ # </fieldset>
128
+ #
129
+ # @example
130
+ # <% fieldset "User Information", :hform, :id => "user-info" do %>
131
+ # words
132
+ # <% end %>
133
+ # generates
134
+ # <fieldset class="hform" id="user-info">
135
+ # <h3 class="legend">User Information</h3>
136
+ # words
137
+ # </fieldset>
41
138
  def fieldset(*args, &block)
42
139
  options = args.extract_options!
43
140
  css_classes = [] << options.delete(:class) << args
@@ -30,11 +30,13 @@ module Viewaide
30
30
  }.freeze
31
31
  MULTIPLE_FRACTIONS = MULTIPLES.keys.map {|key| key.to_s }.freeze
32
32
 
33
+ # force use of Easel-style classes
33
34
  def self.easel_grid!
34
35
  @@last_column = "col-last"
35
36
  @@column_prefix = "col"
36
37
  end
37
38
 
39
+ # force use of Blueprint-style classes (the default)
38
40
  def self.blueprint_grid!
39
41
  @@last_column = "last"
40
42
  @@column_prefix = "span"
@@ -42,15 +44,56 @@ module Viewaide
42
44
 
43
45
  blueprint_grid!
44
46
 
47
+ # @return [String] last column (based on Blueprint or Easel grid formats)
45
48
  def last_column
46
49
  @@last_column
47
50
  end
48
51
 
52
+ # Returns a div with the correct width-calculated class
53
+ # @param [*Args]
54
+ # @return [String]
55
+ # @example
56
+ # <% column do %>Full column<% end %>
57
+ # generates
58
+ # <div class="span-24">Full column</div>
59
+ #
60
+ # @example
61
+ # <% column do %>
62
+ # <% column :half do %>column<% end %>
63
+ # <% end %>
64
+ # generates
65
+ # <div class="span-24">
66
+ # <div class="span-12">column</div>
67
+ # </div>
68
+ #
69
+ # @example
70
+ # <% column :one_third do %>one third<% end %>
71
+ # <% column :two_thirds, :last do %>two thirds<% end %>
72
+ # generates
73
+ # <div class="span-8">one third</div>
74
+ # <div class="span-16 last">two thirds</div>
75
+ #
76
+ # @example
77
+ # <% column :one_third, :custom, :id => "column" do %>words<% end %>
78
+ # generates
79
+ # <div class="span-8 custom" id="column">words</div>
49
80
  def column(*args, &block)
50
81
  @_viewaide_column_count ||= application_width
51
82
  col(*args, &block)
52
83
  end
53
84
 
85
+ # Wraps content in a container
86
+ # @param [Symbol] size size of the container
87
+ # @return [String]
88
+ # @example
89
+ # <% container do %>content<% end %>
90
+ # generates
91
+ # <div class="container">content<% end %>
92
+ #
93
+ # @example
94
+ # <% container :half do %>content<% end %>
95
+ # generates
96
+ # <div class="container span-12">content<% end %>
54
97
  def container(size=nil, *args, &block)
55
98
  opts = args.extract_options!
56
99
  opts.merge!(:suppress_col => true) if size.nil?
@@ -1,7 +1,28 @@
1
1
  module Viewaide
2
2
  module Helpers
3
3
  module JqueryHelper
4
-
4
+ # generates a script tag with the appropriate type,
5
+ # an anonymous function (assigning jQuery to $),
6
+ # and within a #ready callback
7
+ #
8
+ # @param [block] &block the block of text to wrap
9
+ # @return [String]
10
+ # @example
11
+ # <% document_ready do %>
12
+ # $("a[rel=external]").live(function() {
13
+ # $(this).attr({target: "_blank"});
14
+ # });
15
+ # <% end %>
16
+ # generates
17
+ # <script type="text/javascript">
18
+ # (function($) {
19
+ # $(document).ready(function() {
20
+ # $("a[rel=external]").live(function() {
21
+ # $(this).attr({target: "_blank"});
22
+ # });
23
+ # });
24
+ # })(jQuery);
25
+ # </script>
5
26
  def document_ready(&block)
6
27
  html = content_tag :script, :type => "text/javascript" do
7
28
  %(
@@ -2,6 +2,21 @@ module Viewaide
2
2
  module Helpers
3
3
  module LinkHelper
4
4
 
5
+ # Generates a link that's able to be styled like a button.
6
+ # This functions exactly like Rails' #link_to but wraps the link text
7
+ # in a span and assigns a class of "btn"
8
+ #
9
+ # @param [*Args]
10
+ # @return [String]
11
+ # @example
12
+ # <%= link_button "Text", root_path %>
13
+ # generates
14
+ # <a href="/" class="btn"><span>Text</span></a>
15
+ #
16
+ # @example
17
+ # <%= link_button "Text", root_path, :class => "extra" %>
18
+ # generates
19
+ # <a href="/" class="btn extra"><span>Text</span></a>
5
20
  def link_button(*args, &block)
6
21
  doc = Hpricot(link_to(*args, &block))
7
22
  doc.at("a").inner_html = "<span>#{doc.at("a").inner_html}</span>"
@@ -9,6 +24,25 @@ module Viewaide
9
24
  doc.to_html
10
25
  end
11
26
 
27
+ # Generates a link to an email address.
28
+ # This functions exactly like Rails' #link_to but changes the href to include "mailto:"
29
+ # @param [String] email_address the email address for the link
30
+ # @param [*Args]
31
+ # @return [String]
32
+ # @example
33
+ # <%= link_to_email "abc@def.com" %>
34
+ # generates
35
+ # <a href="mailto:abc@def.com">abc@def.com</a>
36
+ #
37
+ # @example
38
+ # <%= link_to_email "abc@def.com", "John Doe" %>
39
+ # generates
40
+ # <a href="mailto:abc@def.com">John Doe</a>
41
+ #
42
+ # @example
43
+ # <%= link_to_email "abc@def.com", "John Doe", :class => "extra" %>
44
+ # generates
45
+ # <a href="mailto:abc@def.com" class="extra">John Doe</a>
12
46
  def link_to_email(email_address, *args)
13
47
  options = args.extract_options!
14
48
  link = args.first.is_a?(String) ? h(args.first) : email_address
@@ -1,7 +1,19 @@
1
1
  module Viewaide
2
2
  module Helpers
3
3
  module MessageHelper
4
-
4
+ # Generates paragraphs, each containing the values of the hash passed
5
+ # @param [Hash] messages a hash (#flash, especially) that will render the values in separate paragraphs
6
+ # @return [String]
7
+ # @example
8
+ # <%= messages(:notice => "Your record was saved") %>
9
+ # generates
10
+ # <p class="notice box single-line">Your record was saved</p>
11
+ #
12
+ # @example
13
+ # <%= messages(:notice => "Your record was saved", :error => "Something happened!") %>
14
+ # generates
15
+ # <p class="notice box single-line">Your record was saved</p>
16
+ # <p class="error box single-line">Something happened!</p>
5
17
  def messages(messages, options = {})
6
18
  except_keys = [options[:except]].flatten.compact
7
19
  only_keys = [options[:only]].flatten.compact
@@ -1,6 +1,23 @@
1
1
  module Viewaide
2
2
  module Helpers
3
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>
4
21
  def tab(name, path, options = {}, li_options = {})
5
22
  opts = parse_tab_options(name, li_options)
6
23
 
@@ -2,6 +2,21 @@ module Viewaide
2
2
  module Helpers
3
3
  module StructureHelper
4
4
 
5
+ # Generate a blockquote
6
+ # @param [*Args]
7
+ # @return [String]
8
+ # @example
9
+ # <% blockquote do %>Quoted text<% end %>
10
+ # generates
11
+ # <blockquote>Quoted text</blockquote>
12
+ #
13
+ # @example
14
+ # <% blockquote :author => "W. Shakespeare" do %>All the world's a stage<% end %>
15
+ # generates
16
+ # <div class="quote-cited">
17
+ # <blockquote>All the world's a stage</blockquote>
18
+ # <cite>W. Shakespeare</cite>
19
+ # </div>
5
20
  def blockquote(*args, &block)
6
21
  options = args.extract_options!
7
22
  author = options.delete(:author)
@@ -21,6 +36,26 @@ module Viewaide
21
36
  concat(html)
22
37
  end
23
38
 
39
+ # Allows assignment of <body> attributes.
40
+ # The body (when accepting a block) should be used in your application's layout
41
+ # @param [*Args]
42
+ # @return [String]
43
+ # @example
44
+ # <% body do %>body goes here<% end %>
45
+ # generates
46
+ # <body>body goes here</body>
47
+ #
48
+ # @example
49
+ # <% body :home, "logged-in", :id => "application" do %>body goes here<% end %>
50
+ # generates
51
+ # <body class="home logged-in" id="application">body goes here</body>
52
+ #
53
+ # @example
54
+ # <% body :home, "logged-in" %> # within an ERB template
55
+ # <% body :id => "application" %> # within a different ERB template
56
+ # <% body do %>body goes here<% end %> # within application layout
57
+ # generates
58
+ # <body class="home logged-in" id="application">body goes here</body>
24
59
  def body(*args)
25
60
  options = args.extract_options!
26
61
  @_page_body_attributes ||= {}
@@ -2,6 +2,23 @@ module Viewaide
2
2
  module Helpers
3
3
  module TableHelper
4
4
 
5
+ # Generates <tr> elements with alternating classes
6
+ # @param [Hash] options options passed for classes to cycle through
7
+ # @return [String]
8
+ # @example
9
+ # <% zebra_row do %>no class<% end %><% zebra_row do %>alt class<% end %>
10
+ # generates
11
+ # <tr>no class</tr>
12
+ # <tr class="alt">alt class</tr>
13
+ #
14
+ # @example
15
+ # <% (colors = %w(red white blue)).each do |color| %>
16
+ # <% zebra_row :cycle_list => colors do %>the color <%= color %><% end %>
17
+ # <% end %>
18
+ # generates
19
+ # <tr class="red">the color red</tr>
20
+ # <tr class="white">the color white</tr>
21
+ # <tr class="blue">the color blue</tr>
5
22
  def zebra_row(options = {}, &block)
6
23
  cycle_list = options.delete(:cycle_list) || [nil, "alt"]
7
24
  css_classes = [cycle(*cycle_list)] << options.delete(:class)
@@ -13,6 +30,25 @@ module Viewaide
13
30
  concat(html)
14
31
  end
15
32
 
33
+ # Generates a <table> and appropriate <thead> elements
34
+ # @param [*Args]
35
+ # @return [String]
36
+ # @example
37
+ # <% recordset :headers => ["First Column", "Second Column"] do %>
38
+ # <tbody>
39
+ # </tbody>
40
+ # <% end %>
41
+ # generates
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
+ # <tbody>
50
+ # </tbody>
51
+ # </table>
16
52
  def recordset(*args, &block)
17
53
  options = args.extract_options!
18
54
  options[:table] ||= {}
@@ -32,6 +32,8 @@ module Viewaide
32
32
  end
33
33
 
34
34
  module InstanceMethods
35
+ # Clears viewaide session counts for non-XHR requests
36
+ # @return [nil]
35
37
  def clear_viewaide_cache
36
38
  session[:viewaide_cached_column_counts] = nil unless request.xhr?
37
39
  end
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.3.1"
8
+ s.version = "0.3.2"
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-09}
12
+ s.date = %q{2010-01-12}
13
13
  s.description = %q{Making your views easier}
14
14
  s.email = %q{joshua.clayton@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -74,16 +74,16 @@ Gem::Specification.new do |s|
74
74
  s.specification_version = 3
75
75
 
76
76
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
77
- s.add_runtime_dependency(%q<actionview>, [">= 2.1.0"])
77
+ s.add_runtime_dependency(%q<actionpack>, [">= 2.1.0"])
78
78
  s.add_runtime_dependency(%q<activesupport>, [">= 2.1.0"])
79
79
  s.add_runtime_dependency(%q<hpricot>, [">= 0.8.1"])
80
80
  else
81
- s.add_dependency(%q<actionview>, [">= 2.1.0"])
81
+ s.add_dependency(%q<actionpack>, [">= 2.1.0"])
82
82
  s.add_dependency(%q<activesupport>, [">= 2.1.0"])
83
83
  s.add_dependency(%q<hpricot>, [">= 0.8.1"])
84
84
  end
85
85
  else
86
- s.add_dependency(%q<actionview>, [">= 2.1.0"])
86
+ s.add_dependency(%q<actionpack>, [">= 2.1.0"])
87
87
  s.add_dependency(%q<activesupport>, [">= 2.1.0"])
88
88
  s.add_dependency(%q<hpricot>, [">= 0.8.1"])
89
89
  end
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.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Clayton
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-09 00:00:00 -05:00
12
+ date: 2010-01-12 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: actionview
16
+ name: actionpack
17
17
  type: :runtime
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement