html 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.rspec +1 -0
- data/.travis.yml +16 -0
- data/Changelog.md +3 -0
- data/Gemfile +6 -0
- data/Gemfile.devtools +64 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/TODO +2 -0
- data/config/flay.yml +3 -0
- data/config/flog.yml +3 -0
- data/config/mutant.yml +3 -0
- data/config/roodi.yml +18 -0
- data/config/site.reek +93 -0
- data/config/yardstick.yml +2 -0
- data/html.gemspec +20 -0
- data/lib/html.rb +117 -0
- data/lib/html/fragment.rb +54 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/unit/html/class_methods/attributes_spec.rb +20 -0
- data/spec/unit/html/class_methods/content_tag_spec.rb +38 -0
- data/spec/unit/html/class_methods/content_tags_spec.rb +11 -0
- data/spec/unit/html/class_methods/escape_spec.rb +21 -0
- data/spec/unit/html/class_methods/join_spec.rb +23 -0
- data/spec/unit/html/class_methods/nocontent_tags_spec.rb +11 -0
- data/spec/unit/html/class_methods/tag_spec.rb +37 -0
- data/spec/unit/html/fragment/class_methods/build_spec.rb +24 -0
- data/spec/unit/html/fragment/initialize_spec.rb +17 -0
- metadata +139 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
language: ruby
|
2
|
+
bundler_args: --without guard
|
3
|
+
script: "bundle exec rake ci"
|
4
|
+
rvm:
|
5
|
+
- 1.9.2
|
6
|
+
- 1.9.3
|
7
|
+
- jruby-19mode
|
8
|
+
- rbx-19mode
|
9
|
+
allowed_failures:
|
10
|
+
matrix:
|
11
|
+
- 1.8.7
|
12
|
+
- jruby-18mode
|
13
|
+
- rbx-18mode
|
14
|
+
notifications:
|
15
|
+
email:
|
16
|
+
- mbj@seonic.net
|
data/Changelog.md
ADDED
data/Gemfile
ADDED
data/Gemfile.devtools
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
group :development do
|
4
|
+
gem 'rake', '~> 10.0.3'
|
5
|
+
gem 'rspec', '~> 2.13.0'
|
6
|
+
gem 'yard', '~> 0.8.5'
|
7
|
+
end
|
8
|
+
|
9
|
+
group :yard do
|
10
|
+
gem 'kramdown', '~> 0.14.2'
|
11
|
+
end
|
12
|
+
|
13
|
+
group :guard do
|
14
|
+
gem 'guard', '~> 1.6.2'
|
15
|
+
gem 'guard-bundler', '~> 1.0.0'
|
16
|
+
gem 'guard-rspec', '~> 2.4.1'
|
17
|
+
|
18
|
+
# file system change event handling
|
19
|
+
gem 'rb-fchange', '~> 0.0.6', :require => false
|
20
|
+
gem 'rb-fsevent', '~> 0.9.3', :require => false
|
21
|
+
gem 'rb-inotify', '~> 0.9.0', :require => false
|
22
|
+
|
23
|
+
gem 'listen', '~> 0.7.3'
|
24
|
+
|
25
|
+
# notification handling
|
26
|
+
gem 'libnotify', '~> 0.8.0', :require => false
|
27
|
+
gem 'rb-notifu', '~> 0.0.4', :require => false
|
28
|
+
gem 'terminal-notifier-guard', '~> 1.5.3', :require => false
|
29
|
+
end
|
30
|
+
|
31
|
+
group :metrics do
|
32
|
+
gem 'flay', '~> 2.1.0'
|
33
|
+
gem 'flog', '~> 3.2.2'
|
34
|
+
gem 'reek', '~> 1.3.1'
|
35
|
+
gem 'metric_fu-roodi', '~> 2.2.1'
|
36
|
+
gem 'yardstick', '~> 0.9.3'
|
37
|
+
|
38
|
+
platforms :ruby_18, :ruby_19 do
|
39
|
+
# this indirectly depends on ffi which does not build on ruby-head
|
40
|
+
gem 'yard-spellcheck', '~> 0.1.5'
|
41
|
+
end
|
42
|
+
|
43
|
+
platforms :mri_19, :rbx do
|
44
|
+
gem 'mutant', '~> 0.2.20'
|
45
|
+
end
|
46
|
+
|
47
|
+
platforms :mri_19 do
|
48
|
+
gem 'simplecov', '~> 0.7.1'
|
49
|
+
end
|
50
|
+
|
51
|
+
platforms :rbx do
|
52
|
+
gem 'pelusa', '~> 0.2.2'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
group :benchmarks do
|
57
|
+
gem 'rbench', '~> 0.2.3'
|
58
|
+
end
|
59
|
+
|
60
|
+
platform :jruby do
|
61
|
+
group :jruby do
|
62
|
+
gem 'jruby-openssl', '~> 0.8.2'
|
63
|
+
end
|
64
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
HTML
|
2
|
+
====
|
3
|
+
|
4
|
+
[![Build Status](https://secure.travis-ci.org/mbj/html.png?branch=master)](http://travis-ci.org/mbj/html)
|
5
|
+
[![Dependency Status](https://gemnasium.com/mbj/html.png)](https://gemnasium.com/mbj/html)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/mbj/html.png)](https://codeclimate.com/github/mbj/html)
|
7
|
+
|
8
|
+
A library to generate html fragments.
|
9
|
+
|
10
|
+
Installation
|
11
|
+
------------
|
12
|
+
|
13
|
+
Install the gem `html` via your preferred method.
|
14
|
+
|
15
|
+
Examples
|
16
|
+
--------
|
17
|
+
|
18
|
+
Soon.
|
19
|
+
|
20
|
+
Credits
|
21
|
+
-------
|
22
|
+
|
23
|
+
* [Markus Schirp (mbj)](https://github.com/mbj) Author
|
24
|
+
|
25
|
+
Contributing
|
26
|
+
-------------
|
27
|
+
|
28
|
+
* Fork the project.
|
29
|
+
* Make your feature addition or bug fix.
|
30
|
+
* Add tests for it. This is important so I don't break it in a
|
31
|
+
future version unintentionally.
|
32
|
+
* Commit, do not mess with Rakefile or version
|
33
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
34
|
+
* Send me a pull request. Bonus points for topic branches.
|
35
|
+
|
36
|
+
License
|
37
|
+
-------
|
38
|
+
|
39
|
+
This gem is published under the MIT license. See `LICENSE` file.
|
data/Rakefile
ADDED
data/TODO
ADDED
data/config/flay.yml
ADDED
data/config/flog.yml
ADDED
data/config/mutant.yml
ADDED
data/config/roodi.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
AbcMetricMethodCheck: { score: 10.3 }
|
3
|
+
AssignmentInConditionalCheck: { }
|
4
|
+
CaseMissingElseCheck: { }
|
5
|
+
ClassLineCountCheck: { line_count: 293 }
|
6
|
+
ClassNameCheck: { pattern: !ruby/regexp '/\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/' }
|
7
|
+
ClassVariableCheck: { }
|
8
|
+
CyclomaticComplexityBlockCheck: { complexity: 2 }
|
9
|
+
CyclomaticComplexityMethodCheck: { complexity: 4 }
|
10
|
+
EmptyRescueBodyCheck: { }
|
11
|
+
ForLoopCheck: { }
|
12
|
+
# TODO: decrease line_count to 5 to 10
|
13
|
+
MethodLineCountCheck: { line_count: 14 }
|
14
|
+
MethodNameCheck: { pattern: !ruby/regexp '/\A(?:[a-z\d](?:_?[a-z\d])+[?!=]?|\[\]=?|==|<=>|[+*&|-])\z/' }
|
15
|
+
ModuleLineCountCheck: { line_count: 295 }
|
16
|
+
ModuleNameCheck: { pattern: !ruby/regexp '/\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/' }
|
17
|
+
# TODO: decrease parameter_count to 2 or less
|
18
|
+
ParameterNumberCheck: { parameter_count: 3 }
|
data/config/site.reek
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
---
|
2
|
+
UncommunicativeParameterName:
|
3
|
+
accept: []
|
4
|
+
exclude: []
|
5
|
+
enabled: true
|
6
|
+
reject:
|
7
|
+
- !ruby/regexp /^.$/
|
8
|
+
- !ruby/regexp /[0-9]$/
|
9
|
+
- !ruby/regexp /[A-Z]/
|
10
|
+
LargeClass:
|
11
|
+
max_methods: 10
|
12
|
+
exclude: []
|
13
|
+
enabled: true
|
14
|
+
max_instance_variables: 2
|
15
|
+
UncommunicativeMethodName:
|
16
|
+
accept: []
|
17
|
+
exclude: []
|
18
|
+
enabled: true
|
19
|
+
reject:
|
20
|
+
- !ruby/regexp /^[a-z]$/
|
21
|
+
- !ruby/regexp /[0-9]$/
|
22
|
+
- !ruby/regexp /[A-Z]/
|
23
|
+
LongParameterList:
|
24
|
+
max_params: 2
|
25
|
+
exclude:
|
26
|
+
- HTML#self.content_tag
|
27
|
+
enabled: true
|
28
|
+
overrides: {}
|
29
|
+
FeatureEnvy:
|
30
|
+
exclude: []
|
31
|
+
enabled: true
|
32
|
+
ClassVariable:
|
33
|
+
exclude: []
|
34
|
+
enabled: true
|
35
|
+
BooleanParameter:
|
36
|
+
exclude: []
|
37
|
+
enabled: true
|
38
|
+
IrresponsibleModule:
|
39
|
+
exclude: []
|
40
|
+
enabled: true
|
41
|
+
UncommunicativeModuleName:
|
42
|
+
accept: []
|
43
|
+
exclude: []
|
44
|
+
enabled: true
|
45
|
+
reject:
|
46
|
+
- !ruby/regexp /^.$/
|
47
|
+
- !ruby/regexp /[0-9]$/
|
48
|
+
NestedIterators:
|
49
|
+
ignore_iterators: []
|
50
|
+
exclude:
|
51
|
+
- Adamantium::ModuleMethods#define_memoize_method # 2 levels
|
52
|
+
enabled: true
|
53
|
+
max_allowed_nesting: 1
|
54
|
+
LongMethod:
|
55
|
+
max_statements: 7 # TODO: decrease max_statements to 5 or less
|
56
|
+
exclude: []
|
57
|
+
enabled: true
|
58
|
+
Duplication:
|
59
|
+
allow_calls: []
|
60
|
+
exclude: []
|
61
|
+
enabled: true
|
62
|
+
max_calls: 1
|
63
|
+
UtilityFunction:
|
64
|
+
max_helper_calls: 1
|
65
|
+
exclude: []
|
66
|
+
enabled: true
|
67
|
+
Attribute:
|
68
|
+
exclude: []
|
69
|
+
enabled: false
|
70
|
+
UncommunicativeVariableName:
|
71
|
+
accept: []
|
72
|
+
exclude: []
|
73
|
+
enabled: true
|
74
|
+
reject:
|
75
|
+
- !ruby/regexp /^.$/
|
76
|
+
- !ruby/regexp /[0-9]$/
|
77
|
+
- !ruby/regexp /[A-Z]/
|
78
|
+
SimulatedPolymorphism:
|
79
|
+
exclude: []
|
80
|
+
enabled: true
|
81
|
+
max_ifs: 1
|
82
|
+
DataClump:
|
83
|
+
exclude: []
|
84
|
+
enabled: true
|
85
|
+
max_copies: 1
|
86
|
+
min_clump_size: 3
|
87
|
+
ControlCouple:
|
88
|
+
exclude: []
|
89
|
+
enabled: true
|
90
|
+
LongYieldList:
|
91
|
+
max_params: 1
|
92
|
+
exclude: []
|
93
|
+
enabled: true
|
data/html.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = 'html'
|
5
|
+
gem.version = '0.0.1'
|
6
|
+
gem.authors = [ 'Markus Schirp' ]
|
7
|
+
gem.email = [ 'mbj@seonic.net' ]
|
8
|
+
gem.description = 'Because HTML is not a String'
|
9
|
+
gem.summary = gem.description
|
10
|
+
gem.homepage = 'https://github.com/mbj/html'
|
11
|
+
|
12
|
+
gem.require_paths = [ 'lib' ]
|
13
|
+
gem.files = `git ls-files`.split("\n")
|
14
|
+
gem.test_files = `git ls-files -- spec`.split("\n")
|
15
|
+
gem.extra_rdoc_files = %w[TODO]
|
16
|
+
|
17
|
+
gem.add_runtime_dependency('backports', [ '~> 3.0', '>= 3.0.3' ])
|
18
|
+
gem.add_runtime_dependency('adamantium', '~> 0.0.7')
|
19
|
+
gem.add_runtime_dependency('equalizer', '~> 0.0.5')
|
20
|
+
end
|
data/lib/html.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'backports'
|
3
|
+
require 'adamantium'
|
4
|
+
require 'equalizer'
|
5
|
+
require 'ice_nine'
|
6
|
+
|
7
|
+
# Library namespace
|
8
|
+
module HTML
|
9
|
+
|
10
|
+
CONTENT_TAGS = IceNine.deep_freeze(%w(
|
11
|
+
a abbr address article aside audio b bdi bdo blockquote
|
12
|
+
body button canvas caption cite code col colgroup data
|
13
|
+
dd del details dfn div dl dt em embed eventsource fieldset
|
14
|
+
fieldsource figcaption figure footer form h1 h2 h3 h4 h5 h6
|
15
|
+
head header hgroup html i iframe ins kbd label legend li link
|
16
|
+
mark menu nav noscript object ol optgroup option output p pre
|
17
|
+
q ruby rp rt s samp script section select small span strong
|
18
|
+
style sub summary sup table tbody textarea tfoot th thead time
|
19
|
+
title td tr ul var video
|
20
|
+
))
|
21
|
+
|
22
|
+
NOCONTENT_TAGS = IceNine.deep_freeze(%w(
|
23
|
+
area br command hr img input keygen map meta meter progress
|
24
|
+
param source track wbr
|
25
|
+
))
|
26
|
+
|
27
|
+
# Join html compoinents
|
28
|
+
#
|
29
|
+
# @param [Enumerable<#to_s>] components
|
30
|
+
#
|
31
|
+
# @return [HTML::Fragment]
|
32
|
+
#
|
33
|
+
# @api private
|
34
|
+
#
|
35
|
+
def self.join(components)
|
36
|
+
contents = components.map do |component|
|
37
|
+
Fragment.build(component)
|
38
|
+
end
|
39
|
+
Fragment.new(contents.join)
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
# Escape html
|
44
|
+
#
|
45
|
+
# @param [String] text
|
46
|
+
#
|
47
|
+
# @return [String]
|
48
|
+
#
|
49
|
+
# @api private
|
50
|
+
#
|
51
|
+
def self.escape(text)
|
52
|
+
text.gsub(
|
53
|
+
/[><"]/,
|
54
|
+
'>' => '<',
|
55
|
+
'<' => '>',
|
56
|
+
'"' => '&'
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
CONTENT_TAGS.each do |name|
|
61
|
+
class_eval(<<-RUBY, __FILE__, __LINE__)
|
62
|
+
def self.#{name}(*args)
|
63
|
+
content_tag(:#{name}, *args)
|
64
|
+
end
|
65
|
+
RUBY
|
66
|
+
end
|
67
|
+
|
68
|
+
NOCONTENT_TAGS.each do |name|
|
69
|
+
class_eval(<<-RUBY, __FILE__, __LINE__)
|
70
|
+
def self.#{name}(*args)
|
71
|
+
tag(:#{name}, *args)
|
72
|
+
end
|
73
|
+
RUBY
|
74
|
+
end
|
75
|
+
|
76
|
+
# Create contentless html tag
|
77
|
+
#
|
78
|
+
# @param [#to_str] type
|
79
|
+
# @param [Hash] attributes
|
80
|
+
#
|
81
|
+
# @return [Fragment]
|
82
|
+
#
|
83
|
+
# @api private
|
84
|
+
#
|
85
|
+
def self.tag(type, attributes={})
|
86
|
+
Fragment.new("<#{type}#{attributes(attributes)}/>")
|
87
|
+
end
|
88
|
+
|
89
|
+
# Create content tag
|
90
|
+
#
|
91
|
+
# @param [#to_str] type
|
92
|
+
# @param [String] content
|
93
|
+
#
|
94
|
+
# @return [Fragment]
|
95
|
+
#
|
96
|
+
# @api private
|
97
|
+
#
|
98
|
+
def self.content_tag(type, content, attributes={})
|
99
|
+
Fragment.new("<#{type}#{attributes(attributes)}>#{Fragment.build(content).to_s}</#{type}>")
|
100
|
+
end
|
101
|
+
|
102
|
+
# Create html attributes
|
103
|
+
#
|
104
|
+
# @param [Hash] attributes
|
105
|
+
#
|
106
|
+
# @return [String]
|
107
|
+
#
|
108
|
+
# @api private
|
109
|
+
#
|
110
|
+
def self.attributes(attributes)
|
111
|
+
attributes.map do |key, value|
|
112
|
+
%Q{ #{key.to_s}="#{escape(value.to_s)}"}
|
113
|
+
end.join
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
require 'html/fragment'
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module HTML
|
2
|
+
|
3
|
+
# An html fragment
|
4
|
+
class Fragment
|
5
|
+
include Adamantium, Equalizer.new(:content)
|
6
|
+
|
7
|
+
# Return contents of fragment
|
8
|
+
#
|
9
|
+
# @return [String]
|
10
|
+
#
|
11
|
+
# @api private
|
12
|
+
#
|
13
|
+
attr_reader :content
|
14
|
+
|
15
|
+
# Initialize object
|
16
|
+
#
|
17
|
+
# @param [String] string
|
18
|
+
#
|
19
|
+
# @return [undefined]
|
20
|
+
#
|
21
|
+
# @api private
|
22
|
+
#
|
23
|
+
def initialize(string)
|
24
|
+
@content = string
|
25
|
+
end
|
26
|
+
|
27
|
+
# Return string
|
28
|
+
#
|
29
|
+
# FIXME: This will be removed once I have my own templating language.
|
30
|
+
#
|
31
|
+
# @return [String]
|
32
|
+
#
|
33
|
+
alias_method :to_s, :content
|
34
|
+
|
35
|
+
# Create new fragment
|
36
|
+
#
|
37
|
+
# @param [String,Fragment] input
|
38
|
+
#
|
39
|
+
# @return [Fragment]
|
40
|
+
#
|
41
|
+
# @api private
|
42
|
+
#
|
43
|
+
def self.build(input)
|
44
|
+
if input.kind_of?(self)
|
45
|
+
input
|
46
|
+
else
|
47
|
+
new(HTML.escape(input))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
EMPTY = new('')
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HTML, '.attributes' do
|
4
|
+
let(:object) { described_class }
|
5
|
+
|
6
|
+
subject { object.attributes(input) }
|
7
|
+
|
8
|
+
examples = {
|
9
|
+
{ 'foo' => 'bar' } => ' foo="bar"',
|
10
|
+
{ 'foo' => '"' } => ' foo="&"',
|
11
|
+
{ :class => :baz } => ' class="baz"'
|
12
|
+
}
|
13
|
+
|
14
|
+
examples.each do |input, expectation|
|
15
|
+
context "with #{input} as input" do
|
16
|
+
let(:input) { input }
|
17
|
+
it { should eql(expectation) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HTML, '.tag' do
|
4
|
+
let(:object) { described_class }
|
5
|
+
|
6
|
+
subject { object.content_tag(*arguments) }
|
7
|
+
|
8
|
+
let(:name) { 'foo' }
|
9
|
+
let(:content) { 'content' }
|
10
|
+
|
11
|
+
context 'without attributes' do
|
12
|
+
let(:arguments) { [ name, content ] }
|
13
|
+
|
14
|
+
it 'should return html fragment' do
|
15
|
+
should eql(HTML::Fragment.new('<foo>content</foo>'))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with attributes' do
|
20
|
+
let(:arguments) { [ name, content, attributes ] }
|
21
|
+
|
22
|
+
context 'empty' do
|
23
|
+
let(:attributes) { {} }
|
24
|
+
|
25
|
+
it 'should return html fragment' do
|
26
|
+
should eql(HTML::Fragment.new('<foo>content</foo>'))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'non empty' do
|
31
|
+
let(:attributes) { { :foo => :bar } }
|
32
|
+
|
33
|
+
it 'should return html fragment' do
|
34
|
+
should eql(HTML::Fragment.new('<foo foo="bar">content</foo>'))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HTML, 'content tags' do
|
4
|
+
let(:object) { described_class }
|
5
|
+
|
6
|
+
HTML::CONTENT_TAGS.each do |name|
|
7
|
+
it "should render #{name} correcty" do
|
8
|
+
object.public_send(name, 'content', {:foo => :bar}).content.should eql(%Q(<#{name} foo="bar">content</#{name}>))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HTML, '.escape' do
|
4
|
+
let(:object) { described_class }
|
5
|
+
|
6
|
+
subject { object.escape(string) }
|
7
|
+
|
8
|
+
examples = {
|
9
|
+
'foo' => 'foo',
|
10
|
+
'<>' => '><',
|
11
|
+
'<foo>' => '>foo<',
|
12
|
+
'<foo bar="baz">' => '>foo bar=&baz&<'
|
13
|
+
}
|
14
|
+
|
15
|
+
examples.each do |input, expectation|
|
16
|
+
context "with #{input} as input" do
|
17
|
+
let(:string) { input }
|
18
|
+
it { should eql(expectation) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HTML, '.join' do
|
4
|
+
let(:object) { described_class }
|
5
|
+
|
6
|
+
subject { object.join(input) }
|
7
|
+
|
8
|
+
examples = {
|
9
|
+
[] => '',
|
10
|
+
['foo'] => 'foo',
|
11
|
+
['foo', 'bar'] => 'foobar',
|
12
|
+
['foo', HTML::Fragment.new('bar')] => 'foobar',
|
13
|
+
['foo', HTML::Fragment.new('<bar>')] => 'foo<bar>',
|
14
|
+
['<foo>', HTML::Fragment.new('<bar>')] => '>foo<<bar>',
|
15
|
+
}
|
16
|
+
|
17
|
+
examples.each do |input, expectation|
|
18
|
+
context "with #{input.inspect} as input" do
|
19
|
+
let(:input) { input }
|
20
|
+
it { should eql(HTML::Fragment.new(expectation)) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HTML, 'nocontent tags' do
|
4
|
+
let(:object) { described_class }
|
5
|
+
|
6
|
+
HTML::NOCONTENT_TAGS.each do |name|
|
7
|
+
it "should render #{name} correcty" do
|
8
|
+
object.public_send(name, :foo => :bar).content.should eql(%Q(<#{name} foo="bar"/>))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HTML, '.tag' do
|
4
|
+
let(:object) { described_class }
|
5
|
+
|
6
|
+
subject { object.tag(*arguments) }
|
7
|
+
|
8
|
+
let(:name) { 'foo' }
|
9
|
+
|
10
|
+
context 'without attributes' do
|
11
|
+
let(:arguments) { [ name ] }
|
12
|
+
|
13
|
+
it 'should return html fragment' do
|
14
|
+
should eql(HTML::Fragment.new('<foo/>'))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'with attributes' do
|
19
|
+
let(:arguments) { [ name, attributes ] }
|
20
|
+
|
21
|
+
context 'empty' do
|
22
|
+
let(:attributes) { {} }
|
23
|
+
|
24
|
+
it 'should return html fragment' do
|
25
|
+
should eql(HTML::Fragment.new('<foo/>'))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'non empty' do
|
30
|
+
let(:attributes) { { :foo => :bar } }
|
31
|
+
|
32
|
+
it 'should return html fragment' do
|
33
|
+
should eql(HTML::Fragment.new('<foo foo="bar"/>'))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HTML::Fragment, '.build' do
|
4
|
+
let(:object) { described_class }
|
5
|
+
subject { object.build(input) }
|
6
|
+
|
7
|
+
context 'when input is string' do
|
8
|
+
let(:input) { '<foo>' }
|
9
|
+
|
10
|
+
it 'should store escaped string' do
|
11
|
+
subject.content.should eql('>foo<')
|
12
|
+
end
|
13
|
+
|
14
|
+
it { should be_a(described_class) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when input is HTML::Fragment' do
|
18
|
+
let(:input) { HTML::Fragment.new(mock) }
|
19
|
+
|
20
|
+
it 'should be input' do
|
21
|
+
should be(input)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# NOTE: This will move to class_methods/new_spec.rb with mutant-0.3.0!
|
4
|
+
describe HTML::Fragment, '#initialize' do
|
5
|
+
let(:object) { described_class }
|
6
|
+
|
7
|
+
subject { object.new(input) }
|
8
|
+
|
9
|
+
let(:input) { Object.new }
|
10
|
+
|
11
|
+
its(:content) { should eql(input) }
|
12
|
+
|
13
|
+
it 'should freeze input' do
|
14
|
+
subject
|
15
|
+
input.frozen?.should be(true)
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: html
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Markus Schirp
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: backports
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
- - ! '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 3.0.3
|
25
|
+
type: :runtime
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.0'
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 3.0.3
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: adamantium
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.0.7
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ~>
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: 0.0.7
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: equalizer
|
54
|
+
requirement: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 0.0.5
|
60
|
+
type: :runtime
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.0.5
|
68
|
+
description: Because HTML is not a String
|
69
|
+
email:
|
70
|
+
- mbj@seonic.net
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files:
|
74
|
+
- TODO
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- .travis.yml
|
79
|
+
- Changelog.md
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.devtools
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- TODO
|
85
|
+
- config/flay.yml
|
86
|
+
- config/flog.yml
|
87
|
+
- config/mutant.yml
|
88
|
+
- config/roodi.yml
|
89
|
+
- config/site.reek
|
90
|
+
- config/yardstick.yml
|
91
|
+
- html.gemspec
|
92
|
+
- lib/html.rb
|
93
|
+
- lib/html/fragment.rb
|
94
|
+
- spec/spec_helper.rb
|
95
|
+
- spec/unit/html/class_methods/attributes_spec.rb
|
96
|
+
- spec/unit/html/class_methods/content_tag_spec.rb
|
97
|
+
- spec/unit/html/class_methods/content_tags_spec.rb
|
98
|
+
- spec/unit/html/class_methods/escape_spec.rb
|
99
|
+
- spec/unit/html/class_methods/join_spec.rb
|
100
|
+
- spec/unit/html/class_methods/nocontent_tags_spec.rb
|
101
|
+
- spec/unit/html/class_methods/tag_spec.rb
|
102
|
+
- spec/unit/html/fragment/class_methods/build_spec.rb
|
103
|
+
- spec/unit/html/fragment/initialize_spec.rb
|
104
|
+
homepage: https://github.com/mbj/html
|
105
|
+
licenses: []
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 1.8.23
|
125
|
+
signing_key:
|
126
|
+
specification_version: 3
|
127
|
+
summary: Because HTML is not a String
|
128
|
+
test_files:
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
- spec/unit/html/class_methods/attributes_spec.rb
|
131
|
+
- spec/unit/html/class_methods/content_tag_spec.rb
|
132
|
+
- spec/unit/html/class_methods/content_tags_spec.rb
|
133
|
+
- spec/unit/html/class_methods/escape_spec.rb
|
134
|
+
- spec/unit/html/class_methods/join_spec.rb
|
135
|
+
- spec/unit/html/class_methods/nocontent_tags_spec.rb
|
136
|
+
- spec/unit/html/class_methods/tag_spec.rb
|
137
|
+
- spec/unit/html/fragment/class_methods/build_spec.rb
|
138
|
+
- spec/unit/html/fragment/initialize_spec.rb
|
139
|
+
has_rdoc:
|