record_tag_helper 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8253794b3fab21cbf65384d8ac9c08ea94f460f7
4
+ data.tar.gz: 992b983c94b08156dee4869bb1903179a19430b4
5
+ SHA512:
6
+ metadata.gz: c415f7a919ed1e04c796162b069ba7a85e976b7b46c3fe13ac6ae7b9f21813d00af8b5a441cc5190646e0ccc36b7dfe50e49b31b7fe69e385d6594107d600fc7
7
+ data.tar.gz: 7c1adcff3902e8e983ed20d00878d73fecc9895ce7a4ede9e89428e22be19cd56409145359b7ea0001d71e81bb5ed320881ee1bf9f519a069badc3762dfe62f0
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 David Heinemeier Hansson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,84 @@
1
+ RecordTagHelper
2
+ =================
3
+ [![Build Status](https://travis-ci.org/rails/record_tag_helper.svg?branch=master)](https://travis-ci.org/rails/record_tag_helper)
4
+
5
+ RecordTagHelper consists of code that was formerly a part of `ActionView`, but is being removed from Rails core for the upcoming 5.0.0 release. This gem is provided to ensure projects that use functionality from `ActionView::Helpers::RecordTagHelper` have an appropriate upgrade path.
6
+
7
+ This gem provides methods for generating container tags, such as `div`, for your record. This is the recommended way of creating a container for your Active Record object, as it adds appropriate class and id attributes to that container. You can then refer to those containers easily by following that convention, instead of having to think about which class or id attribute you should use.
8
+
9
+ ### Getting Started
10
+
11
+ Simply add `gem 'record_tag_helper', '~> 1.0'` to your Gemfile and run `bundle install`.
12
+
13
+ #### `content_tag_for`
14
+
15
+ Renders a container tag that relates to your Active Record Object.
16
+
17
+ For example, given `@article` is an object of type `Article`, you can do:
18
+
19
+ ```html+erb
20
+ <%= content_tag_for(:tr, @article) do %>
21
+ <td><%= @article.title %></td>
22
+ <% end %>
23
+ ```
24
+
25
+ This will generate this HTML output:
26
+
27
+ ```html
28
+ <tr id="article_1234" class="article">
29
+ <td>Hello World!</td>
30
+ </tr>
31
+ ```
32
+
33
+ You can also supply HTML attributes as an additional option hash. For example:
34
+
35
+ ```html+erb
36
+ <%= content_tag_for(:tr, @article, class: "frontpage") do %>
37
+ <td><%= @article.title %></td>
38
+ <% end %>
39
+ ```
40
+
41
+ Will generate this HTML output:
42
+
43
+ ```html
44
+ <tr id="article_1234" class="article frontpage">
45
+ <td>Hello World!</td>
46
+ </tr>
47
+ ```
48
+
49
+ You can pass a collection of Active Record objects. This method will loop through your objects and create a container for each of them. For example, given `@articles` is an array of two `Article` objects:
50
+
51
+ ```html+erb
52
+ <%= content_tag_for(:tr, @articles) do |article| %>
53
+ <td><%= article.title %></td>
54
+ <% end %>
55
+ ```
56
+
57
+ Will generate this HTML output:
58
+
59
+ ```html
60
+ <tr id="article_1234" class="article">
61
+ <td>Hello World!</td>
62
+ </tr>
63
+ <tr id="article_1235" class="article">
64
+ <td>Ruby on Rails Rocks!</td>
65
+ </tr>
66
+ ```
67
+
68
+ #### `div_for`
69
+
70
+ This is actually a convenient method which calls `content_tag_for` internally with `:div` as the tag name. You can pass either an Active Record object or a collection of objects. For example:
71
+
72
+ ```html+erb
73
+ <%= div_for(@article, class: "frontpage") do %>
74
+ <td><%= @article.title %></td>
75
+ <% end %>
76
+ ```
77
+
78
+ Will generate this HTML output:
79
+
80
+ ```html
81
+ <div id="article_1234" class="article frontpage">
82
+ <td>Hello World!</td>
83
+ </div>
84
+ ```
@@ -0,0 +1,108 @@
1
+ require 'action_view/record_identifier'
2
+
3
+ module ActionView
4
+ # = Action View Record Tag Helpers
5
+ module Helpers
6
+ module RecordTagHelper
7
+ include ActionView::RecordIdentifier
8
+
9
+ # Produces a wrapper DIV element with id and class parameters that
10
+ # relate to the specified Active Record object. Usage example:
11
+ #
12
+ # <%= div_for(@person, class: "foo") do %>
13
+ # <%= @person.name %>
14
+ # <% end %>
15
+ #
16
+ # produces:
17
+ #
18
+ # <div id="person_123" class="person foo"> Joe Bloggs </div>
19
+ #
20
+ # You can also pass an array of Active Record objects, which will then
21
+ # get iterated over and yield each record as an argument for the block.
22
+ # For example:
23
+ #
24
+ # <%= div_for(@people, class: "foo") do |person| %>
25
+ # <%= person.name %>
26
+ # <% end %>
27
+ #
28
+ # produces:
29
+ #
30
+ # <div id="person_123" class="person foo"> Joe Bloggs </div>
31
+ # <div id="person_124" class="person foo"> Jane Bloggs </div>
32
+ #
33
+ def div_for(record, *args, &block)
34
+ content_tag_for(:div, record, *args, &block)
35
+ end
36
+
37
+ # content_tag_for creates an HTML element with id and class parameters
38
+ # that relate to the specified Active Record object. For example:
39
+ #
40
+ # <%= content_tag_for(:tr, @person) do %>
41
+ # <td><%= @person.first_name %></td>
42
+ # <td><%= @person.last_name %></td>
43
+ # <% end %>
44
+ #
45
+ # would produce the following HTML (assuming @person is an instance of
46
+ # a Person object, with an id value of 123):
47
+ #
48
+ # <tr id="person_123" class="person">....</tr>
49
+ #
50
+ # If you require the HTML id attribute to have a prefix, you can specify it:
51
+ #
52
+ # <%= content_tag_for(:tr, @person, :foo) do %> ...
53
+ #
54
+ # produces:
55
+ #
56
+ # <tr id="foo_person_123" class="person">...
57
+ #
58
+ # You can also pass an array of objects which this method will loop through
59
+ # and yield the current object to the supplied block, reducing the need for
60
+ # having to iterate through the object (using <tt>each</tt>) beforehand.
61
+ # For example (assuming @people is an array of Person objects):
62
+ #
63
+ # <%= content_tag_for(:tr, @people) do |person| %>
64
+ # <td><%= person.first_name %></td>
65
+ # <td><%= person.last_name %></td>
66
+ # <% end %>
67
+ #
68
+ # produces:
69
+ #
70
+ # <tr id="person_123" class="person">...</tr>
71
+ # <tr id="person_124" class="person">...</tr>
72
+ #
73
+ # content_tag_for also accepts a hash of options, which will be converted to
74
+ # additional HTML attributes. If you specify a <tt>:class</tt> value, it will be combined
75
+ # with the default class name for your object. For example:
76
+ #
77
+ # <%= content_tag_for(:li, @person, class: "bar") %>...
78
+ #
79
+ # produces:
80
+ #
81
+ # <li id="person_123" class="person bar">...
82
+ #
83
+ def content_tag_for(tag_name, single_or_multiple_records, prefix = nil, options = nil, &block)
84
+ options, prefix = prefix, nil if prefix.is_a?(Hash)
85
+
86
+ Array(single_or_multiple_records).map do |single_record|
87
+ content_tag_for_single_record(tag_name, single_record, prefix, options, &block)
88
+ end.join("\n").html_safe
89
+ end
90
+
91
+ private
92
+
93
+ # Called by <tt>content_tag_for</tt> internally to render a content tag
94
+ # for each record.
95
+ def content_tag_for_single_record(tag_name, record, prefix, options, &block)
96
+ options = options ? options.dup : {}
97
+ options[:class] = [ dom_class(record, prefix), options[:class] ].compact
98
+ options[:id] = dom_id(record, prefix)
99
+
100
+ if block_given?
101
+ content_tag(tag_name, capture(record, &block), options)
102
+ else
103
+ content_tag(tag_name, "", options)
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,11 @@
1
+ require 'action_view'
2
+
3
+ module ActionView
4
+ module Helpers
5
+ autoload :RecordTagHelper, 'action_view/helpers/record_tag_helper'
6
+ end
7
+ end
8
+
9
+ ActiveSupport.on_load(:action_view) do
10
+ include ActionView::Helpers::RecordTagHelper
11
+ end
@@ -0,0 +1,3 @@
1
+ module RecordTagHelper
2
+ VERSION = "0.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: record_tag_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - David Heinemeier Hansson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.0.alpha
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.0.0.alpha
27
+ description: ActionView Record Tag Helpers
28
+ email: david@loudthinking.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - LICENSE
34
+ - README.md
35
+ - lib/action_view/helpers/record_tag_helper.rb
36
+ - lib/record_tag_helper.rb
37
+ - lib/record_tag_helper/version.rb
38
+ homepage: https://github.com/todd/record_tag_helper
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.2.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.4.5
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: ActionView Record Tag Helpers
62
+ test_files: []
63
+ has_rdoc: