markaby 0.9.0 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.ruby-version +1 -1
- data/.travis.yml +3 -7
- data/CHANGELOG.rdoc +19 -0
- data/Gemfile +10 -8
- data/Gemfile.lock +63 -49
- data/Markaby.gemspec +13 -16
- data/README.rdoc +67 -13
- data/Rakefile +30 -24
- data/lib/markaby/builder.rb +50 -73
- data/lib/markaby/builder_tags.rb +6 -4
- data/lib/markaby/cssproxy.rb +5 -5
- data/lib/markaby/html5.rb +118 -0
- data/lib/markaby/kernel_method.rb +3 -3
- data/lib/markaby/rails.rb +6 -6
- data/lib/markaby/tagset.rb +89 -0
- data/lib/markaby/version.rb +7 -0
- data/lib/markaby/xhtml_frameset.rb +13 -0
- data/lib/markaby/xhtml_strict.rb +89 -0
- data/lib/markaby/xhtml_transitional.rb +61 -0
- data/lib/markaby/xml_tagset.rb +19 -0
- data/lib/markaby.rb +6 -10
- data/spec/markaby/builder_spec.rb +1 -1
- data/spec/markaby/css_proxy_spec.rb +13 -12
- data/spec/markaby/html5_spec.rb +59 -25
- data/spec/markaby/markaby_spec.rb +19 -19
- data/spec/markaby/markaby_test_unit_spec.rb +97 -38
- data/spec/markaby/rails_spec.rb +1 -1
- data/spec/spec_helper.rb +18 -11
- metadata +19 -22
- data/lib/markaby/tags.rb +0 -310
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0dc12cb3b6384a562bf884e5fb8478ced1bfdb1334cbf861340b7bcad1eb6ea4
|
4
|
+
data.tar.gz: f313b51ab7011ea110dd3a1f5bcfd4b702b66edfb3401f9bcca4e35ee5906fc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 358e8500a7b6c8a418308f02d408dff670a1a201a0bb4af60445af98aa21e1c093ce835bea52e13403b9a9349f5f9672352673f452b185d8137e98e3edf72557
|
7
|
+
data.tar.gz: 3d377ee8f1d7982c7a4bfaa08b7f6f0f0839b6b37cccc515035e3b729946727a1f28db4dea130ab8338c7dafa6b92aa2774c3278be67baa228820187d7e3a231
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.3
|
1
|
+
ruby-2.7.3
|
data/.travis.yml
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
language: ruby
|
2
2
|
sudo: false
|
3
3
|
rvm:
|
4
|
-
- 1.8
|
5
|
-
- 1.9
|
6
|
-
- 2.0
|
7
|
-
- 2.1
|
8
|
-
- 2.2
|
9
|
-
- 2.3
|
10
4
|
- 2.4
|
5
|
+
- 2.5
|
6
|
+
- 2.6
|
7
|
+
- 2.7
|
11
8
|
matrix:
|
12
9
|
allow_failures:
|
13
|
-
- rvm: 2.5
|
14
10
|
- rvm: jruby-9.1.15.0
|
15
11
|
- rvm: rbx-2
|
16
12
|
install: bundle install --without=development --jobs=3 --retry=3
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
= HEAD
|
2
|
+
|
3
|
+
= 0.9.1
|
4
|
+
|
5
|
+
* update release tasks [tech task]
|
6
|
+
* re-release version since code was included in last release
|
7
|
+
|
8
|
+
= 0.9.0
|
9
|
+
|
10
|
+
* Add data attributes: https://github.com/markaby/markaby/pull/44 (rahoulb)
|
11
|
+
|
12
|
+
* Add data + aria attributes
|
13
|
+
* Allow creation of custom web components / elements in html5
|
14
|
+
my_custom_element prop: "value" =>
|
15
|
+
"<my-custom-element prop="value"></my-custom-element>"
|
16
|
+
See https://stackoverflow.com/questions/9845011/are-custom-elements-valid-html5
|
17
|
+
* split up tag sets into different files
|
18
|
+
* add standardrb + use code conventions
|
19
|
+
|
1
20
|
= 0.7.1 (2010-08-19)
|
2
21
|
|
3
22
|
* Rails fixes for form_for called from erb templates
|
data/Gemfile
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
|
-
gem
|
3
|
+
gem "builder"
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem "standardrb"
|
7
|
+
end
|
4
8
|
|
5
9
|
group :test do
|
6
|
-
gem
|
7
|
-
gem
|
8
|
-
gem
|
9
|
-
gem
|
10
|
-
gem 'ruby-debug', :platform => [:mri_18]
|
11
|
-
gem 'ruby-debug19', :platform => [:mri_19]
|
10
|
+
gem "rake"
|
11
|
+
gem "rspec"
|
12
|
+
gem "test-unit"
|
13
|
+
gem "byebug"
|
12
14
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,65 +1,79 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
rspec-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
rspec-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
4
|
+
ast (2.4.2)
|
5
|
+
builder (3.2.4)
|
6
|
+
byebug (11.1.3)
|
7
|
+
diff-lcs (1.5.0)
|
8
|
+
json (2.6.3)
|
9
|
+
language_server-protocol (3.17.0.3)
|
10
|
+
lint_roller (1.0.0)
|
11
|
+
parallel (1.23.0)
|
12
|
+
parser (3.2.2.1)
|
13
|
+
ast (~> 2.4.1)
|
14
|
+
power_assert (2.0.3)
|
15
|
+
rainbow (3.1.1)
|
16
|
+
rake (13.0.6)
|
17
|
+
regexp_parser (2.8.0)
|
18
|
+
rexml (3.2.5)
|
19
|
+
rspec (3.12.0)
|
20
|
+
rspec-core (~> 3.12.0)
|
21
|
+
rspec-expectations (~> 3.12.0)
|
22
|
+
rspec-mocks (~> 3.12.0)
|
23
|
+
rspec-core (3.12.2)
|
24
|
+
rspec-support (~> 3.12.0)
|
25
|
+
rspec-expectations (3.12.3)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.12.0)
|
28
|
+
rspec-mocks (3.12.5)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.12.0)
|
31
|
+
rspec-support (3.12.0)
|
32
|
+
rubocop (1.50.2)
|
33
|
+
json (~> 2.3)
|
34
|
+
parallel (~> 1.10)
|
35
|
+
parser (>= 3.2.0.0)
|
36
|
+
rainbow (>= 2.2.2, < 4.0)
|
37
|
+
regexp_parser (>= 1.8, < 3.0)
|
38
|
+
rexml (>= 3.2.5, < 4.0)
|
39
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
40
|
+
ruby-progressbar (~> 1.7)
|
41
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
42
|
+
rubocop-ast (1.28.1)
|
43
|
+
parser (>= 3.2.1.0)
|
44
|
+
rubocop-performance (1.16.0)
|
45
|
+
rubocop (>= 1.7.0, < 2.0)
|
46
|
+
rubocop-ast (>= 0.4.0)
|
47
|
+
ruby-progressbar (1.13.0)
|
48
|
+
standard (1.28.2)
|
49
|
+
language_server-protocol (~> 3.17.0.2)
|
50
|
+
lint_roller (~> 1.0)
|
51
|
+
rubocop (~> 1.50.2)
|
52
|
+
standard-custom (~> 1.0.0)
|
53
|
+
standard-performance (~> 1.0.1)
|
54
|
+
standard-custom (1.0.0)
|
55
|
+
lint_roller (~> 1.0)
|
56
|
+
standard-performance (1.0.1)
|
57
|
+
lint_roller (~> 1.0)
|
58
|
+
rubocop-performance (~> 1.16.0)
|
59
|
+
standardrb (1.0.1)
|
60
|
+
standard
|
61
|
+
test-unit (3.5.8)
|
50
62
|
power_assert
|
63
|
+
unicode-display_width (2.4.2)
|
51
64
|
|
52
65
|
PLATFORMS
|
66
|
+
arm64-darwin-22
|
53
67
|
ruby
|
68
|
+
x86_64-darwin-17
|
54
69
|
|
55
70
|
DEPENDENCIES
|
56
71
|
builder
|
57
72
|
byebug
|
58
73
|
rake
|
59
74
|
rspec
|
60
|
-
|
61
|
-
ruby-debug19
|
75
|
+
standardrb
|
62
76
|
test-unit
|
63
77
|
|
64
78
|
BUNDLED WITH
|
65
|
-
|
79
|
+
2.4.13
|
data/Markaby.gemspec
CHANGED
@@ -1,24 +1,21 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'markaby'
|
1
|
+
require_relative "lib/markaby/version"
|
5
2
|
|
6
3
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
11
|
-
spec.description
|
12
|
-
spec.summary
|
13
|
-
spec.homepage
|
14
|
-
spec.license
|
4
|
+
spec.name = "markaby"
|
5
|
+
spec.version = Markaby::VERSION
|
6
|
+
spec.authors = ["Scott Taylor", "judofyr", "_why"]
|
7
|
+
spec.email = ["scott@railsnewbie.com"]
|
8
|
+
spec.description = "_why's markaby templating language"
|
9
|
+
spec.summary = "A pure ruby based, html markup language"
|
10
|
+
spec.homepage = ""
|
11
|
+
spec.license = "MIT"
|
15
12
|
|
16
|
-
spec.files
|
17
|
-
spec.executables
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
13
|
+
spec.files = `git ls-files`.split($/)
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
15
|
spec.require_paths = ["lib"]
|
20
16
|
|
21
17
|
spec.add_dependency "builder"
|
22
|
-
spec.add_development_dependency "bundler", "
|
18
|
+
spec.add_development_dependency "bundler", ">= 2.2.10"
|
23
19
|
spec.add_development_dependency "rake"
|
20
|
+
spec.required_ruby_version = '>= 2.7.0'
|
24
21
|
end
|
data/README.rdoc
CHANGED
@@ -16,8 +16,6 @@ then bundle install:
|
|
16
16
|
|
17
17
|
bundle install
|
18
18
|
|
19
|
-
or gem install if you are a weirdo not using bundler.
|
20
|
-
|
21
19
|
=== Using Markaby with Rails 4/5+:
|
22
20
|
|
23
21
|
Install the gem (using bundler), then:
|
@@ -31,9 +29,6 @@ Install the gem (using bundler), then:
|
|
31
29
|
indent: 2,
|
32
30
|
})
|
33
31
|
|
34
|
-
Note, Markaby hasn't been tested on anything below Rails 5. Please submit bugs
|
35
|
-
and/or patches if you'd like support for anything before rails 5.
|
36
|
-
|
37
32
|
Name your templates with an html.mab extension. You'll also want to configure
|
38
33
|
your text editor to see .mab as ruby.
|
39
34
|
|
@@ -159,15 +154,17 @@ Which results in:
|
|
159
154
|
<div class="entryContent">Okay, once again, the idea here is ...</div>
|
160
155
|
</div>
|
161
156
|
|
157
|
+
Alternatively you can define the class as an attribute on your element - see below.
|
158
|
+
|
162
159
|
== 2. Element IDs
|
163
160
|
|
164
161
|
IDs may be added by the use of bang methods:
|
165
162
|
|
166
|
-
div.page!
|
167
|
-
div.content!
|
163
|
+
div.page! do
|
164
|
+
div.content! do
|
168
165
|
h1 "A Short Short Saintly Dog"
|
169
|
-
|
170
|
-
|
166
|
+
end
|
167
|
+
end
|
171
168
|
|
172
169
|
Which results in:
|
173
170
|
|
@@ -177,6 +174,8 @@ Which results in:
|
|
177
174
|
</div>
|
178
175
|
</div>
|
179
176
|
|
177
|
+
Alternatively you can define the ID as an attribute on your element - see below.
|
178
|
+
|
180
179
|
== 3. Validate Your XHTML 1.0 Output
|
181
180
|
|
182
181
|
If you'd like Markaby to help you assemble valid XHTML documents,
|
@@ -195,8 +194,8 @@ tag.
|
|
195
194
|
Now, since Markaby knows which doctype you're using, it checks a big
|
196
195
|
list of valid tags and attributes before printing anything.
|
197
196
|
|
198
|
-
>> div :
|
199
|
-
>> img :
|
197
|
+
>> div styl: "padding: 10px" do
|
198
|
+
>> img src: "samorost.jpg"
|
200
199
|
>> end
|
201
200
|
InvalidHtmlError: no such attribute `styl'
|
202
201
|
|
@@ -222,11 +221,11 @@ as an argument:
|
|
222
221
|
One caveat: if you have other tags inside a block, the string
|
223
222
|
passed back will be ignored.
|
224
223
|
|
225
|
-
div.comment
|
224
|
+
div.comment do
|
226
225
|
div.author "_why"
|
227
226
|
div.says "Torpedoooooes!"
|
228
227
|
"<div>Silence.</div>"
|
229
|
-
|
228
|
+
end
|
230
229
|
|
231
230
|
The final div above won't appear in the output. You can't mix
|
232
231
|
tag modes like that, friend.
|
@@ -269,6 +268,8 @@ won't work with this technique.
|
|
269
268
|
end
|
270
269
|
end
|
271
270
|
|
271
|
+
If you wish to register your own, specialist, tags, you can install a TagHandler
|
272
|
+
|
272
273
|
== Some other notes, so you aren't confused:
|
273
274
|
|
274
275
|
=== On using different tagsets:
|
@@ -283,6 +284,59 @@ sub-template:
|
|
283
284
|
Note, this is only necessary if you were rendering, say, a one off page as
|
284
285
|
html transitional but had the default engine as html5.
|
285
286
|
|
287
|
+
=== Defining attributes on elements
|
288
|
+
|
289
|
+
If you do not use the <tt>CssProxy</tt> (<tt>div.entry</tt> to define the class, <tt>div.page!</tt> to define the ID), then you can pass a hash to your element to define any arbitrary attributes.
|
290
|
+
|
291
|
+
div id: "page-123", class: "entry" do
|
292
|
+
div style: "display: inline-block;" do
|
293
|
+
p "Have you noticed this book is basically written by a lunatic?"
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
Will result in
|
298
|
+
|
299
|
+
<div id="page-123" class="entry">
|
300
|
+
<div style="display: inline-block;">
|
301
|
+
<p>Have you noticed this book is basically written by a lunatic?</p>
|
302
|
+
</div>
|
303
|
+
</div>
|
304
|
+
|
305
|
+
If you pass a hash to your attribute definition, Markaby will expand the hash entries. This is useful for data attributes (for example, if you are using a Stimulus controller), or aria attributes. Any attributes will have underscores replaced with dashes when the hash is expanded.
|
306
|
+
|
307
|
+
div data: { controller: "something" } do
|
308
|
+
div do
|
309
|
+
h1(data: { something_target: "title" }) { "There goes my pickup" }
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
Will result in
|
314
|
+
|
315
|
+
<div data-controller="something">
|
316
|
+
<div>
|
317
|
+
<h1 data-something-target="title">There goes my pickup</h1>
|
318
|
+
</div>
|
319
|
+
</div>
|
320
|
+
|
321
|
+
=== Custom elements and web components
|
322
|
+
|
323
|
+
If you are using the HTML5 tagset (which is the default), and your document has custom-elements defined, you can create those in the same way as standard elements.
|
324
|
+
|
325
|
+
Unlike standard elements, there is no validity checking for your attributes.
|
326
|
+
|
327
|
+
article do
|
328
|
+
my_custom_panel variant: "primary" do
|
329
|
+
p "Our careers are so over"
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
Results in
|
334
|
+
|
335
|
+
<article>
|
336
|
+
<my-custom-panel variant="primary">
|
337
|
+
<p>Our careers are so over</p>
|
338
|
+
</my-custom-panel>
|
339
|
+
</article>
|
286
340
|
|
287
341
|
= Credits
|
288
342
|
|
data/Rakefile
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
require
|
1
|
+
require "rake"
|
2
2
|
require "bundler/gem_tasks"
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
require "rake/clean"
|
5
5
|
|
6
6
|
RSpec::Core::RakeTask.new(:spec)
|
7
|
-
task :
|
7
|
+
task default: :spec
|
8
8
|
|
9
9
|
Bundler::GemHelper.install_tasks
|
10
10
|
|
11
11
|
desc "List any Markaby specific warnings"
|
12
12
|
task :warnings do
|
13
|
-
`ruby -w test/test_markaby.rb 2>&1`.split(
|
14
|
-
next unless
|
15
|
-
next if
|
13
|
+
`ruby -w test/test_markaby.rb 2>&1`.split("\n").each do |line|
|
14
|
+
next unless /warning:/.match?(line)
|
15
|
+
next if /builder-/.match?(line)
|
16
16
|
puts line
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
desc "Start a Markaby-aware IRB session"
|
21
21
|
task :irb do
|
22
|
-
sh
|
22
|
+
sh "irb -I lib -r markaby -r markaby/kernel_method"
|
23
23
|
end
|
24
24
|
|
25
25
|
namespace :gemspec do
|
@@ -29,19 +29,25 @@ namespace :gemspec do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
#
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
#
|
41
|
-
#
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
32
|
+
namespace :release do
|
33
|
+
# make sure to bump version + update changelogs in lib/markaby/version.rb before running
|
34
|
+
task :patch => [:spec, :update_gemspec, :tag_release, :build, :push_tags]
|
35
|
+
|
36
|
+
task :update_gemspec => ["gemspec:commit"]
|
37
|
+
|
38
|
+
task :tag_release do
|
39
|
+
require File.dirname(__FILE__) + "/lib/markaby"
|
40
|
+
version = "v#{Markaby::VERSION}"
|
41
|
+
sh "git tag #{version}"
|
42
|
+
end
|
43
|
+
|
44
|
+
task :push_tags do
|
45
|
+
sh "git push --tags"
|
46
|
+
end
|
47
|
+
|
48
|
+
task :push_gem do
|
49
|
+
sh "gem push pkg/markaby-#{Markaby::VERSION}.gem"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
task :release => "release:patch"
|
data/lib/markaby/builder.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "markaby/tagset"
|
2
|
+
require "markaby/builder_tags"
|
3
3
|
|
4
4
|
module Markaby
|
5
5
|
RUBY_VERSION_ID = RUBY_VERSION.split(".").join.to_i
|
@@ -23,13 +23,12 @@ module Markaby
|
|
23
23
|
#
|
24
24
|
class Builder
|
25
25
|
include Markaby::BuilderTags
|
26
|
-
|
27
26
|
GENERIC_OPTIONS = {
|
28
|
-
:
|
29
|
-
:
|
27
|
+
indent: 0,
|
28
|
+
auto_validation: true
|
30
29
|
}
|
31
30
|
|
32
|
-
HTML5_OPTIONS
|
31
|
+
HTML5_OPTIONS = HTML5.default_options.dup
|
33
32
|
DEFAULT_OPTIONS = GENERIC_OPTIONS.merge(HTML5_OPTIONS)
|
34
33
|
|
35
34
|
@@options = DEFAULT_OPTIONS.dup
|
@@ -52,7 +51,7 @@ module Markaby
|
|
52
51
|
@tagset = tagset
|
53
52
|
|
54
53
|
tagset.default_options.each do |k, v|
|
55
|
-
|
54
|
+
instance_variable_set("@#{k}".to_sym, v)
|
56
55
|
end
|
57
56
|
end
|
58
57
|
|
@@ -85,13 +84,11 @@ module Markaby
|
|
85
84
|
instance_variable_set("@#{k}", v)
|
86
85
|
end
|
87
86
|
|
88
|
-
|
89
|
-
helper.
|
90
|
-
instance_variable_set(iv, helper.instance_variable_get(iv))
|
91
|
-
end
|
87
|
+
helper&.instance_variables&.each do |iv|
|
88
|
+
instance_variable_set(iv, helper.instance_variable_get(iv))
|
92
89
|
end
|
93
90
|
|
94
|
-
@builder = XmlMarkup.new(:
|
91
|
+
@builder = XmlMarkup.new(indent: @indent, target: @streams.last)
|
95
92
|
|
96
93
|
text(capture(&block)) if block
|
97
94
|
end
|
@@ -150,56 +147,24 @@ module Markaby
|
|
150
147
|
# Create a tag named +tag+. Other than the first argument which is the tag name,
|
151
148
|
# the arguments are the same as the tags implemented via method_missing.
|
152
149
|
def tag!(tag, *args, &block)
|
153
|
-
|
154
|
-
|
155
|
-
# TODO: Move this logic to the tagset so that the tagset itself can validate + raise when invalid
|
150
|
+
attributes = {}
|
156
151
|
if @auto_validation && @tagset
|
157
|
-
|
158
|
-
|
159
|
-
elsif args.last.respond_to?(:to_hash)
|
160
|
-
attrs = args.last.to_hash
|
161
|
-
|
162
|
-
if @tagset.forms.include?(tag) && attrs[:id]
|
163
|
-
attrs[:name] ||= attrs[:id]
|
164
|
-
end
|
165
|
-
|
166
|
-
attrs.each do |k, v|
|
167
|
-
atname = k.to_s.downcase.intern
|
168
|
-
|
169
|
-
unless k =~ /:/ or @tagset.tagset[tag].include?(atname) or (@tagset == Markaby::HTML5 && atname.to_s =~ /^data-/)
|
170
|
-
raise InvalidXhtmlError, "no attribute `#{k}' on #{tag} elements"
|
171
|
-
end
|
172
|
-
|
173
|
-
if atname == :id
|
174
|
-
ele_id = v.to_s
|
175
|
-
|
176
|
-
if @used_ids.has_key? ele_id
|
177
|
-
raise InvalidXhtmlError, "id `#{ele_id}' already used (id's must be unique)."
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
if AttrsBoolean.include? atname
|
182
|
-
if v
|
183
|
-
attrs[k] = atname.to_s
|
184
|
-
else
|
185
|
-
attrs.delete k
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
152
|
+
attributes = @tagset.validate_and_transform_attributes!(tag, *args)
|
153
|
+
tag = @tagset.validate_and_transform_tag_name! tag
|
190
154
|
end
|
191
|
-
|
155
|
+
element_id = attributes[:id].to_s
|
156
|
+
raise InvalidXhtmlError, "id `#{element_id}' already used (id's must be unique)." if @used_ids.has_key?(element_id)
|
192
157
|
if block
|
193
158
|
str = capture(&block)
|
194
159
|
block = proc { text(str) }
|
195
160
|
end
|
196
161
|
|
197
162
|
f = fragment { @builder.tag!(tag, *args, &block) }
|
198
|
-
@used_ids[
|
163
|
+
@used_ids[element_id] = f unless element_id.empty?
|
199
164
|
f
|
200
165
|
end
|
201
166
|
|
202
|
-
|
167
|
+
private
|
203
168
|
|
204
169
|
# This method is used to intercept calls to helper methods and instance
|
205
170
|
# variables. Here is the order of interception:
|
@@ -210,32 +175,40 @@ module Markaby
|
|
210
175
|
# * If +sym+ is also the name of an instance variable, the
|
211
176
|
# value of the instance variable is returned.
|
212
177
|
# * If +sym+ has come this far and no +tagset+ is found, +sym+ and its arguments are passed to tag!
|
213
|
-
# * If a tagset is found,
|
178
|
+
# * If a tagset is found, the tagset is tole to handle +sym+
|
214
179
|
#
|
215
180
|
# method_missing used to be the lynchpin in Markaby, but it's no longer used to handle
|
216
181
|
# HTML tags. See html_tag for that.
|
217
182
|
def method_missing(sym, *args, &block)
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
elsif @_helper && instance_variables_for(@_helper).include?(ivar)
|
229
|
-
@_helper.instance_variable_get(ivar)
|
230
|
-
elsif instance_methods_for(::Builder::XmlMarkup).include?(sym)
|
231
|
-
@builder.__send__(sym, *args, &block)
|
232
|
-
elsif !@tagset
|
233
|
-
tag!(sym, *args, &block)
|
234
|
-
else
|
235
|
-
super
|
183
|
+
case response_for(sym)
|
184
|
+
when :helper then @_helper.send(sym, *args, &block)
|
185
|
+
when :assigns then @assigns[sym]
|
186
|
+
when :stringy_assigns then @assigns[sym.to_s]
|
187
|
+
when :ivar then instance_variable_get(ivar)
|
188
|
+
when :helper_ivar then @_helper.instance_variable_get(ivar)
|
189
|
+
when :xml_markup then @builder.__send__(sym, *args, &block)
|
190
|
+
when :tag then tag!(sym, *args, &block)
|
191
|
+
when :tagset then @tagset.handle_tag sym, self, *args, &block
|
192
|
+
else super
|
236
193
|
end
|
237
194
|
end
|
238
195
|
|
196
|
+
def response_for sym
|
197
|
+
return :helper if @_helper.respond_to?(sym, true)
|
198
|
+
return :assigns if @assigns.has_key?(sym)
|
199
|
+
return :stringy_assigns if @assigns.has_key?(sym.to_s)
|
200
|
+
return :ivar if instance_variables_for(self).include?(ivar = "@#{sym}".to_sym)
|
201
|
+
return :helper_ivar if @_helper && instance_variables_for(@_helper).include?(ivar)
|
202
|
+
return :xml_markup if instance_methods_for(::Builder::XmlMarkup).include?(sym)
|
203
|
+
return :tag if @tagset.nil?
|
204
|
+
return :tagset if @tagset.can_handle? sym
|
205
|
+
nil
|
206
|
+
end
|
207
|
+
|
208
|
+
def respond_to_missing? sym, include_private = false
|
209
|
+
!response_for(sym).nil?
|
210
|
+
end
|
211
|
+
|
239
212
|
if RUBY_VERSION_ID >= 191
|
240
213
|
def instance_variables_for(obj)
|
241
214
|
obj.instance_variables
|
@@ -282,11 +255,15 @@ module Markaby
|
|
282
255
|
undef_method method if method_defined?(method)
|
283
256
|
end
|
284
257
|
|
285
|
-
|
258
|
+
private
|
286
259
|
|
287
|
-
def method_missing(
|
260
|
+
def method_missing(...)
|
288
261
|
transform_stream unless transformed_stream?
|
289
|
-
@str.__send__(
|
262
|
+
@str.__send__(...)
|
263
|
+
end
|
264
|
+
|
265
|
+
def respond_to_missing? sym, *args
|
266
|
+
@str.respond_to? sym
|
290
267
|
end
|
291
268
|
|
292
269
|
def transform_stream
|