active_html_tags 0.1.0

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
+ SHA256:
3
+ metadata.gz: 20be1d0b49a3501924cc532bce80310d2f3f2cbd9815ebdaf4c513fbb14bb6a4
4
+ data.tar.gz: 87cc98938f77d8188c7a6ccf6d20a98004c50f920913a884b8698cfb0f422a77
5
+ SHA512:
6
+ metadata.gz: 24ea23e08946c99c4f51ee570f5887487ca3a14819d36dee12bc04ebd619b2ee68a53c3f0c708f84d27b81de92bbd9d56332e556d7d1b5f6f452e5e0f4fd59e4
7
+ data.tar.gz: 42aaf129a568fa6ed1fbd58771410e895a9d9384b68ab342929156a3b6f0455acf558da27b592ea152100336c475667f6a9ae509187071caed14ea3fc4f2bdef
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2021 Fabian
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,142 @@
1
+ # ActiveHtmlTags
2
+
3
+ A simple helper to simplify the generation of html by bringing `content_tag` to the next level.
4
+
5
+ # Getting started
6
+
7
+ Add the gem to your Gemfile. For the last officially released gem:
8
+
9
+ ```ruby
10
+ gem 'active_html_tags'
11
+ ```
12
+
13
+ Now you should be able to use any html tag as a ruby method in your views.
14
+
15
+ # Usage
16
+
17
+ ActiveHtmlTags is a helper to use any kind of HTML tag as a direct method instead of passing it to `content_tag`. At the same time it allows for multiple arguments to be given and for smarter options.
18
+
19
+ ```ruby
20
+ # In any view using ApplicationHelper, for example in app/views/___/___.html.erb or app/views/layouts/application.html.erb
21
+
22
+ <%= h1 "This is pretty awesome" %>
23
+ <%= content_tag :h1, "compared to this" %>
24
+ ```
25
+
26
+ The name mappings from html tags to method names are 1:1. Therefore you can create constructs like these:
27
+ ```ruby
28
+ <%= div do %>
29
+ <%= table do %>
30
+ <%= tr do %>
31
+ <%= th "but it doesn't stop here" %>
32
+ <%= td do %>
33
+ you can make such nice tables
34
+ <% end %>
35
+ <% end %>
36
+ <%= tr(th("very dense tables?"), td(:yes)) %>
37
+ <% end %>
38
+
39
+ <%= table tr(th("complete tables?"), td(:yes)) %>
40
+ <% end %>
41
+ ```
42
+
43
+ A list of all HTML available and usable tags can be found on [w3schools - TAGs](https://www.w3schools.com/TAGs/)
44
+
45
+ ### Unlimited arguments
46
+
47
+ Additionally the `content_tag` method signature has been improved slightly. Now it supports a list of arguments
48
+ ```ruby
49
+ <%= h1 "This is pretty awesome", "because you can add as much as you want", small("and what you want") %>
50
+ vs
51
+ <%= content_tag :h1, safe_join(["this is", "not very", "sexy", content_tag(:small, "or readable")], " ") %>
52
+ ```
53
+
54
+ ### Advanced options for style
55
+
56
+ Have you ever wondered why this happens with css? Now you don't have run into this anymore, arrays and hashes are first class citizens in ActiveHtmlTags.
57
+
58
+ ```ruby
59
+ <%= span "this text is actually green", style: {color: :green}%>
60
+ # <span style="color: green">this text is actually green</span>
61
+ vs
62
+ <%= content_tag :span, "this text is sadly not green", style: {color: :green}%>
63
+ # <span style="{color: :green}">this text is sadly not green</span>
64
+ ```
65
+
66
+ This allows for more complex scenarios
67
+ ```ruby
68
+ <%= base_style = {"background-color" => "blue"} # Place this somewhere nicely to allow for compositon. %>
69
+
70
+ <%= span "this text is actually green on blue", style: base_style.merge({color: :green}) %>
71
+ # <span style="background-color: blue ; color: green">this text is actually green on blue</span>
72
+ ```
73
+
74
+ Of course arrays are loved too.
75
+ ```ruby
76
+ <% base_style = ["background-color: blue"]%>
77
+
78
+ <%= span "this text is actually green on blue", style: base_style + ["color: green"] %>
79
+ # <span style="background-color: blue ; color: green">this text is actually green on blue</span>
80
+ ```
81
+
82
+ Boht arrays and hashes are joined using ` ; `
83
+
84
+ ### Advanced options for javascript
85
+
86
+ Options will be joined using ` ; ` in case of html attributes who require javascript. A reference of these is also available here: [w3schools - HTML Attribute Reference](https://www.w3schools.com/tags/ref_attributes.asp)
87
+ ```ruby
88
+ <%= span "don't click me", onclick: ["1 + 1", "2 + 2"] %>
89
+ # <span onclick="1 + 1 ; 2 + 2">don't click me</span>
90
+ ```
91
+
92
+ Only the values will be shown in case of hashes. This allows easier code re-use and overwriting.
93
+ ```ruby
94
+ <%= span "don't click me", onclick: {base: "1 + 1", feature: "2 + 2"} %>
95
+ # <span onclick="1 + 1 ; 2 + 2">don't click me</span>
96
+ ```
97
+
98
+ ### Advanced options for class and all other attributes
99
+
100
+ In all other cases, arrays and hash values will be joined using spaces ` `. A reference of all html attributes is also available here: [w3schools - HTML Attribute Reference](https://www.w3schools.com/tags/ref_attributes.asp)
101
+
102
+ ```ruby
103
+ <% current_color = good_or_bad ? "btn-primary" : "btn-default" %>
104
+ <% current_size = nice_or_cool ? "btn-lg" : "btn-sm" %>
105
+ <%= span "a nice bootstrap button", class: ["btn", current_state, current_size] %>
106
+ # <span class="btn btn-primary btn-lg">a nice boostrap button</span>
107
+ ```
108
+
109
+ In case of hashes, you can override values easier.
110
+ ```ruby
111
+ <% base_button = {base: :btn, color: "btn-primary"} %>
112
+
113
+ <%= span "a nice bootstrap button", class: base_button) %>
114
+ # <span class="btn btn-primary">a nice boostrap button</span>
115
+
116
+ <%= span "a nice bootstrap button", class: base_button.merge({color: "btn-danger"}) %>
117
+ # <span class="btn btn-danger">a nice boostrap button</span>
118
+ ```
119
+
120
+ ## Installation
121
+ Add this line to your application's Gemfile:
122
+
123
+ ```ruby
124
+ gem 'active_html_tags'
125
+ ```
126
+
127
+ And then execute:
128
+ ```bash
129
+ $ bundle
130
+ ```
131
+
132
+ Or install it yourself as:
133
+ ```bash
134
+ $ gem install active_html_tags
135
+ ```
136
+
137
+ ## Contributing
138
+
139
+ Feel free to create a merge request in case of bugs, features and more.
140
+
141
+ ## License
142
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require "bundler/setup"
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ require "rake/testtask"
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << 'test'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.verbose = false
11
+ end
12
+
13
+ task default: :test
@@ -0,0 +1,4 @@
1
+ module ActiveHtmlTags
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveHtmlTags
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,342 @@
1
+ require "active_html_tags/version"
2
+ require "active_html_tags/railtie"
3
+
4
+ module ActiveHtmlTags
5
+ HTML_TAGS = [
6
+ :a,
7
+ :abbr,
8
+ :acronym,
9
+ :address,
10
+ :applet,
11
+ :area,
12
+ :article,
13
+ :aside,
14
+ :audio,
15
+ :b,
16
+ :base,
17
+ :basefont,
18
+ :bb,
19
+ :bdo,
20
+ :big,
21
+ :blockquote,
22
+ :body,
23
+ :button,
24
+ :canvas,
25
+ :caption,
26
+ :center,
27
+ :cite,
28
+ :code,
29
+ :col,
30
+ :colgroup,
31
+ :command,
32
+ :datagrid,
33
+ :datalist,
34
+ :dd,
35
+ :del,
36
+ :details,
37
+ :dfn,
38
+ :dialog,
39
+ :dir,
40
+ :div,
41
+ :dl,
42
+ :dt,
43
+ :em,
44
+ :embed,
45
+ :eventsource,
46
+ :fieldset,
47
+ :figcaption,
48
+ :figure,
49
+ :font,
50
+ :footer,
51
+ :form,
52
+ :frame,
53
+ :frameset,
54
+ :h1,
55
+ :h2,
56
+ :h3,
57
+ :h4,
58
+ :h5,
59
+ :h6,
60
+ :head,
61
+ :header,
62
+ :hgroup,
63
+ :html,
64
+ :i,
65
+ :iframe,
66
+ :img,
67
+ :input,
68
+ :ins,
69
+ :isindex,
70
+ :kbd,
71
+ :keygen,
72
+ :label,
73
+ :legend,
74
+ :li,
75
+ :link,
76
+ :map,
77
+ :mark,
78
+ :menu,
79
+ :meta,
80
+ :meter,
81
+ :nav,
82
+ :noframes,
83
+ :noscript,
84
+ :object,
85
+ :ol,
86
+ :optgroup,
87
+ :option,
88
+ :output,
89
+ :p,
90
+ :param,
91
+ :pre,
92
+ :progress,
93
+ :q,
94
+ :rp,
95
+ :rt,
96
+ :ruby,
97
+ :s,
98
+ :samp,
99
+ :script,
100
+ :section,
101
+ :select,
102
+ :small,
103
+ :source,
104
+ :span,
105
+ :strike,
106
+ :strong,
107
+ :style,
108
+ :sub,
109
+ :sup,
110
+ :table,
111
+ :tbody,
112
+ :td,
113
+ :textarea,
114
+ :tfoot,
115
+ :th,
116
+ :thead,
117
+ :time,
118
+ :title,
119
+ :tr,
120
+ :track,
121
+ :tt,
122
+ :u,
123
+ :ul,
124
+ :var,
125
+ :video,
126
+ :wbr,
127
+ :hr,
128
+ :br,
129
+ # :"!--...--",
130
+ # :"!doctype",
131
+ ]
132
+
133
+ HTML_ATTRIBUTES = {
134
+ accept: :default,
135
+ #accept-charset: :default,
136
+ accept_charset: :default,
137
+ accesskey: :default,
138
+ action: :default,
139
+ align: :default,
140
+ alt: :default,
141
+ async: :js,
142
+ autocomplete: :default,
143
+ autofocus: :default,
144
+ autoplay: :default,
145
+ bgcolor: :default,
146
+ border: :default,
147
+ charset: :default,
148
+ checked: :default,
149
+ cite: :default,
150
+ class: :default,
151
+ color: :default,
152
+ cols: :default,
153
+ colspan: :default,
154
+ content: :default,
155
+ contenteditable: :default,
156
+ controls: :default,
157
+ coords: :default,
158
+ data: :default,
159
+ #data-*: :default,
160
+ datetime: :default,
161
+ default: :default,
162
+ defer: :js,
163
+ dir: :default,
164
+ dirname: :default,
165
+ disabled: :default,
166
+ download: :default,
167
+ draggable: :default,
168
+ enctype: :default,
169
+ for: :default,
170
+ form: :default,
171
+ formaction: :default,
172
+ headers: :default,
173
+ height: :default,
174
+ hidden: :default,
175
+ high: :default,
176
+ href: :default,
177
+ hreflang: :default,
178
+ #http-equiv: :default,
179
+ http_equiv: :default,
180
+ id: :default,
181
+ ismap: :default,
182
+ kind: :default,
183
+ label: :default,
184
+ lang: :default,
185
+ list: :default,
186
+ loop: :default,
187
+ low: :default,
188
+ max: :default,
189
+ maxlength: :default,
190
+ media: :default,
191
+ method: :default,
192
+ min: :default,
193
+ multiple: :default,
194
+ muted: :default,
195
+ name: :default,
196
+ novalidate: :default,
197
+ onabort: :js,
198
+ onafterprint: :js,
199
+ onbeforeprint: :js,
200
+ onbeforeunload: :js,
201
+ onblur: :js,
202
+ oncanplay: :js,
203
+ oncanplaythrough: :js,
204
+ onchange: :js,
205
+ onclick: :js,
206
+ oncontextmenu: :js,
207
+ oncopy: :js,
208
+ oncuechange: :js,
209
+ oncut: :js,
210
+ ondblclick: :js,
211
+ ondrag: :js,
212
+ ondragend: :js,
213
+ ondragenter: :js,
214
+ ondragleave: :js,
215
+ ondragover: :js,
216
+ ondragstart: :js,
217
+ ondrop: :js,
218
+ ondurationchange: :js,
219
+ onemptied: :js,
220
+ onended: :js,
221
+ onerror: :js,
222
+ onfocus: :js,
223
+ onhashchange: :js,
224
+ oninput: :js,
225
+ oninvalid: :js,
226
+ onkeydown: :js,
227
+ onkeypress: :js,
228
+ onkeyup: :js,
229
+ onload: :js,
230
+ onloadeddata: :js,
231
+ onloadedmetadata: :js,
232
+ onloadstart: :js,
233
+ onmousedown: :js,
234
+ onmousemove: :js,
235
+ onmouseout: :js,
236
+ onmouseover: :js,
237
+ onmouseup: :js,
238
+ onmousewheel: :js,
239
+ onoffline: :js,
240
+ ononline: :js,
241
+ onpagehide: :js,
242
+ onpageshow: :js,
243
+ onpaste: :js,
244
+ onpause: :js,
245
+ onplay: :js,
246
+ onplaying: :js,
247
+ onpopstate: :js,
248
+ onprogress: :js,
249
+ onratechange: :js,
250
+ onreset: :js,
251
+ onresize: :js,
252
+ onscroll: :js,
253
+ onsearch: :js,
254
+ onseeked: :js,
255
+ onseeking: :js,
256
+ onselect: :js,
257
+ onstalled: :js,
258
+ onstorage: :js,
259
+ onsubmit: :js,
260
+ onsuspend: :js,
261
+ ontimeupdate: :js,
262
+ ontoggle: :js,
263
+ onunload: :js,
264
+ onvolumechange: :js,
265
+ onwaiting: :js,
266
+ onwheel: :js,
267
+ open: :default,
268
+ optimum: :default,
269
+ pattern: :default,
270
+ placeholder: :default,
271
+ poster: :default,
272
+ preload: :default,
273
+ readonly: :default,
274
+ rel: :default,
275
+ required: :default,
276
+ reversed: :default,
277
+ rows: :default,
278
+ rowspan: :default,
279
+ sandbox: :default,
280
+ scope: :default,
281
+ selected: :default,
282
+ shape: :default,
283
+ size: :default,
284
+ sizes: :default,
285
+ span: :default,
286
+ spellcheck: :default,
287
+ src: :default,
288
+ srcdoc: :default,
289
+ srclang: :default,
290
+ srcset: :default,
291
+ start: :default,
292
+ step: :default,
293
+ style: :style,
294
+ tabindex: :default,
295
+ target: :default,
296
+ title: :default,
297
+ translate: :default,
298
+ type: :default,
299
+ usemap: :default,
300
+ value: :default,
301
+ width: :default,
302
+ wrap: :default,
303
+ }
304
+
305
+ HTML_TAGS.each do |tagname|
306
+ define_method tagname do |*args, safe_join_with: " ", **opts, &blk|
307
+ opts.each do |key,value|
308
+ case HTML_ATTRIBUTES[key]
309
+ when :default
310
+ case opts[key]
311
+ when nil, String #fastpath
312
+ when Hash
313
+ opts = opts.merge(key => safe_join(opts[key].values, " "))
314
+ when Array
315
+ opts = opts.merge(key => safe_join(opts[key].map(&:to_s), " "))
316
+ end
317
+ when :style
318
+ case opts[:style]
319
+ when nil, String #fastpath
320
+ when Hash
321
+ opts = opts.merge(style: safe_join(opts[:style].map {|key,value| safe_join([key, value], ": ")}, " ; "))
322
+ when Array
323
+ opts = opts.merge(style: safe_join(opts[:style].map(&:to_s), " ; "))
324
+ end
325
+ when :js
326
+ case opts[key]
327
+ when nil, String # fastpath
328
+ when Hash
329
+ opts = opts.merge(key => safe_join(opts[key].values.flatten, " ; "))
330
+ when Array
331
+ opts = opts.merge(key => safe_join(opts[key].flatten.map(&:to_s), " ; "))
332
+ end
333
+ end
334
+ end
335
+ content_tag(tagname, safe_join(args.flatten, safe_join_with), **opts, &blk)
336
+ end
337
+ end
338
+ end
339
+
340
+ ActiveSupport.on_load(:action_controller) do
341
+ ActionController::Base.helper ActiveHtmlTags
342
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :active_html_tags do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_html_tags
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fabian stillhart
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-10-26 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: '6.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 6.1.4.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '6.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 6.1.4.1
33
+ description: Annoyed to write content_tag(:span, 'LOL')? Just use the new helpers
34
+ as follows span('lol') to avoid writing to much code while having the safety of
35
+ rails.
36
+ email:
37
+ - fabian_stillhart@hotmail.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - MIT-LICENSE
43
+ - README.md
44
+ - Rakefile
45
+ - lib/active_html_tags.rb
46
+ - lib/active_html_tags/railtie.rb
47
+ - lib/active_html_tags/version.rb
48
+ - lib/tasks/active_html_tags_tasks.rake
49
+ homepage: https://github.com/stillhart/active_html_tags
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ allowed_push_host: https://rubygems.org
54
+ homepage_uri: https://github.com/stillhart/active_html_tags
55
+ source_code_uri: https://github.com/stillhart/active_html_tags
56
+ changelog_uri: https://github.com/stillhart/active_html_tags
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.2.3
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: A simple helper to bring content_tag to the next level
76
+ test_files: []