fira 0.3.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/fira.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- ID_PATTERN = /(<.*)#([a-z_A-Z\-]+)(.*>.*<\/.*>)/
3
+ ID_PATTERN = /(<[^\/]?.*)#([a-z_A-Z\-]+)/
4
4
  CLASS_PATTERN = /\.([a-z_A-Z\-]+)/
5
- TAG_PATTERN = /<.*>/
6
- OPEN_TAG_PATTERN = /(<.*>)(.*<\/.*>)/
5
+ TAG_PATTERN = /<[^\/]?.*>/
7
6
 
8
7
  #begin parsing text
9
8
  def parse_text(contents)
@@ -19,7 +18,7 @@ end
19
18
  #scan for ids and replace with html id attributes
20
19
  def parse_ids(contents)
21
20
 
22
- result = contents.gsub(ID_PATTERN, '\1 id="\2" \3')
21
+ result = contents.gsub(ID_PATTERN, '\1 id="\2"')
23
22
  end
24
23
 
25
24
  #scan for classes and create html class attributes
@@ -31,9 +30,8 @@ def parse_classes(contents)
31
30
  tags = contents.scan(TAG_PATTERN)
32
31
  tags.each do |tag|
33
32
 
34
- open_tag = tag.scan(OPEN_TAG_PATTERN)
33
+ classes = tag.scan(CLASS_PATTERN)
35
34
 
36
- classes = open_tag[0][0].scan(CLASS_PATTERN)
37
35
 
38
36
  if ! classes.empty?
39
37
 
@@ -50,14 +48,11 @@ def parse_classes(contents)
50
48
  att = att.sub(/class=' /, "class='")
51
49
 
52
50
  #remove the fira class attributes
53
- new_open_tag = open_tag[0][0].gsub(CLASS_PATTERN, "")
51
+ new_tag = tag.gsub(CLASS_PATTERN, "")
54
52
 
55
53
  #save the html class attributes back into the tag
56
- new_open_tag = new_open_tag.sub(/>/,att + "\\0")
57
-
58
- #replace the old opening tag with the new
59
- new_tag = tag.gsub(OPEN_TAG_PATTERN, new_open_tag + '\2')
60
-
54
+ new_tag = new_tag.sub(/>/,att + "\\0")
55
+
61
56
  #save the whole html tag back into the file
62
57
  result = result.sub(tag, new_tag)
63
58
  end
@@ -80,15 +75,11 @@ files.each do |fi|
80
75
  File.open(fi, 'r+'){
81
76
  |f|
82
77
  contents = f.read
83
-
84
- tag_pattern = /<.*>/
85
-
86
- result = parse_ids(contents)
87
78
 
88
- result = parse_classes(result, tag_pattern)
79
+ result = parse_text(contents)
89
80
 
90
81
  #make the new file's name
91
- new_file = fi.sub(/(\.fi$|\.html.fi$)/, ".html")
82
+ new_file = fi.sub(/(\.fira$|\.html.fira$)/, ".html")
92
83
 
93
84
  File.open(new_file, "w") { |nf| nf.write(result)}
94
85
  }
data/lib/fira/engine.rb CHANGED
@@ -2,10 +2,9 @@ module Fira
2
2
 
3
3
  class Engine
4
4
 
5
- ID_PATTERN = /(<.*)#([a-z_A-Z\-]+)(.*>.*<\/.*>)/
5
+ ID_PATTERN = /(<[^\/]?.*)#([a-z_A-Z\-]+)/
6
6
  CLASS_PATTERN = /\.([a-z_A-Z\-]+)/
7
- TAG_PATTERN = /<.*>/
8
- OPEN_TAG_PATTERN = /(<.*>)(.*<\/.*>)/
7
+ TAG_PATTERN = /<[^\/]?.*>/
9
8
 
10
9
  #begin parsing text
11
10
  def parse_text(contents)
@@ -21,7 +20,7 @@ module Fira
21
20
  #scan for ids and replace with html id attributes
22
21
  def parse_ids(contents)
23
22
 
24
- result = contents.gsub(ID_PATTERN, '\1 id="\2" \3')
23
+ result = contents.gsub(ID_PATTERN, '\1 id="\2"')
25
24
  end
26
25
 
27
26
  #scan for classes and create html class attributes
@@ -33,38 +32,31 @@ module Fira
33
32
  tags = contents.scan(TAG_PATTERN)
34
33
  tags.each do |tag|
35
34
 
36
- open_tag = tag.scan(OPEN_TAG_PATTERN)
35
+ classes = tag.scan(CLASS_PATTERN)
37
36
 
38
- if ! open_tag.empty?
39
37
 
40
- classes = open_tag[0][0].scan(CLASS_PATTERN)
41
-
42
- if ! classes.empty?
38
+ if ! classes.empty?
39
+
40
+ #build a class attribute
41
+ att = "class='"
42
+
43
+ classes.each do |cl|
44
+ att += " #{cl[0]}"
45
+ end
46
+
47
+ att += "'"
43
48
 
44
- #build a class attribute
45
- att = "class='"
49
+ #remove the space before the first class
50
+ att = att.sub(/class=' /, "class='")
46
51
 
47
- classes.each do |cl|
48
- att += " #{cl[0]}"
49
- end
50
-
51
- att += "'"
52
-
53
- #remove the space before the first class
54
- att = att.sub(/class=' /, "class='")
55
-
56
- #remove the fira class attributes
57
- new_open_tag = open_tag[0][0].gsub(CLASS_PATTERN, "")
52
+ #remove the fira class attributes
53
+ new_tag = tag.gsub(CLASS_PATTERN, "")
58
54
 
59
- #save the html class attributes back into the tag
60
- new_open_tag = new_open_tag.sub(/>/,att + "\\0")
61
-
62
- #replace the old opening tag with the new
63
- new_tag = tag.gsub(OPEN_TAG_PATTERN, new_open_tag + '\2')
64
-
65
- #save the whole html tag back into the file
66
- result = result.sub(tag, new_tag)
67
- end
55
+ #save the html class attributes back into the tag
56
+ new_tag = new_tag.sub(/>/,att + "\\0")
57
+
58
+ #save the whole html tag back into the file
59
+ result = result.sub(tag, new_tag)
68
60
  end
69
61
  end
70
62
 
data/lib/fira/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fira
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.2"
3
3
  end
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.3.0
4
+ version: 0.3.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-01-25 00:00:00.000000000 Z
12
+ date: 2013-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  requirements: []
128
128
  rubyforge_project:
129
- rubygems_version: 1.8.24
129
+ rubygems_version: 1.8.25
130
130
  signing_key:
131
131
  specification_version: 3
132
132
  summary: Smarter HTML