fira 0.4.1 → 0.5.1
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/Rakefile +11 -0
- data/bin/fira.rb +0 -0
- data/fira.gemspec +2 -0
- data/lib/fira/engine.rb +25 -6
- data/lib/fira/helpers.rb +2 -1
- data/lib/fira/version.rb +1 -1
- metadata +20 -3
data/Rakefile
CHANGED
data/bin/fira.rb
CHANGED
File without changes
|
data/fira.gemspec
CHANGED
data/lib/fira/engine.rb
CHANGED
@@ -1,20 +1,28 @@
|
|
1
|
+
require 'action_controller'
|
2
|
+
|
1
3
|
module Fira
|
2
4
|
|
3
5
|
class Engine
|
4
6
|
|
5
7
|
|
6
|
-
ID_REGEX = / #([a-z_A-
|
7
|
-
CLASS_REGEX = / \.([a-z_A-
|
8
|
+
ID_REGEX = / #([^0-9][a-z_A-Z0-9_\-]+)/
|
9
|
+
CLASS_REGEX = / \.([^0-9][a-z_A-Z0-9_\-]+)/
|
10
|
+
QUOTE_REGEX = /\S+=["']?(?:.(?!["']?\s+(?:\S+)=|[>"']))+.["']?/
|
11
|
+
TAG_END_REGEX = /([\/]?>)/
|
8
12
|
|
9
13
|
def parse_text(text)
|
10
14
|
output = ""
|
11
15
|
tokenizer = HTML::Tokenizer.new(text)
|
12
16
|
while token = tokenizer.next
|
17
|
+
#if it's an opening tag, analyze it
|
13
18
|
if token[0] == "<" and token[token.length - 1] == ">" and token[1] != "/"
|
14
|
-
|
19
|
+
|
20
|
+
#remove any quotes
|
21
|
+
quotes = token.scan(QUOTE_REGEX)
|
22
|
+
no_quotes = token.gsub(QUOTE_REGEX, '')
|
15
23
|
|
16
24
|
#find and replace fira ID attributes
|
17
|
-
result =
|
25
|
+
result = no_quotes.sub(ID_REGEX, ' id="\1"')
|
18
26
|
|
19
27
|
#find fira class attributes
|
20
28
|
classes = result.scan(CLASS_REGEX)
|
@@ -39,10 +47,14 @@ module Fira
|
|
39
47
|
#remove the rest of the fira class attributes
|
40
48
|
final_result = new_tag.gsub(CLASS_REGEX, "")
|
41
49
|
|
42
|
-
|
50
|
+
#add back in the quotes
|
51
|
+
final = insert_quotes(quotes, final_result)
|
43
52
|
else
|
44
|
-
|
53
|
+
#add back in the quotes
|
54
|
+
final = insert_quotes(quotes, result)
|
45
55
|
end
|
56
|
+
|
57
|
+
output += final
|
46
58
|
|
47
59
|
else
|
48
60
|
output += token
|
@@ -51,6 +63,13 @@ module Fira
|
|
51
63
|
|
52
64
|
return output
|
53
65
|
end
|
66
|
+
|
67
|
+
def insert_quotes(_quotes, tag)
|
68
|
+
space = ''
|
69
|
+
space = ' ' if _quotes.length > 0
|
70
|
+
quotes = _quotes.join(" ")
|
71
|
+
tag.sub(TAG_END_REGEX, space + quotes + '\1')
|
72
|
+
end
|
54
73
|
|
55
74
|
|
56
75
|
end
|
data/lib/fira/helpers.rb
CHANGED
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.
|
4
|
+
version: 0.5.1
|
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-
|
12
|
+
date: 2013-05-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -77,6 +77,22 @@ dependencies:
|
|
77
77
|
- - <
|
78
78
|
- !ruby/object:Gem::Version
|
79
79
|
version: '4.1'
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rspec
|
82
|
+
requirement: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
80
96
|
description: Adds improvements to HTML syntax for id and class attributes
|
81
97
|
email:
|
82
98
|
- cameronsutter0@gmail.com
|
@@ -128,8 +144,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
144
|
version: '0'
|
129
145
|
requirements: []
|
130
146
|
rubyforge_project:
|
131
|
-
rubygems_version: 1.8.
|
147
|
+
rubygems_version: 1.8.23
|
132
148
|
signing_key:
|
133
149
|
specification_version: 3
|
134
150
|
summary: Smarter HTML
|
135
151
|
test_files: []
|
152
|
+
has_rdoc:
|