hexp 0.0.1.pre
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/.gitignore +18 -0
- data/.travis.yml +19 -0
- data/Gemfile +7 -0
- data/Gemfile.devtools +60 -0
- data/Gemfile.lock +169 -0
- data/README.md +16 -0
- data/Rakefile +13 -0
- data/SPEC.md +53 -0
- data/config/flay.yml +3 -0
- data/config/flog.yml +2 -0
- data/config/mutant.yml +2 -0
- data/config/reek.yml +100 -0
- data/config/yardstick.yml +2 -0
- data/hexp.gemspec +20 -0
- data/lib/hexp.rb +5 -0
- data/lib/hexp/array.rb +43 -0
- data/lib/hexp/version.rb +3 -0
- data/spec/shared_helper.rb +1 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/unit/hexp/array_spec.rb +61 -0
- metadata +88 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
language: ruby
|
|
2
|
+
before_install: gem install bundler
|
|
3
|
+
bundler_args: --without yard guard benchmarks
|
|
4
|
+
script: "bundle exec rake ci:metrics"
|
|
5
|
+
rvm:
|
|
6
|
+
- ree
|
|
7
|
+
- 1.9.2
|
|
8
|
+
- 1.9.3
|
|
9
|
+
- 2.0.0
|
|
10
|
+
- ruby-head
|
|
11
|
+
- rbx-19mode
|
|
12
|
+
- jruby-19mode
|
|
13
|
+
- jruby-head
|
|
14
|
+
notifications:
|
|
15
|
+
email:
|
|
16
|
+
recipients:
|
|
17
|
+
- arne@arnebrasseur.net
|
|
18
|
+
on_success: never
|
|
19
|
+
on_failure: change
|
data/Gemfile
ADDED
data/Gemfile.devtools
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
group :development do
|
|
4
|
+
gem 'rake', '~> 10.0.4'
|
|
5
|
+
gem 'rspec', '~> 2.13.0'
|
|
6
|
+
gem 'yard', '~> 0.8.6.1'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
group :yard do
|
|
10
|
+
gem 'kramdown', '~> 1.0.1'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
group :guard do
|
|
14
|
+
gem 'guard', '~> 1.8.0'
|
|
15
|
+
gem 'guard-bundler', '~> 1.0.0'
|
|
16
|
+
gem 'guard-rspec', '~> 2.5.4'
|
|
17
|
+
|
|
18
|
+
# file system change event handling
|
|
19
|
+
gem 'listen', '~> 1.0.2'
|
|
20
|
+
gem 'rb-fchange', '~> 0.0.6', :require => false
|
|
21
|
+
gem 'rb-fsevent', '~> 0.9.3', :require => false
|
|
22
|
+
gem 'rb-inotify', '~> 0.9.0', :require => false
|
|
23
|
+
|
|
24
|
+
# notification handling
|
|
25
|
+
gem 'libnotify', '~> 0.8.0', :require => false
|
|
26
|
+
gem 'rb-notifu', '~> 0.0.4', :require => false
|
|
27
|
+
gem 'terminal-notifier-guard', '~> 1.5.3', :require => false
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
group :metrics do
|
|
31
|
+
gem 'backports', '~> 3.3', '>= 3.3.0'
|
|
32
|
+
gem 'coveralls', '~> 0.6.6'
|
|
33
|
+
gem 'flay', '~> 2.2.0'
|
|
34
|
+
gem 'flog', '~> 4.0.0'
|
|
35
|
+
gem 'reek', '~> 1.3.1', :git => 'https://github.com/troessner/reek.git'
|
|
36
|
+
gem 'simplecov', '~> 0.7.1'
|
|
37
|
+
gem 'yardstick', '~> 0.9.6'
|
|
38
|
+
|
|
39
|
+
platforms :ruby_19 do
|
|
40
|
+
gem 'yard-spellcheck', '~> 0.1.5'
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
platforms :mri_19, :rbx do
|
|
44
|
+
gem 'mutant', '~> 0.2.20'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
platforms :rbx do
|
|
48
|
+
gem 'pelusa', '~> 0.2.2'
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
group :benchmarks do
|
|
53
|
+
gem 'rbench', '~> 0.2.3'
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
platform :jruby do
|
|
57
|
+
group :jruby do
|
|
58
|
+
gem 'jruby-openssl', '~> 0.8.5'
|
|
59
|
+
end
|
|
60
|
+
end
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
GIT
|
|
2
|
+
remote: https://github.com/datamapper/devtools.git
|
|
3
|
+
revision: f0e3a3a42673266c46b983bc79a4ab6e1623bccc
|
|
4
|
+
specs:
|
|
5
|
+
devtools (0.0.1)
|
|
6
|
+
ice_nine (~> 0.7.0)
|
|
7
|
+
|
|
8
|
+
GIT
|
|
9
|
+
remote: https://github.com/troessner/reek.git
|
|
10
|
+
revision: 79e1b9bb5400d5aba172cbab5e65531daab24b3e
|
|
11
|
+
specs:
|
|
12
|
+
reek (1.3.1)
|
|
13
|
+
ruby2ruby (~> 2.0.2)
|
|
14
|
+
ruby_parser (~> 3.1.1)
|
|
15
|
+
sexp_processor
|
|
16
|
+
|
|
17
|
+
GEM
|
|
18
|
+
remote: https://rubygems.org/
|
|
19
|
+
specs:
|
|
20
|
+
abstract_type (0.0.5)
|
|
21
|
+
backports (~> 3.0, >= 3.0.3)
|
|
22
|
+
adamantium (0.0.7)
|
|
23
|
+
backports (~> 3.0, >= 3.0.3)
|
|
24
|
+
ice_nine (~> 0.7.0)
|
|
25
|
+
backports (3.3.1)
|
|
26
|
+
coderay (1.0.9)
|
|
27
|
+
colorize (0.5.8)
|
|
28
|
+
coveralls (0.6.7)
|
|
29
|
+
colorize
|
|
30
|
+
multi_json (~> 1.3)
|
|
31
|
+
rest-client
|
|
32
|
+
simplecov (>= 0.7)
|
|
33
|
+
thor
|
|
34
|
+
descendants_tracker (0.0.1)
|
|
35
|
+
diff-lcs (1.2.4)
|
|
36
|
+
equalizer (0.0.5)
|
|
37
|
+
adamantium (~> 0.0.6)
|
|
38
|
+
backports (~> 3.0, >= 3.0.3)
|
|
39
|
+
ffi (1.8.1)
|
|
40
|
+
ffi-hunspell (0.3.0)
|
|
41
|
+
ffi (~> 1.0)
|
|
42
|
+
flay (2.2.0)
|
|
43
|
+
ruby_parser (~> 3.0)
|
|
44
|
+
sexp_processor (~> 4.0)
|
|
45
|
+
flog (4.0.0)
|
|
46
|
+
ruby_parser (~> 3.1, > 3.1.0)
|
|
47
|
+
sexp_processor (~> 4.0)
|
|
48
|
+
formatador (0.2.4)
|
|
49
|
+
guard (1.8.0)
|
|
50
|
+
formatador (>= 0.2.4)
|
|
51
|
+
listen (>= 1.0.0)
|
|
52
|
+
lumberjack (>= 1.0.2)
|
|
53
|
+
pry (>= 0.9.10)
|
|
54
|
+
thor (>= 0.14.6)
|
|
55
|
+
guard-bundler (1.0.0)
|
|
56
|
+
bundler (~> 1.0)
|
|
57
|
+
guard (~> 1.1)
|
|
58
|
+
guard-rspec (2.5.4)
|
|
59
|
+
guard (>= 1.1)
|
|
60
|
+
rspec (~> 2.11)
|
|
61
|
+
ice_nine (0.7.0)
|
|
62
|
+
inflecto (0.0.2)
|
|
63
|
+
json (1.7.7)
|
|
64
|
+
kramdown (1.0.2)
|
|
65
|
+
libnotify (0.8.0)
|
|
66
|
+
ffi (>= 1.0.11)
|
|
67
|
+
listen (1.0.3)
|
|
68
|
+
rb-fsevent (>= 0.9.3)
|
|
69
|
+
rb-inotify (>= 0.9)
|
|
70
|
+
rb-kqueue (>= 0.2)
|
|
71
|
+
lumberjack (1.0.3)
|
|
72
|
+
method_source (0.8.1)
|
|
73
|
+
mime-types (1.23)
|
|
74
|
+
multi_json (1.7.3)
|
|
75
|
+
mutant (0.2.20)
|
|
76
|
+
abstract_type (~> 0.0.3)
|
|
77
|
+
adamantium (~> 0.0.7)
|
|
78
|
+
backports (~> 3.0, >= 3.0.3)
|
|
79
|
+
descendants_tracker (~> 0.0.1)
|
|
80
|
+
diff-lcs (~> 1.2.1)
|
|
81
|
+
equalizer (~> 0.0.5)
|
|
82
|
+
ice_nine (~> 0.7.0)
|
|
83
|
+
inflecto (~> 0.0.2)
|
|
84
|
+
rspec (~> 2.13.0)
|
|
85
|
+
to_source (~> 0.2.19)
|
|
86
|
+
mutant-melbourne (2.0.3)
|
|
87
|
+
pelusa (0.2.2)
|
|
88
|
+
pry (0.9.12.2)
|
|
89
|
+
coderay (~> 1.0.5)
|
|
90
|
+
method_source (~> 0.8)
|
|
91
|
+
slop (~> 3.4)
|
|
92
|
+
rake (10.0.4)
|
|
93
|
+
rb-fchange (0.0.6)
|
|
94
|
+
ffi
|
|
95
|
+
rb-fsevent (0.9.3)
|
|
96
|
+
rb-inotify (0.9.0)
|
|
97
|
+
ffi (>= 0.5.0)
|
|
98
|
+
rb-kqueue (0.2.0)
|
|
99
|
+
ffi (>= 0.5.0)
|
|
100
|
+
rb-notifu (0.0.4)
|
|
101
|
+
rbench (0.2.3)
|
|
102
|
+
rest-client (1.6.7)
|
|
103
|
+
mime-types (>= 1.16)
|
|
104
|
+
rspec (2.13.0)
|
|
105
|
+
rspec-core (~> 2.13.0)
|
|
106
|
+
rspec-expectations (~> 2.13.0)
|
|
107
|
+
rspec-mocks (~> 2.13.0)
|
|
108
|
+
rspec-core (2.13.1)
|
|
109
|
+
rspec-expectations (2.13.0)
|
|
110
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
|
111
|
+
rspec-mocks (2.13.1)
|
|
112
|
+
ruby2ruby (2.0.5)
|
|
113
|
+
ruby_parser (~> 3.1)
|
|
114
|
+
sexp_processor (~> 4.0)
|
|
115
|
+
ruby_parser (3.1.3)
|
|
116
|
+
sexp_processor (~> 4.1)
|
|
117
|
+
sexp_processor (4.2.1)
|
|
118
|
+
simplecov (0.7.1)
|
|
119
|
+
multi_json (~> 1.0)
|
|
120
|
+
simplecov-html (~> 0.7.1)
|
|
121
|
+
simplecov-html (0.7.1)
|
|
122
|
+
slop (3.4.5)
|
|
123
|
+
terminal-notifier-guard (1.5.3)
|
|
124
|
+
thor (0.18.1)
|
|
125
|
+
to_source (0.2.20)
|
|
126
|
+
abstract_type (~> 0.0.5)
|
|
127
|
+
adamantium (~> 0.0.7)
|
|
128
|
+
equalizer (~> 0.0.5)
|
|
129
|
+
mutant-melbourne (~> 2.0.3)
|
|
130
|
+
yard (0.8.6.1)
|
|
131
|
+
yard-spellcheck (0.1.5)
|
|
132
|
+
ffi-hunspell (~> 0.2)
|
|
133
|
+
yard (~> 0.6)
|
|
134
|
+
yardstick (0.9.6)
|
|
135
|
+
backports (~> 3.3, >= 3.3.0)
|
|
136
|
+
yard (~> 0.8, >= 0.8.6)
|
|
137
|
+
|
|
138
|
+
PLATFORMS
|
|
139
|
+
ruby
|
|
140
|
+
|
|
141
|
+
DEPENDENCIES
|
|
142
|
+
backports (~> 3.3, >= 3.3.0)
|
|
143
|
+
coveralls (~> 0.6.6)
|
|
144
|
+
devtools!
|
|
145
|
+
flay (~> 2.2.0)
|
|
146
|
+
flog (~> 4.0.0)
|
|
147
|
+
guard (~> 1.8.0)
|
|
148
|
+
guard-bundler (~> 1.0.0)
|
|
149
|
+
guard-rspec (~> 2.5.4)
|
|
150
|
+
jruby-openssl (~> 0.8.5)
|
|
151
|
+
json (~> 1.7.7)
|
|
152
|
+
kramdown (~> 1.0.1)
|
|
153
|
+
libnotify (~> 0.8.0)
|
|
154
|
+
listen (~> 1.0.2)
|
|
155
|
+
mutant (~> 0.2.20)
|
|
156
|
+
pelusa (~> 0.2.2)
|
|
157
|
+
rake (~> 10.0.4)
|
|
158
|
+
rb-fchange (~> 0.0.6)
|
|
159
|
+
rb-fsevent (~> 0.9.3)
|
|
160
|
+
rb-inotify (~> 0.9.0)
|
|
161
|
+
rb-notifu (~> 0.0.4)
|
|
162
|
+
rbench (~> 0.2.3)
|
|
163
|
+
reek (~> 1.3.1)!
|
|
164
|
+
rspec (~> 2.13.0)
|
|
165
|
+
simplecov (~> 0.7.1)
|
|
166
|
+
terminal-notifier-guard (~> 1.5.3)
|
|
167
|
+
yard (~> 0.8.6.1)
|
|
168
|
+
yard-spellcheck (~> 0.1.5)
|
|
169
|
+
yardstick (~> 0.9.6)
|
data/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
hexp
|
|
2
|
+
====
|
|
3
|
+
|
|
4
|
+
[][gem]
|
|
5
|
+
[][travis]
|
|
6
|
+
[][gemnasium]
|
|
7
|
+
[][codeclimate]
|
|
8
|
+
[][coveralls]
|
|
9
|
+
|
|
10
|
+
[gem]: https://rubygems.org/gems/dm-mapper
|
|
11
|
+
[travis]: https://travis-ci.org/plexus/hexp
|
|
12
|
+
[gemnasium]: https://gemnasium.com/plexus/hexp
|
|
13
|
+
[codeclimate]: https://codeclimate.com/github/plexus/hexp
|
|
14
|
+
[coveralls]: https://coveralls.io/r/plexus/hexp
|
|
15
|
+
|
|
16
|
+
HTML expressions
|
data/Rakefile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'devtools'
|
|
2
|
+
require 'rubygems/package_task'
|
|
3
|
+
|
|
4
|
+
Devtools.init_rake_tasks
|
|
5
|
+
|
|
6
|
+
spec = Gem::Specification.load(File.expand_path('../hexp.gemspec', __FILE__))
|
|
7
|
+
gem = Gem::PackageTask.new(spec)
|
|
8
|
+
gem.define
|
|
9
|
+
|
|
10
|
+
desc "Push gem to rubygems.org"
|
|
11
|
+
task :push => :gem do
|
|
12
|
+
sh "gem push pkg/hexp-#{Hexp::VERSION}.gem"
|
|
13
|
+
end
|
data/SPEC.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# HTML Expressions (hexp) Specification
|
|
2
|
+
|
|
3
|
+
HTML Expressions, hexps for short, are a subset of s-expressions. They provide a convention for working with HTML data in applications in a structured fashion.
|
|
4
|
+
|
|
5
|
+
Most languages contain a DOM implementation to work with HTML/XML documents, fragments and nodes. However, generating HTML through the DOM API is verbose and tedious. A hexp implementation SHOULD implement conversions from and to DOM documents. A hexp implementation SHOULD NOT convert directly from or to HTML.
|
|
6
|
+
|
|
7
|
+
A hexp implementation MUST implement hexp normalization. Several shorthands are provided for the convenience of the programmer when entering literal hexps. These non-strict hexps should be normalized to strict hexps before further manipulation.
|
|
8
|
+
|
|
9
|
+
## Strict hexps
|
|
10
|
+
|
|
11
|
+
A strict hexp is a triplet, it represents a single HTML node. The first element is the tag name, the second a dictionary of attributes, the third is a list of child nodes.
|
|
12
|
+
|
|
13
|
+
If the language implements the concept of a symbol (interned string), the tag name MUST BE a symbol. Otherwise it will be represented as a regular string.
|
|
14
|
+
|
|
15
|
+
The attributes are represented in a dictionary (hash), with both keys and values being strings.
|
|
16
|
+
|
|
17
|
+
The list of child nodes is a list (array) of other hexps or strings, the latter representing text nodes in the corresponding DOM.
|
|
18
|
+
|
|
19
|
+
An example in Ruby of a strict hexp :
|
|
20
|
+
|
|
21
|
+
````ruby
|
|
22
|
+
[:div, {'class': 'hexp-example'}, [
|
|
23
|
+
[:p, {}, "Hello, world"]
|
|
24
|
+
]
|
|
25
|
+
]
|
|
26
|
+
````
|
|
27
|
+
|
|
28
|
+
A normalized hexp MUST be made immutable (frozen, persistent) if the runtime supports it. Operations that alter a hexp MUST return a new hexp values, rather than changing the hexp value in-place.
|
|
29
|
+
|
|
30
|
+
## Non-strict hexps
|
|
31
|
+
|
|
32
|
+
Following simplifications are allowed for entering literal hexps, the implementation MUST provide a mechanism for converting these to strict hexps.
|
|
33
|
+
|
|
34
|
+
````ruby
|
|
35
|
+
# non-strict -> strict
|
|
36
|
+
[:p] -> [:p, {}, []]
|
|
37
|
+
[:p, {'class' => 'foo'}] -> [:p, {'class' => 'foo'}, []]
|
|
38
|
+
[:p, ['hello,', [:br], 'world'] -> [:p, {}, ['hello,', [:br, {}, []], 'world']
|
|
39
|
+
````
|
|
40
|
+
|
|
41
|
+
### Omitting attributes or children
|
|
42
|
+
|
|
43
|
+
If the dictionary of attributes is empty, it may be omitted.
|
|
44
|
+
|
|
45
|
+
If the list of children is empty, it may be omitted.
|
|
46
|
+
|
|
47
|
+
### A single text node as child
|
|
48
|
+
|
|
49
|
+
If the represented node its only child is a text node, a single string may be given rather than a list of children. An example would be `<p>Hello, world</p>`, this can be represented as `[:p, "Hello, world"]`, which would be normalized to `[:p, {}, ["Hello, world"]]`.
|
|
50
|
+
|
|
51
|
+
### Standard coercion protocol
|
|
52
|
+
|
|
53
|
+
In a dynamically typed object-oriented language, a convention may be set for a protocol that objects can implement to return a strict hexp representation of themselves. For Ruby this will be the `to_hexp` method. In the list of children, objects can be added that implement `to_hexp`. The normalization procedure must detect that the object implements this method, and add the resulting hexps to the list of children.
|
data/config/flay.yml
ADDED
data/config/flog.yml
ADDED
data/config/mutant.yml
ADDED
data/config/reek.yml
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
---
|
|
2
|
+
Attribute:
|
|
3
|
+
enabled: true
|
|
4
|
+
exclude: []
|
|
5
|
+
BooleanParameter:
|
|
6
|
+
enabled: true
|
|
7
|
+
exclude: []
|
|
8
|
+
ClassVariable:
|
|
9
|
+
enabled: true
|
|
10
|
+
exclude: []
|
|
11
|
+
ControlParameter:
|
|
12
|
+
enabled: true
|
|
13
|
+
exclude: []
|
|
14
|
+
DataClump:
|
|
15
|
+
enabled: true
|
|
16
|
+
exclude: []
|
|
17
|
+
max_copies: 0
|
|
18
|
+
min_clump_size: 1
|
|
19
|
+
DuplicateMethodCall:
|
|
20
|
+
enabled: true
|
|
21
|
+
exclude: []
|
|
22
|
+
max_calls: 1
|
|
23
|
+
allow_calls: []
|
|
24
|
+
FeatureEnvy:
|
|
25
|
+
enabled: true
|
|
26
|
+
exclude: []
|
|
27
|
+
IrresponsibleModule:
|
|
28
|
+
enabled: true
|
|
29
|
+
exclude: []
|
|
30
|
+
LongParameterList:
|
|
31
|
+
enabled: true
|
|
32
|
+
exclude: []
|
|
33
|
+
max_params: 1
|
|
34
|
+
overrides: {}
|
|
35
|
+
LongYieldList:
|
|
36
|
+
enabled: true
|
|
37
|
+
exclude: []
|
|
38
|
+
max_params: 0
|
|
39
|
+
NestedIterators:
|
|
40
|
+
enabled: true
|
|
41
|
+
exclude: []
|
|
42
|
+
max_allowed_nesting: 1
|
|
43
|
+
ignore_iterators: []
|
|
44
|
+
NilCheck:
|
|
45
|
+
enabled: true
|
|
46
|
+
exclude: []
|
|
47
|
+
RepeatedConditional:
|
|
48
|
+
enabled: true
|
|
49
|
+
exclude: []
|
|
50
|
+
max_ifs: 1
|
|
51
|
+
TooManyInstanceVariables:
|
|
52
|
+
enabled: true
|
|
53
|
+
exclude: []
|
|
54
|
+
max_instance_variables: 12
|
|
55
|
+
TooManyMethods:
|
|
56
|
+
enabled: true
|
|
57
|
+
exclude: []
|
|
58
|
+
max_methods: 15
|
|
59
|
+
TooManyStatements:
|
|
60
|
+
enabled: true
|
|
61
|
+
exclude: []
|
|
62
|
+
max_statements: 5
|
|
63
|
+
UncommunicativeMethodName:
|
|
64
|
+
enabled: true
|
|
65
|
+
exclude: []
|
|
66
|
+
reject:
|
|
67
|
+
- !ruby/regexp /^[a-z]$/
|
|
68
|
+
- !ruby/regexp /[0-9]$/
|
|
69
|
+
- !ruby/regexp /[A-Z]/
|
|
70
|
+
accept: []
|
|
71
|
+
UncommunicativeModuleName:
|
|
72
|
+
enabled: true
|
|
73
|
+
exclude: []
|
|
74
|
+
reject:
|
|
75
|
+
- !ruby/regexp /^.$/
|
|
76
|
+
- !ruby/regexp /[0-9]$/
|
|
77
|
+
accept: []
|
|
78
|
+
UncommunicativeParameterName:
|
|
79
|
+
enabled: true
|
|
80
|
+
exclude: []
|
|
81
|
+
reject:
|
|
82
|
+
- !ruby/regexp /^.$/
|
|
83
|
+
- !ruby/regexp /[0-9]$/
|
|
84
|
+
- !ruby/regexp /[A-Z]/
|
|
85
|
+
accept: []
|
|
86
|
+
UncommunicativeVariableName:
|
|
87
|
+
enabled: true
|
|
88
|
+
exclude: []
|
|
89
|
+
reject:
|
|
90
|
+
- !ruby/regexp /^.$/
|
|
91
|
+
- !ruby/regexp /[0-9]$/
|
|
92
|
+
- !ruby/regexp /[A-Z]/
|
|
93
|
+
accept: []
|
|
94
|
+
UnusedParameters:
|
|
95
|
+
enabled: true
|
|
96
|
+
exclude: []
|
|
97
|
+
UtilityFunction:
|
|
98
|
+
enabled: true
|
|
99
|
+
exclude: []
|
|
100
|
+
max_helper_calls: 0
|
data/hexp.gemspec
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require File.expand_path('../lib/hexp/version', __FILE__)
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |gem|
|
|
6
|
+
gem.name = 'hexp'
|
|
7
|
+
gem.version = Hexp::VERSION
|
|
8
|
+
gem.authors = [ 'Arne Brasseur' ]
|
|
9
|
+
gem.email = [ 'arne@arnebrasseur.net' ]
|
|
10
|
+
gem.description = 'HTML expressions'
|
|
11
|
+
gem.summary = gem.description
|
|
12
|
+
gem.homepage = 'https://github.com/plexus/hexp'
|
|
13
|
+
|
|
14
|
+
gem.require_paths = %w[lib]
|
|
15
|
+
gem.files = `git ls-files`.split($/)
|
|
16
|
+
gem.test_files = `git ls-files -- spec`.split($/)
|
|
17
|
+
gem.extra_rdoc_files = %w[README.md]
|
|
18
|
+
|
|
19
|
+
gem.add_dependency 'ice_nine', '~> 0.7.0'
|
|
20
|
+
end
|
data/lib/hexp.rb
ADDED
data/lib/hexp/array.rb
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module Hexp
|
|
2
|
+
class Array < ::Array
|
|
3
|
+
def self.[](*args)
|
|
4
|
+
super(*normalize(args))
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.normalize(args)
|
|
8
|
+
idx = 0
|
|
9
|
+
case args[idx]
|
|
10
|
+
when Symbol
|
|
11
|
+
tag = args[idx] ; idx+=1
|
|
12
|
+
attrs = case args[idx]
|
|
13
|
+
when Hash
|
|
14
|
+
idx += 1 ; args[idx-1]
|
|
15
|
+
else
|
|
16
|
+
{}
|
|
17
|
+
end
|
|
18
|
+
children = normalize_children args[idx]
|
|
19
|
+
[tag, attrs, children]
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.normalize_children(children)
|
|
24
|
+
case children
|
|
25
|
+
when String
|
|
26
|
+
[ children ]
|
|
27
|
+
when ::Array
|
|
28
|
+
children.map do |child|
|
|
29
|
+
case child
|
|
30
|
+
when String
|
|
31
|
+
child
|
|
32
|
+
when ::Array
|
|
33
|
+
Hexp::Array[*child]
|
|
34
|
+
else
|
|
35
|
+
raise "bad input #{child}"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
else
|
|
39
|
+
[]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
data/lib/hexp/version.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'hexp'
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
# SimpleCov MUST be started before require 'hexp'
|
|
4
|
+
#
|
|
5
|
+
if ENV['COVERAGE'] == 'true'
|
|
6
|
+
require 'simplecov'
|
|
7
|
+
require 'coveralls'
|
|
8
|
+
|
|
9
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
|
10
|
+
SimpleCov::Formatter::HTMLFormatter,
|
|
11
|
+
Coveralls::SimpleCov::Formatter
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
SimpleCov.start do
|
|
15
|
+
command_name 'spec:unit'
|
|
16
|
+
|
|
17
|
+
# add_filter 'config'
|
|
18
|
+
|
|
19
|
+
# add_group 'Finalizer', 'lib/data_mapper/finalizer'
|
|
20
|
+
|
|
21
|
+
minimum_coverage 98.10 # 0.10 lower under JRuby
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
require 'shared_helper' # requires hexp
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
H=Hexp::Array
|
|
4
|
+
|
|
5
|
+
describe Hexp::Array do
|
|
6
|
+
describe 'normalization' do
|
|
7
|
+
describe 'with a single parameter' do
|
|
8
|
+
it 'should return a triplet' do
|
|
9
|
+
H[:div].count.should == 3
|
|
10
|
+
end
|
|
11
|
+
it 'should treat the first as the tag' do
|
|
12
|
+
H[:div][0].should == :div
|
|
13
|
+
end
|
|
14
|
+
it 'should set an empty attribute list' do
|
|
15
|
+
H[:div][1].should == {}
|
|
16
|
+
end
|
|
17
|
+
it 'should set an empty children list' do
|
|
18
|
+
H[:div][2].should == []
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe 'with two parameters' do
|
|
23
|
+
it 'should treat the first as the tag' do
|
|
24
|
+
H[:div, {class: 'foo'}][0].should == :div
|
|
25
|
+
end
|
|
26
|
+
it 'should treat the second as the attribute list, if it is a Hash' do
|
|
27
|
+
H[:div, {class: 'foo'}][1].should == {class: 'foo'}
|
|
28
|
+
end
|
|
29
|
+
it 'should treat the second as a list of children, if it is an Array' do
|
|
30
|
+
H[:div, []][2].should == []
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe 'with a single text child node' do
|
|
35
|
+
it 'should set is as the single child' do
|
|
36
|
+
H[:div, "this is text in the div"][2].should == ["this is text in the div"]
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe 'with child nodes' do
|
|
41
|
+
it 'must normalize them recursively' do
|
|
42
|
+
H[:div, [
|
|
43
|
+
[:h1, "Big Title"],
|
|
44
|
+
[:p, {class: 'greeting'}, "hello world"],
|
|
45
|
+
"Some loose text"
|
|
46
|
+
]
|
|
47
|
+
][2].should == [
|
|
48
|
+
[:h1, {}, ["Big Title"] ],
|
|
49
|
+
[:p, {class: 'greeting'}, ["hello world"] ],
|
|
50
|
+
"Some loose text"
|
|
51
|
+
]
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
describe 'with bad input' do
|
|
56
|
+
it 'should raise exception' do
|
|
57
|
+
expect { H[:p, {}, [123]] }.to raise_exception
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: hexp
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1.pre
|
|
5
|
+
prerelease: 6
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Arne Brasseur
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-05-23 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: ice_nine
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ~>
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 0.7.0
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ~>
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: 0.7.0
|
|
30
|
+
description: HTML expressions
|
|
31
|
+
email:
|
|
32
|
+
- arne@arnebrasseur.net
|
|
33
|
+
executables: []
|
|
34
|
+
extensions: []
|
|
35
|
+
extra_rdoc_files:
|
|
36
|
+
- README.md
|
|
37
|
+
files:
|
|
38
|
+
- .gitignore
|
|
39
|
+
- .travis.yml
|
|
40
|
+
- Gemfile
|
|
41
|
+
- Gemfile.devtools
|
|
42
|
+
- Gemfile.lock
|
|
43
|
+
- README.md
|
|
44
|
+
- Rakefile
|
|
45
|
+
- SPEC.md
|
|
46
|
+
- config/flay.yml
|
|
47
|
+
- config/flog.yml
|
|
48
|
+
- config/mutant.yml
|
|
49
|
+
- config/reek.yml
|
|
50
|
+
- config/yardstick.yml
|
|
51
|
+
- hexp.gemspec
|
|
52
|
+
- lib/hexp.rb
|
|
53
|
+
- lib/hexp/array.rb
|
|
54
|
+
- lib/hexp/version.rb
|
|
55
|
+
- spec/shared_helper.rb
|
|
56
|
+
- spec/spec_helper.rb
|
|
57
|
+
- spec/unit/hexp/array_spec.rb
|
|
58
|
+
homepage: https://github.com/plexus/hexp
|
|
59
|
+
licenses: []
|
|
60
|
+
post_install_message:
|
|
61
|
+
rdoc_options: []
|
|
62
|
+
require_paths:
|
|
63
|
+
- lib
|
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
|
+
none: false
|
|
66
|
+
requirements:
|
|
67
|
+
- - ! '>='
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
segments:
|
|
71
|
+
- 0
|
|
72
|
+
hash: -3692654222847691207
|
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
|
+
none: false
|
|
75
|
+
requirements:
|
|
76
|
+
- - ! '>'
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: 1.3.1
|
|
79
|
+
requirements: []
|
|
80
|
+
rubyforge_project:
|
|
81
|
+
rubygems_version: 1.8.23
|
|
82
|
+
signing_key:
|
|
83
|
+
specification_version: 3
|
|
84
|
+
summary: HTML expressions
|
|
85
|
+
test_files:
|
|
86
|
+
- spec/shared_helper.rb
|
|
87
|
+
- spec/spec_helper.rb
|
|
88
|
+
- spec/unit/hexp/array_spec.rb
|