fira 0.5.1 → 0.5.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.
- data/README.md +13 -3
- data/lib/fira/engine.rb +16 -9
- data/lib/fira/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
Fira adds ease-of-use functionality to HTML files.
|
6
6
|
|
7
|
-
Instead of typing id="foo" or class="foo bar"
|
7
|
+
Instead of typing `id="foo"` or `class="foo bar"`, you can simply type `#foo` or `.foo .bar` in HTML tags (in the normal place where you put id or class attributes)
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -29,10 +29,20 @@ Once in your Gemfile, Fira will be the default template_engine for <code>rails g
|
|
29
29
|
##Examples
|
30
30
|
|
31
31
|
###Id's
|
32
|
-
|
32
|
+
|
33
|
+
<div #my_id >
|
34
|
+
|
35
|
+
becomes
|
36
|
+
|
37
|
+
<div id="my_id" >
|
33
38
|
|
34
39
|
###Classes
|
35
|
-
|
40
|
+
|
41
|
+
<div .multiple .classes >
|
42
|
+
|
43
|
+
becomes
|
44
|
+
|
45
|
+
<div class='multiple classes' >
|
36
46
|
|
37
47
|
## Contributing
|
38
48
|
|
data/lib/fira/engine.rb
CHANGED
@@ -8,14 +8,16 @@ module Fira
|
|
8
8
|
ID_REGEX = / #([^0-9][a-z_A-Z0-9_\-]+)/
|
9
9
|
CLASS_REGEX = / \.([^0-9][a-z_A-Z0-9_\-]+)/
|
10
10
|
QUOTE_REGEX = /\S+=["']?(?:.(?!["']?\s+(?:\S+)=|[>"']))+.["']?/
|
11
|
+
TAG_OPEN_REGEX = /<[^\/%]\w* /
|
11
12
|
TAG_END_REGEX = /([\/]?>)/
|
12
13
|
|
13
14
|
def parse_text(text)
|
14
15
|
output = ""
|
15
16
|
tokenizer = HTML::Tokenizer.new(text)
|
16
17
|
while token = tokenizer.next
|
18
|
+
|
17
19
|
#if it's an opening tag, analyze it
|
18
|
-
if token
|
20
|
+
if is_opening_tag?(token)
|
19
21
|
|
20
22
|
#remove any quotes
|
21
23
|
quotes = token.scan(QUOTE_REGEX)
|
@@ -28,22 +30,22 @@ module Fira
|
|
28
30
|
classes = result.scan(CLASS_REGEX)
|
29
31
|
|
30
32
|
if ! classes.empty?
|
31
|
-
|
33
|
+
|
32
34
|
#build an HTML class attribute
|
33
35
|
att = 'class="'
|
34
|
-
|
36
|
+
|
35
37
|
classes.each do |cl|
|
36
38
|
att += " #{cl[0]}"
|
37
39
|
end
|
38
|
-
|
40
|
+
|
39
41
|
att += '"'
|
40
|
-
|
42
|
+
|
41
43
|
#remove the space before the first class
|
42
44
|
att = att.sub(/class=" /, ' class="')
|
43
45
|
|
44
46
|
#remove the first fira class attribute
|
45
47
|
new_tag = result.sub(CLASS_REGEX, att)
|
46
|
-
|
48
|
+
|
47
49
|
#remove the rest of the fira class attributes
|
48
50
|
final_result = new_tag.gsub(CLASS_REGEX, "")
|
49
51
|
|
@@ -53,7 +55,7 @@ module Fira
|
|
53
55
|
#add back in the quotes
|
54
56
|
final = insert_quotes(quotes, result)
|
55
57
|
end
|
56
|
-
|
58
|
+
|
57
59
|
output += final
|
58
60
|
|
59
61
|
else
|
@@ -70,7 +72,12 @@ module Fira
|
|
70
72
|
quotes = _quotes.join(" ")
|
71
73
|
tag.sub(TAG_END_REGEX, space + quotes + '\1')
|
72
74
|
end
|
73
|
-
|
74
|
-
|
75
|
+
|
76
|
+
def is_opening_tag?(text)
|
77
|
+
val = text =~ TAG_OPEN_REGEX
|
78
|
+
val ? true : false
|
79
|
+
end
|
80
|
+
|
81
|
+
|
75
82
|
end
|
76
83
|
end
|
data/lib/fira/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fira
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|