html_tagger 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.
- data/.gemtest +0 -0
- data/README.md +7 -0
- data/html_tagger.gemspec +4 -2
- data/lib/html_tagger.rb +71 -11
- data/lib/html_tagger/version.rb +1 -1
- data/spec/html_tagger/html_tagger_spec.rb +58 -1
- metadata +27 -12
data/.gemtest
ADDED
File without changes
|
data/README.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
Several convience methods monkey patched on String to wrap in HTML formatting.
|
4
4
|
|
5
|
+
Method chaining is possible, but produces a lot of embedded SPAN tags. New methods to be added later will allow for a call for a single SPAN tag.
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
5
10
|
## Installation
|
6
11
|
|
7
12
|
Add this line to your application's Gemfile:
|
@@ -27,3 +32,5 @@ Or install it yourself as:
|
|
27
32
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
33
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
34
|
5. Create new Pull Request
|
35
|
+
|
36
|
+
[](http://coderwall.com/coyote)
|
data/html_tagger.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.email = ["craig.a.cook@gmail.com"]
|
8
8
|
gem.description = %q{OO simple html tagging of text, similar to JS calls}
|
9
9
|
gem.summary = %q{generates HTML tags similar to how it is done in JavaScript}
|
10
|
-
gem.homepage = ""
|
10
|
+
gem.homepage = "https://github.com/coyote/html_tagger"
|
11
11
|
|
12
12
|
gem.files = `git ls-files`.split($\)
|
13
13
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -15,7 +15,9 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.name = "html_tagger"
|
16
16
|
gem.require_paths = ["lib"]
|
17
17
|
gem.version = HtmlTagger::VERSION
|
18
|
+
|
19
|
+
# dependencies -- dev only
|
18
20
|
gem.add_development_dependency "rspec-expectations", "2.9.0"
|
19
21
|
gem.add_development_dependency "rspec", "2.9.0"
|
20
|
-
gem.add_development_dependency
|
22
|
+
gem.add_development_dependency "rubygems-test"
|
21
23
|
end
|
data/lib/html_tagger.rb
CHANGED
@@ -3,50 +3,110 @@ require "html_tagger/version"
|
|
3
3
|
class String
|
4
4
|
|
5
5
|
def link(linked_to_url)
|
6
|
-
'
|
6
|
+
styles('link:'+linked_to_url)
|
7
7
|
end
|
8
8
|
|
9
9
|
def bold
|
10
|
-
|
10
|
+
styles('bold')
|
11
11
|
end
|
12
12
|
|
13
13
|
def color(text_color)
|
14
|
-
|
14
|
+
styles('color:'+text_color)
|
15
15
|
end
|
16
16
|
|
17
17
|
def italics
|
18
|
-
|
18
|
+
styles('italics')
|
19
19
|
end
|
20
20
|
|
21
21
|
def oblique
|
22
|
-
|
22
|
+
styles('oblique')
|
23
23
|
end
|
24
24
|
|
25
25
|
def underscore
|
26
|
-
|
26
|
+
styles('underline')
|
27
27
|
end
|
28
28
|
|
29
29
|
def underline
|
30
|
-
|
30
|
+
styles('underline')
|
31
31
|
end
|
32
32
|
|
33
33
|
def strikeout
|
34
|
-
|
34
|
+
styles('strikeout')
|
35
35
|
end
|
36
36
|
|
37
37
|
def subscript
|
38
|
-
|
38
|
+
styles('subscript')
|
39
39
|
end
|
40
40
|
|
41
41
|
def superscript
|
42
|
-
|
42
|
+
styles('superscript')
|
43
43
|
end
|
44
44
|
|
45
45
|
def add_class(added_class)
|
46
|
-
'
|
46
|
+
styles('class:'+added_class)
|
47
47
|
end
|
48
48
|
|
49
|
+
def styles(*styles)
|
50
|
+
|
51
|
+
tag_attrs = {}
|
52
|
+
|
53
|
+
supported_wrapper_tags = ['span', 'div']
|
54
|
+
|
55
|
+
wrap_tags = { 'before' => [], 'after' => []}
|
56
|
+
|
57
|
+
block = 'span'
|
58
|
+
|
59
|
+
if (styles.first.is_a?(Symbol)) # specify block type
|
60
|
+
block = styles.first.to_s
|
61
|
+
raise "Supported wrapper tags are "+ supported_wrapper_tags.join(' and ') unless supported_wrapper_tags.include?(block)
|
62
|
+
styles.shift
|
63
|
+
end
|
64
|
+
|
65
|
+
styles.reverse.each do |styl|
|
66
|
+
|
67
|
+
case styl
|
68
|
+
when /^id:(.+)/
|
69
|
+
raise "Only one ID allowed for an element." if tag_attrs['id']
|
70
|
+
tag_attrs['id'] = $1
|
71
|
+
when /^link:(.+)/
|
72
|
+
wrap_tags['before'] << "<a href=\"#{$1}\">"
|
73
|
+
wrap_tags['after'] = ['</a>'] + wrap_tags['after']
|
74
|
+
when /^class:(.+)/
|
75
|
+
tag_attrs['class'] = $1 + (tag_attrs['class'].nil? ? '' : ' ' + tag_attrs['class'])
|
76
|
+
when /^color:(.+)/
|
77
|
+
tag_attrs['color'] = $1 # first wins if specified > 1 time
|
78
|
+
when 'bold'
|
79
|
+
tag_attrs['style'] = 'font-weight:bold; ' + tag_attrs['style'].to_s
|
80
|
+
when /^italics?$/
|
81
|
+
tag_attrs['style'] = 'font-style:italic; ' + tag_attrs['style'].to_s
|
82
|
+
when /^under(line|score)$/
|
83
|
+
tag_attrs['style'] = 'text-decoration:underline; ' + tag_attrs['style'].to_s
|
84
|
+
when 'oblique'
|
85
|
+
tag_attrs['style'] = 'font-style:oblique; ' + tag_attrs['style'].to_s
|
86
|
+
when /^strike(out|through)$/
|
87
|
+
tag_attrs['style'] = 'text-decoration:line-through; ' + tag_attrs['style'].to_s
|
88
|
+
when 'subscript'
|
89
|
+
tag_attrs['style'] = 'font-size:xx-small; vertical-align:bottom; ' + tag_attrs['style'].to_s
|
90
|
+
when 'superscript'
|
91
|
+
tag_attrs['style'] = 'font-size:xx-small; vertical-align:top; ' + tag_attrs['style'].to_s
|
92
|
+
else
|
93
|
+
raise "Unexpected style element."
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
block_wrapper = ''
|
99
|
+
block_closer = ''
|
100
|
+
unless tag_attrs.empty?
|
101
|
+
block_wrapper = '<' + block + ' ' +
|
102
|
+
tag_attrs.keys.inject(''){ |accum, html_attr| accum + html_attr + '="' + tag_attrs[html_attr].chomp('; ') + '" '}.chomp(' ') + '>'
|
103
|
+
block_closer = '</' + block + '>'
|
104
|
+
end
|
105
|
+
wrap_tags['before'].join + block_wrapper + self + block_closer + wrap_tags['after'].join
|
49
106
|
|
107
|
+
end
|
108
|
+
|
109
|
+
## compat with 0.0.1 gem
|
50
110
|
def add_style(style)
|
51
111
|
'<span style="' + style + '">' + self + "</span>"
|
52
112
|
end
|
data/lib/html_tagger/version.rb
CHANGED
@@ -13,7 +13,7 @@ describe "HtmlTagger" do
|
|
13
13
|
|
14
14
|
context "HTML String" do
|
15
15
|
|
16
|
-
context "
|
16
|
+
context "proxy methods for #style" do
|
17
17
|
|
18
18
|
it "linkifes self" do
|
19
19
|
text.link('http://localhost:3000/link').should == "<a href=\"http://localhost:3000/link\">#{text}</a>"
|
@@ -59,10 +59,67 @@ describe "HtmlTagger" do
|
|
59
59
|
text.superscript.should == "<span style=\"font-size:xx-small; vertical-align:top\">#{text}</span>"
|
60
60
|
end
|
61
61
|
|
62
|
+
end
|
63
|
+
|
64
|
+
context "it can add multiple stylings at once." do
|
65
|
+
|
66
|
+
it "adds style elements" do
|
67
|
+
text.styles('bold','italics').should == "<span style=\"font-weight:bold; font-style:italic\">Text to Markup</span>"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "can add color as well as style elements" do
|
71
|
+
text.styles('color:red','bold').should == "<span style=\"font-weight:bold\" color=\"red\">Text to Markup</span>"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "can add ID, color, and style elements" do
|
75
|
+
text.styles('id:foo','color:green','underscore').should == "<span style=\"text-decoration:underline\" color=\"green\" id=\"foo\">Text to Markup</span>"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "can add class, ID, and style elements" do
|
79
|
+
text.styles('id:bar', 'color:orange', 'bold', 'class:baz').should == "<span class=\"baz\" style=\"font-weight:bold\" color=\"orange\" id=\"bar\">Text to Markup</span>"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "can add many classes while adding styles" do
|
83
|
+
text.styles('bold','class:foo','class:bar').should == "<span class=\"foo bar\" style=\"font-weight:bold\">Text to Markup</span>"
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
context "block tag selection" do
|
89
|
+
|
90
|
+
it "allows selection explicitly using :span for <SPAN> tag" do
|
91
|
+
text.styles(:span, 'bold').should match /^<span/
|
92
|
+
end
|
93
|
+
|
94
|
+
it "allows selection explicitly using :div for <DIV> tag" do
|
95
|
+
text.styles(:div, 'bold').should match /^<div/
|
96
|
+
end
|
97
|
+
|
98
|
+
it "users a <SPAN> tag when no block element is specified." do
|
99
|
+
text.styles('bold').should match /^<span/
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
context "exceptions" do
|
105
|
+
|
106
|
+
|
107
|
+
it "raises an exception when trying to add an unknown trait" do
|
108
|
+
lambda { text.styles('boo')}.should raise_error RuntimeError
|
109
|
+
end
|
110
|
+
|
111
|
+
it "raises an error when trying to add more than one ID to the element." do
|
112
|
+
lambda { text.styles('id:foo', 'id:bar')}.should raise_error RuntimeError
|
113
|
+
end
|
114
|
+
|
115
|
+
it "raises an exception on an unsupported block tag type" do
|
116
|
+
lambda { text.styles(:foo, 'bold')}.should raise_error RuntimeError
|
117
|
+
end
|
62
118
|
|
63
119
|
|
64
120
|
end
|
65
121
|
|
122
|
+
|
66
123
|
end
|
67
124
|
|
68
125
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html_tagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,29 +13,39 @@ date: 2012-04-19 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec-expectations
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- - =
|
19
|
+
- - '='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: 2.9.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.9.0
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rspec
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
|
-
- - =
|
35
|
+
- - '='
|
31
36
|
- !ruby/object:Gem::Version
|
32
37
|
version: 2.9.0
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - '='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.9.0
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rubygems-test
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,7 +53,12 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
description: OO simple html tagging of text, similar to JS calls
|
48
63
|
email:
|
49
64
|
- craig.a.cook@gmail.com
|
@@ -51,6 +66,7 @@ executables: []
|
|
51
66
|
extensions: []
|
52
67
|
extra_rdoc_files: []
|
53
68
|
files:
|
69
|
+
- .gemtest
|
54
70
|
- .gitignore
|
55
71
|
- Gemfile
|
56
72
|
- LICENSE
|
@@ -61,7 +77,7 @@ files:
|
|
61
77
|
- lib/html_tagger/version.rb
|
62
78
|
- spec/html_tagger/html_tagger_spec.rb
|
63
79
|
- spec/spec_helper.rb
|
64
|
-
homepage:
|
80
|
+
homepage: https://github.com/coyote/html_tagger
|
65
81
|
licenses: []
|
66
82
|
post_install_message:
|
67
83
|
rdoc_options: []
|
@@ -81,11 +97,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
97
|
version: '0'
|
82
98
|
requirements: []
|
83
99
|
rubyforge_project:
|
84
|
-
rubygems_version: 1.8.
|
100
|
+
rubygems_version: 1.8.21
|
85
101
|
signing_key:
|
86
102
|
specification_version: 3
|
87
103
|
summary: generates HTML tags similar to how it is done in JavaScript
|
88
104
|
test_files:
|
89
105
|
- spec/html_tagger/html_tagger_spec.rb
|
90
106
|
- spec/spec_helper.rb
|
91
|
-
has_rdoc:
|