huml 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Changes +6 -0
- data/README.md +64 -2
- data/lib/huml.rb +13 -1
- data/lib/huml/parser.treetop +7 -3
- data/lib/huml/version.rb +1 -1
- data/spec/huml/engine_spec.rb +9 -0
- data/spec/huml/parser_spec.rb +28 -11
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60f2da52abfd05442289f852c80db11b7153e8df
|
4
|
+
data.tar.gz: 1a2ab5f644d1da8f20f48e4713c8a5ff1e1c6b15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4ee88977c23a2e7e01261c4deb31724edd5b904d4974ab616ae519adca9bdf5d79123a9421f7e555013a66b67447d3c90597dd6b0721fcddc69795db7bb023d
|
7
|
+
data.tar.gz: cee05c180b9e031e86074df920dbe079c9d70ff77a486e46d364dbb111f8b79805aed0a5388fff4053cbb25d15e4e0b4d54c04ed813f578ba1bb0b8fd67a8101
|
data/.gitignore
CHANGED
data/Changes
ADDED
data/README.md
CHANGED
@@ -1,23 +1,85 @@
|
|
1
1
|
# Huml
|
2
2
|
|
3
|
-
Huml is
|
3
|
+
Huml is to [Haml](github.com/haml/haml) what [Scss](http://sass-lang.com/) is to [Sass](http://sass-lang.com/).
|
4
4
|
Like the relationship between Sass and Scss, Huml uses braces for nesting structure
|
5
5
|
when Haml uses indentations.
|
6
6
|
|
7
|
+
## Basic Usage
|
8
|
+
|
9
|
+
Huml can be used from the command line or as part of a Ruby web framework. The first step is to install the gem:
|
10
|
+
|
11
|
+
gem install huml
|
12
|
+
|
13
|
+
After writing some Huml, you can run
|
14
|
+
|
15
|
+
huml document.huml
|
16
|
+
|
17
|
+
to compile it to HTML.
|
18
|
+
|
7
19
|
## Formatting
|
8
20
|
|
21
|
+
The most basic element of Huml is a similar to Haml.
|
22
|
+
|
23
|
+
%tagname(attr1='value1' attr2='value2') = 'Content'
|
24
|
+
|
25
|
+
Adding `class` and `id` attributes uses the same syntax as the CSS too.
|
26
|
+
|
27
|
+
%tagname#id.class
|
28
|
+
|
29
|
+
If the element contains inner elements, you can use curly brace to wrap it
|
30
|
+
|
31
|
+
%ul {
|
32
|
+
%li = 'Salt'
|
33
|
+
%li = 'Pepper'
|
34
|
+
}
|
35
|
+
|
36
|
+
becomes
|
37
|
+
|
38
|
+
<ul>
|
39
|
+
<li>Salt</li>
|
40
|
+
<li>Pepper</li>
|
41
|
+
</ul>
|
42
|
+
|
43
|
+
You can also put plain text as a child of an element:
|
44
|
+
|
45
|
+
%p {
|
46
|
+
'Hello,'
|
47
|
+
'World!'
|
48
|
+
}
|
49
|
+
|
50
|
+
It's also possible to embed Ruby code into Haml documents. A hyphen, `-`, will run the code but not output the result.
|
51
|
+
You can even use control statements like if and while:
|
52
|
+
|
53
|
+
%p {
|
54
|
+
'Date/Time:'
|
55
|
+
- now = DateTime.now
|
56
|
+
%strong = "#{now}"
|
57
|
+
|
58
|
+
- if now > DateTime.parse("December 31, 2006")
|
59
|
+
'Happy new year!'
|
60
|
+
- end
|
61
|
+
}
|
62
|
+
|
63
|
+
## An Example
|
64
|
+
|
9
65
|
doctype 5
|
10
66
|
%html {
|
11
67
|
|
12
68
|
%head {
|
13
69
|
%script(type="text/javascript" src="app.js")
|
14
|
-
%link(rel="stylesheet" type="text/css" media="all")
|
70
|
+
%link(href="app.css" rel="stylesheet" type="text/css" media="all")
|
15
71
|
}
|
16
72
|
|
17
73
|
%body {
|
18
74
|
%div.container {
|
19
75
|
%h3.header = "page header"
|
20
76
|
%p(style="background-color: #fff;") = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
|
77
|
+
|
78
|
+
- for item in %w(hello world) do
|
79
|
+
%div = "interpolate #{item} here"
|
80
|
+
- end
|
81
|
+
|
82
|
+
"plain text is eligible"
|
21
83
|
}
|
22
84
|
}
|
23
85
|
|
data/lib/huml.rb
CHANGED
@@ -87,9 +87,21 @@ module Huml
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
-
class
|
90
|
+
class Dynamic < Treetop::Runtime::SyntaxNode
|
91
|
+
def tokenize
|
92
|
+
[:dynamic, "\"#{literal.text_value}\""]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class Static < Treetop::Runtime::SyntaxNode
|
91
97
|
def tokenize
|
92
98
|
[:static, literal.text_value]
|
93
99
|
end
|
94
100
|
end
|
101
|
+
|
102
|
+
class Code < Treetop::Runtime::SyntaxNode
|
103
|
+
def tokenize
|
104
|
+
[:code, code.text_value]
|
105
|
+
end
|
106
|
+
end
|
95
107
|
end
|
data/lib/huml/parser.treetop
CHANGED
@@ -33,13 +33,17 @@ grammar Huml
|
|
33
33
|
end
|
34
34
|
|
35
35
|
rule html
|
36
|
-
block* <HTML>
|
36
|
+
( block / string / code )* <HTML>
|
37
37
|
end
|
38
38
|
|
39
39
|
rule string
|
40
|
-
'"' literal:([
|
40
|
+
'"' literal:([^"]*) '"' space <Dynamic>
|
41
41
|
/
|
42
|
-
"'" literal:([
|
42
|
+
"'" literal:([^']*) "'" space <Static>
|
43
|
+
end
|
44
|
+
|
45
|
+
rule code
|
46
|
+
space "-" space code:([^\n]*) [\r\n] space <Code>
|
43
47
|
end
|
44
48
|
|
45
49
|
end
|
data/lib/huml/version.rb
CHANGED
data/spec/huml/engine_spec.rb
CHANGED
@@ -10,4 +10,13 @@ describe Huml::Engine do
|
|
10
10
|
it "outputs a divider with its content" do
|
11
11
|
expect(eval(subject.call("%div = 'content'"))).to eq("<div>\n content\n</div>")
|
12
12
|
end
|
13
|
+
|
14
|
+
it "interpolates for dynamic strings" do
|
15
|
+
expect(eval(Huml::Engine.new.call("'\#{var}'"))).to eq("\#{var}")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "doesn't interpolate for static strings" do
|
19
|
+
var = "hello"
|
20
|
+
expect(eval(Huml::Engine.new.call("\"\#{var}\""))).to eq("hello")
|
21
|
+
end
|
13
22
|
end
|
data/spec/huml/parser_spec.rb
CHANGED
@@ -64,49 +64,53 @@ describe Huml::Parser do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
it "recognizes a literal string" do
|
67
|
-
expect(subject.parse('"hello world"', root: :string).tokenize).to eq([:
|
67
|
+
expect(subject.parse('"hello world"', root: :string).tokenize).to eq([:dynamic, '"hello world"'])
|
68
68
|
expect(subject.parse("'hello world'", root: :string).tokenize).to eq([:static, "hello world"])
|
69
69
|
end
|
70
70
|
|
71
71
|
it "recognizes string composed of characters with hyphen" do
|
72
|
-
expect(subject.parse('
|
72
|
+
expect(subject.parse("'col-xs-6'", root: :string).tokenize).to eq([:static, "col-xs-6"])
|
73
73
|
end
|
74
74
|
|
75
75
|
it "recognizes string composed of characters with underscore" do
|
76
|
-
expect(subject.parse('
|
76
|
+
expect(subject.parse("'foo_bar'", root: :string).tokenize).to eq([:static, "foo_bar"])
|
77
|
+
end
|
78
|
+
|
79
|
+
it "recognizes UTF-8 characters" do
|
80
|
+
expect(subject.parse("'中文嘛也通'", root: :string).tokenize).to eq([:static, "中文嘛也通"])
|
77
81
|
end
|
78
82
|
|
79
83
|
it "recognizes a fragment of css" do
|
80
|
-
expect(subject.parse('"background-color: #fff;"
|
84
|
+
expect(subject.parse("'background-color: #fff;'", root: :string).tokenize).to eq([:static, "background-color: #fff;"])
|
81
85
|
end
|
82
86
|
|
83
87
|
it "recognizes a block containing a string" do
|
84
|
-
expect(subject.parse(
|
88
|
+
expect(subject.parse("%div = 'string here'", root: :block).tokenize).to eq([:html, :tag, :div, [:html, :attrs], [:static, "string here"]])
|
85
89
|
end
|
86
90
|
|
87
91
|
it "recognizes a pair" do
|
88
|
-
expect(subject.parse(
|
92
|
+
expect(subject.parse("src = 'foo.png'", root: :pair).tokenize).to eq([:html, :attr, :src, [:static, "foo.png"]])
|
89
93
|
end
|
90
94
|
|
91
95
|
it "recognizes attributes" do
|
92
|
-
expect(subject.parse(
|
96
|
+
expect(subject.parse("( src = 'foo.png' alt = 'foo image' )", root: :attributes).tokenize).to eq([[:html, :attr, :src, [:static, "foo.png"]], [:html, :attr, :alt, [:static, "foo image"]]])
|
93
97
|
end
|
94
98
|
|
95
99
|
it "recognizes a block with attributes" do
|
96
|
-
expect(subject.parse(
|
100
|
+
expect(subject.parse("%div(class='foo') {}", root: :block).tokenize).to eq([:html, :tag, :div, [:html, :attrs, [:html, :attr, :class, [:static, "foo"]]], [:multi]])
|
97
101
|
end
|
98
102
|
|
99
103
|
it "recognizes a assignment with attributes" do
|
100
|
-
expect(subject.parse(
|
104
|
+
expect(subject.parse("%div(class='foo') = 'string here'", root: :block).tokenize).to eq([:html, :tag, :div, [:html, :attrs, [:html, :attr, :class, [:static, "foo"]]], [:static, "string here"]])
|
101
105
|
end
|
102
106
|
|
103
107
|
it "recognizes a atomic element" do
|
104
108
|
expect(subject.parse('%div', root: :block).tokenize).to eq([:html, :tag, :div, [:html, :attrs]])
|
105
109
|
expect(subject.parse('%div()', root: :block).tokenize).to eq([:html, :tag, :div, [:html, :attrs]])
|
106
|
-
expect(subject.parse(
|
110
|
+
expect(subject.parse("%div(class='foo')", root: :block).tokenize).to eq([:html, :tag, :div,
|
107
111
|
[:html, :attrs,
|
108
112
|
[:html, :attr, :class, [:static, "foo"]]]])
|
109
|
-
expect(subject.parse(
|
113
|
+
expect(subject.parse("%div.foo#bar(role='sidebar')", root: :block).tokenize).to eq([:html, :tag, :div,
|
110
114
|
[:html, :attrs,
|
111
115
|
[:html, :attr, :class, [:static, "foo"]],
|
112
116
|
[:html, :attr, :id, [:static, "bar"]],
|
@@ -116,4 +120,17 @@ describe Huml::Parser do
|
|
116
120
|
it "recognizes multiple atomic elements" do
|
117
121
|
expect(subject.parse("%div()\n%div()", root: :html).tokenize).to eq([[:html, :tag, :div, [:html, :attrs]], [:html, :tag, :div, [:html, :attrs]]])
|
118
122
|
end
|
123
|
+
|
124
|
+
it "recognizes code" do
|
125
|
+
expect(subject.parse(" - @var.each do |item| \n", root: :code).tokenize).to eq([:code, "@var.each do |item| "])
|
126
|
+
end
|
127
|
+
|
128
|
+
it "recognizes embeded code" do
|
129
|
+
template = <<TEMPLATE
|
130
|
+
- @var.each do |item|
|
131
|
+
"variable #\{item\} here.\n"
|
132
|
+
- end
|
133
|
+
TEMPLATE
|
134
|
+
expect(subject.parse(template, root: :html).tokenize).to eq([[:code, '@var.each do |item|'], [:dynamic, "\"variable \#{item} here.\n\""], [:code, 'end']])
|
135
|
+
end
|
119
136
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: huml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shelling
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: temple
|
@@ -75,12 +75,14 @@ extensions: []
|
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
77
|
- .gitignore
|
78
|
+
- Changes
|
78
79
|
- Gemfile
|
79
80
|
- Gemfile.lock
|
80
81
|
- README.md
|
81
82
|
- Rakefile
|
82
83
|
- bin/huml
|
83
84
|
- examples/simple.huml
|
85
|
+
- examples/string.huml
|
84
86
|
- huml.gemspec
|
85
87
|
- lib/huml.rb
|
86
88
|
- lib/huml/engine.rb
|