fira 0.4.1 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new('spec')
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.libs << 'test'
9
+ end
10
+
11
+ desc "Run tests"
12
+ task :default => :spec
data/bin/fira.rb CHANGED
File without changes
data/fira.gemspec CHANGED
@@ -20,4 +20,6 @@ Gem::Specification.new do |gem|
20
20
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
21
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
22
  gem.require_paths = ["lib"]
23
+
24
+ gem.add_development_dependency "rspec"
23
25
  end
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-Z\-]+)/
7
- CLASS_REGEX = / \.([a-z_A-Z\-]+)/
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
- #if it's an opening tag, analyze it
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 = token.sub(ID_REGEX, ' id="\1"')
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
- output += final_result
50
+ #add back in the quotes
51
+ final = insert_quotes(quotes, final_result)
43
52
  else
44
- output += result
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
@@ -1,4 +1,5 @@
1
- require 'action_view/template'
1
+ require 'active_support'
2
+ require 'action_view'
2
3
  require 'erubis'
3
4
 
4
5
  module Fira
data/lib/fira/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fira
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.1"
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.4.1
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-04-02 00:00:00.000000000 Z
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.24
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: