html_gen 0.0.12 → 0.0.13

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ac5b5ea7652e96cef3131825ecba4d8b5ba621c
4
- data.tar.gz: 954569c86420e7c71ebb6f407c850989f0bc21e7
3
+ metadata.gz: 132c41c56cc99d2520198d3a9cbe86a8e697e950
4
+ data.tar.gz: d6132cc6f28ce9ec5cdcb4fcfeb7be49a1b0b342
5
5
  SHA512:
6
- metadata.gz: 2f2f765c920ef1ec3202b683f2a959590646872f33d4b3b01ab23557b9234a7ff3ffe502fb59fc12c8d7982ff1338f8935fc1ed030cda47fa93a6341a3bfacee
7
- data.tar.gz: 83c5d9c5b80eb2e846627ed47e3649a5032d7e9ac2cc6dd607783d112c56700b9c11c32afa5bfb8cd36321edf546d28ee6cb4f7f8a6f6924a8f06c8f675df47f
6
+ metadata.gz: 6a7c5a17deebf100eb21fef88227ad3d191291ca3e98c38d52f57ddd64ad5c7b5dd46392951fa1874f7b4bcc5003d350cc2f9d601bc41ca48855bd6573d8cdf3
7
+ data.tar.gz: 44b22116af2f3c85ddf5b62bffc03d135f56f4e6b21519eaa9e075f6e0494c9b157bb29f8a6b6e22695b46c575d8c268fd47dfd0c70fcdcad93b6e899e382c8c
data/.rubocop.yml CHANGED
@@ -12,21 +12,53 @@ AllCops:
12
12
  Style/FileName:
13
13
  Enabled: false
14
14
 
15
+ # Metrics/CyclomaticComplexity:
16
+ # Max: 10
17
+
18
+ Metrics/LineLength:
19
+ Max: 160
20
+
21
+ # Metrics/MethodLength:
22
+ # Max: 50
23
+
24
+ # Metrics/AbcSize:
25
+ # Max: 25
26
+
15
27
  Metrics/ClassLength:
16
28
  Max: 250
17
29
 
30
+ # .find_each is not the same as .each
31
+ Rails/FindEach:
32
+ Enabled: false
33
+
18
34
  Style/AccessModifierIndentation:
19
35
  EnforcedStyle: outdent
20
36
 
37
+ Style/AlignParameters:
38
+ EnforcedStyle: with_fixed_indentation
39
+
21
40
  Style/ClassAndModuleChildren:
22
41
  EnforcedStyle: compact
23
42
 
43
+ Style/ConditionalAssignment:
44
+ Enabled: false
45
+
24
46
  Style/Documentation:
25
47
  Enabled: false
26
48
 
27
49
  Style/EmptyLines:
28
50
  Enabled: false
29
51
 
52
+ # Will report offences for many places that are much more readable without using a guard clause
53
+ Style/GuardClause:
54
+ Enabled: false
55
+
56
+ Style/MultilineMethodCallIndentation:
57
+ EnforcedStyle: indented
58
+
59
+ Style/MultilineOperationIndentation:
60
+ EnforcedStyle: indented
61
+
30
62
  Style/StringLiterals:
31
63
  EnforcedStyle: double_quotes
32
64
 
data/.rubocop_todo.yml CHANGED
@@ -1,24 +1,17 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2016-01-20 15:14:18 +0100 using RuboCop version 0.36.0.
3
+ # on 2016-08-27 14:26:22 +0200 using RuboCop version 0.36.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 6
9
+ # Offense count: 2
10
10
  # Configuration parameters: AllowSafeAssignment.
11
11
  Lint/AssignmentInCondition:
12
12
  Exclude:
13
13
  - 'lib/html_gen/parser.rb'
14
14
 
15
- # Offense count: 3
16
- # Cop supports --auto-correct.
17
- # Configuration parameters: AlignWith, SupportedStyles, AutoCorrect.
18
- # SupportedStyles: keyword, variable, start_of_line
19
- Lint/EndAlignment:
20
- Enabled: false
21
-
22
15
  # Offense count: 1
23
16
  Lint/UselessAssignment:
24
17
  Exclude:
@@ -26,33 +19,20 @@ Lint/UselessAssignment:
26
19
 
27
20
  # Offense count: 3
28
21
  Metrics/AbcSize:
29
- Max: 82
22
+ Max: 88
30
23
 
31
24
  # Offense count: 3
32
25
  Metrics/CyclomaticComplexity:
33
- Max: 35
34
-
35
- # Offense count: 3
36
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
37
- # URISchemes: http, https
38
- Metrics/LineLength:
39
- Max: 189
26
+ Max: 38
40
27
 
41
28
  # Offense count: 1
42
29
  # Configuration parameters: CountComments.
43
30
  Metrics/MethodLength:
44
- Max: 72
31
+ Max: 77
45
32
 
46
33
  # Offense count: 5
47
34
  Metrics/PerceivedComplexity:
48
- Max: 41
49
-
50
- # Offense count: 6
51
- # Configuration parameters: MinBodyLength.
52
- Style/GuardClause:
53
- Exclude:
54
- - 'lib/html_gen/element.rb'
55
- - 'lib/html_gen/parser.rb'
35
+ Max: 45
56
36
 
57
37
  # Offense count: 5
58
38
  Style/IdenticalConditionalBranches:
data/Gemfile CHANGED
@@ -12,7 +12,7 @@ group :development do
12
12
  gem "rspec", "~> 2.8.0"
13
13
  gem "rdoc", "~> 3.12"
14
14
  gem "bundler", ">= 1.0.0"
15
- gem "jeweler", "~> 1.8.4"
15
+ gem "jeweler", "~> 2.1"
16
16
  gem "best_practice_project", github: "kaspernj/best_practice_project", require: false
17
17
  gem "rubocop", require: false
18
18
  end
data/Gemfile.lock CHANGED
@@ -8,54 +8,60 @@ GIT
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- addressable (2.3.7)
11
+ addressable (2.4.0)
12
12
  ast (2.2.0)
13
13
  auto_autoloader (0.0.4)
14
14
  string-cases
15
15
  builder (3.2.2)
16
16
  codeclimate-test-reporter (0.4.6)
17
17
  simplecov (>= 0.7.1, < 1.0.0)
18
+ descendants_tracker (0.0.4)
19
+ thread_safe (~> 0.3, >= 0.3.1)
18
20
  diff-lcs (1.1.3)
19
21
  docile (1.1.5)
20
- faraday (0.8.9)
21
- multipart-post (~> 1.2.0)
22
- git (1.2.9.1)
23
- github_api (0.10.1)
24
- addressable
25
- faraday (~> 0.8.1)
26
- hashie (>= 1.2)
27
- multi_json (~> 1.4)
28
- nokogiri (~> 1.5.2)
29
- oauth2
30
- hashie (3.4.0)
31
- highline (1.6.21)
32
- jeweler (1.8.8)
22
+ faraday (0.9.2)
23
+ multipart-post (>= 1.2, < 3)
24
+ git (1.3.0)
25
+ github_api (0.14.5)
26
+ addressable (~> 2.4.0)
27
+ descendants_tracker (~> 0.0.4)
28
+ faraday (~> 0.8, < 0.10)
29
+ hashie (>= 3.4)
30
+ oauth2 (~> 1.0)
31
+ hashie (3.4.4)
32
+ highline (1.7.8)
33
+ jeweler (2.1.1)
33
34
  builder
34
- bundler (~> 1.0)
35
+ bundler (>= 1.0)
35
36
  git (>= 1.2.5)
36
- github_api (= 0.10.1)
37
+ github_api
37
38
  highline (>= 1.6.15)
38
- nokogiri (= 1.5.10)
39
+ nokogiri (>= 1.5.10)
39
40
  rake
40
41
  rdoc
42
+ semver
41
43
  json (1.8.2)
42
- jwt (1.2.1)
44
+ jwt (1.5.4)
45
+ mini_portile2 (2.1.0)
43
46
  multi_json (1.10.1)
44
47
  multi_xml (0.5.5)
45
- multipart-post (1.2.0)
46
- nokogiri (1.5.10)
47
- oauth2 (1.0.0)
48
+ multipart-post (2.0.0)
49
+ nokogiri (1.6.8)
50
+ mini_portile2 (~> 2.1.0)
51
+ pkg-config (~> 1.1.7)
52
+ oauth2 (1.2.0)
48
53
  faraday (>= 0.8, < 0.10)
49
54
  jwt (~> 1.0)
50
55
  multi_json (~> 1.3)
51
56
  multi_xml (~> 0.5)
52
- rack (~> 1.2)
57
+ rack (>= 1.2, < 3)
53
58
  parser (2.3.0.1)
54
59
  ast (~> 2.2)
60
+ pkg-config (1.1.7)
55
61
  powerpack (0.1.1)
56
- rack (1.6.0)
62
+ rack (2.0.1)
57
63
  rainbow (2.0.0)
58
- rake (10.4.2)
64
+ rake (11.2.2)
59
65
  rdoc (3.12.2)
60
66
  json (~> 1.4)
61
67
  rspec (2.8.0)
@@ -72,12 +78,14 @@ GEM
72
78
  rainbow (>= 1.99.1, < 3.0)
73
79
  ruby-progressbar (~> 1.7)
74
80
  ruby-progressbar (1.7.5)
81
+ semver (1.0.1)
75
82
  simplecov (0.9.1)
76
83
  docile (~> 1.1.0)
77
84
  multi_json (~> 1.0)
78
85
  simplecov-html (~> 0.8.0)
79
86
  simplecov-html (0.8.0)
80
87
  string-cases (0.0.0)
88
+ thread_safe (0.3.5)
81
89
 
82
90
  PLATFORMS
83
91
  ruby
@@ -86,11 +94,11 @@ DEPENDENCIES
86
94
  best_practice_project!
87
95
  bundler (>= 1.0.0)
88
96
  codeclimate-test-reporter
89
- jeweler (~> 1.8.4)
97
+ jeweler (~> 2.1)
90
98
  rdoc (~> 3.12)
91
99
  rspec (~> 2.8.0)
92
100
  rubocop
93
101
  string-cases
94
102
 
95
103
  BUNDLED WITH
96
- 1.11.2
104
+ 1.12.5
data/README.md CHANGED
@@ -28,6 +28,11 @@ p.add_str "Test"
28
28
  div.html #=> '<div width="100px" style="height: 50px;" class="class1 class2">Hello world<p>Test</p></div>'
29
29
  ```
30
30
 
31
+ With text in initializer:
32
+ ```ruby
33
+ HtmlGen::Element.new(:div, str: "Hello world")
34
+ ```
35
+
31
36
  ### Parse HTML into elements
32
37
 
33
38
  ```ruby
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.12
1
+ 0.0.13
data/html_gen.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: html_gen 0.0.12 ruby lib
5
+ # stub: html_gen 0.0.13 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "html_gen"
9
- s.version = "0.0.12"
9
+ s.version = "0.0.13"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Kasper Johansen"]
14
- s.date = "2016-02-04"
14
+ s.date = "2016-08-27"
15
15
  s.description = "A small framework for generating HTML."
16
16
  s.email = "k@spernj.org"
17
17
  s.extra_rdoc_files = [
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
41
41
  ]
42
42
  s.homepage = "http://github.com/kaspernj/html_gen"
43
43
  s.licenses = ["MIT"]
44
- s.rubygems_version = "2.4.0"
44
+ s.rubygems_version = "2.5.1"
45
45
  s.summary = "A small framework for generating HTML."
46
46
 
47
47
  if s.respond_to? :specification_version then
@@ -52,7 +52,7 @@ Gem::Specification.new do |s|
52
52
  s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
53
53
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
54
54
  s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
55
- s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
55
+ s.add_development_dependency(%q<jeweler>, ["~> 2.1"])
56
56
  s.add_development_dependency(%q<best_practice_project>, [">= 0"])
57
57
  s.add_development_dependency(%q<rubocop>, [">= 0"])
58
58
  else
@@ -60,7 +60,7 @@ Gem::Specification.new do |s|
60
60
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
61
61
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
62
62
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
63
- s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
63
+ s.add_dependency(%q<jeweler>, ["~> 2.1"])
64
64
  s.add_dependency(%q<best_practice_project>, [">= 0"])
65
65
  s.add_dependency(%q<rubocop>, [">= 0"])
66
66
  end
@@ -69,7 +69,7 @@ Gem::Specification.new do |s|
69
69
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
70
70
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
71
71
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
72
- s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
72
+ s.add_dependency(%q<jeweler>, ["~> 2.1"])
73
73
  s.add_dependency(%q<best_practice_project>, [">= 0"])
74
74
  s.add_dependency(%q<rubocop>, [">= 0"])
75
75
  end
@@ -1,6 +1,6 @@
1
1
  # This class can be used to generate HTML.
2
2
  #===Examples
3
- # ele = HtmlGen::Element.new(:a) #=> #<HtmlGen::Element:0x00000000e5f650 @attr={}, @name=:a, @classes=[], @str_html="", @str="", @css={}, @eles=[], @nl="\n", @inden="\t">
3
+ # ele = HtmlGen::Element.new(:a) #=> #<HtmlGen::Element:0x00000000e5f650 @attr={}, @name=:a, @classes=[], @str_html="" ...>
4
4
  # ele.classes << "custom_link"
5
5
  # ele.css["font-weight"] = "bold"
6
6
  # ele.attr[:href] = "http://www.youtube.com"
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # ele.html #=> "<a href=\"http://www.youtube.com\" style=\"font-weight: bold;\" class=\"custom_link\">\n\t<b>\n\t\tTitle of link\n\t</b>\n</a>\n"
12
12
  class HtmlGen::Element
13
- FORBIDDEN_SHORT = ["script"].freeze
13
+ FORBIDDEN_SHORT = %w(div script span).freeze
14
14
 
15
15
  # Attributes hash which will be used to generate attributes-elements.
16
16
  #===Example
@@ -66,7 +66,7 @@ class HtmlGen::Element
66
66
  raise "'name' should be a string or a symbol but was a '#{name.class.name}'." if !name.is_a?(String) && !name.is_a?(Symbol)
67
67
  @name = name
68
68
 
69
- {attr: {}, data: {}, classes: [], str_html: "", str: "", css: {}, eles: [], nl: "\n", inden: "\t"}.each do |arg, default_val|
69
+ {attr: {}, data: {}, classes: [], str_html: "", str: "", css: {}, eles: [], nl: "\n", inden: " "}.each do |arg, default_val|
70
70
  if args[arg]
71
71
  instance_variable_set("@#{arg}", args[arg])
72
72
  else
@@ -126,7 +126,8 @@ class HtmlGen::Element
126
126
  # Used for keeping 'pretty'-value and correct indentation according to parent elements.
127
127
  pass_args = {level: (level + 1), pretty: pretty, inden: @inden}
128
128
 
129
- # Clone the attributes-hash since we are going to add stuff to it, and it shouldnt be reflected (if 'html' is called multiple times, it will bug unless we clone).
129
+ # Clone the attributes-hash since we are going to add stuff to it, and it shouldnt be reflected
130
+ # (if 'html' is called multiple times, it will bug unless we clone).
130
131
  attr = @attr.clone
131
132
 
132
133
  # Start generating the string with HTML (possible go give a custom 'str'-variable where the content should be pushed to).
@@ -102,7 +102,7 @@ private
102
102
  # Parses all attributes of the current tag.
103
103
  def parse_attr_of_tag(ele, tag_name)
104
104
  loop do
105
- if match = search(/\A\s*(\S+)=(\"|'|)/)
105
+ if (match = search(/\A\s*(\S+)=(\"|'|)/))
106
106
  attr_name = match[1]
107
107
  raise "Attribute already exists on element: '#{attr_name}'." if ele.attr.key?(attr_name)
108
108
 
@@ -160,16 +160,16 @@ private
160
160
  loop do
161
161
  if search(/\A\s*\Z/)
162
162
  raise "Could not find end of tag: '#{tag_name}'."
163
- elsif match = search(/\A\s*<\s*\/\s*#{Regexp.escape(tag_name)}\s*>\s*/i)
163
+ elsif (match = search(/\A\s*<\s*\/\s*#{Regexp.escape(tag_name)}\s*>\s*/i))
164
164
  puts "Found end: '#{match.to_a}' for '#{@eles_t.last.name}'." if @debug
165
165
  ele = @eles_t.pop
166
166
  raise "Expected ele-name to be: '#{tag_name}' but it wasnt: '#{ele.name}'." if ele.name.to_s != tag_name
167
167
 
168
168
  break
169
- elsif new_ele = parse_tag(false: true)
169
+ elsif (new_ele = parse_tag(false: true))
170
170
  puts "Found new element '#{new_ele.name}' and adding it to '#{ele.name}'." if @debug
171
171
  # ele.eles << new_ele
172
- elsif match = search(/\A(.+?)(<|\Z)/)
172
+ elsif (match = search(/\A(.+?)(<|\Z)/))
173
173
  puts "Text-content-match: '#{match.to_a}'." if @debug
174
174
 
175
175
  # Put end back into buffer.
@@ -2,7 +2,11 @@ require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
2
2
 
3
3
  describe "Parser" do
4
4
  let(:parser) { HtmlGen::Parser.new(str: "<html><head><title>Test</title></head><body>This is the body</body></html>") }
5
- let(:doc) { HtmlGen::Parser.new(str: "<td colspan=\"2\" data-test=\"test-value\" data-nested-test=\"test-nested-keys\" style=\"font-weight: bold;\" width='100px' height=50px>test</td>") }
5
+ let(:doc) do
6
+ HtmlGen::Parser.new(
7
+ str: "<td colspan=\"2\" data-test=\"test-value\" data-nested-test=\"test-nested-keys\" style=\"font-weight: bold;\" width='100px' height=50px>test</td>"
8
+ )
9
+ end
6
10
  let(:td) { doc.eles.first }
7
11
 
8
12
  it "detects a single root element" do
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe "HtmlGen" do
3
+ describe HtmlGen do
4
4
  it "generates elements with classes" do
5
5
  html = HtmlGen::Element.new(:td, classes: [:test]).html(pretty: false)
6
6
  html.should eq "<td class=\"test\" />"
@@ -67,6 +67,20 @@ describe "HtmlGen" do
67
67
  div_ele = HtmlGen::Element.new(:div)
68
68
  div_ele.add_str "test"
69
69
 
70
- div_ele.html.should eq "<div>\n\ttest\n</div>\n"
70
+ div_ele.html.should eq "<div>\n test\n</div>\n"
71
+ end
72
+
73
+ it "adds recursive sub elements correctly" do
74
+ progress = HtmlGen::Element.new(:div, classes: ["progress"])
75
+ progress_bar = progress.add_ele(:div, classes: ["progress-bar"])
76
+ progress_bar_text = progress.add_ele(:div, classes: ["bb-progress-bar-text"], str: "Test")
77
+
78
+ progress.eles.length.should eq 2
79
+ progress_bar.eles.length.should eq 0
80
+ progress_bar_text.eles.length.should eq 0
81
+
82
+ html = progress.html(pretty: false)
83
+
84
+ html.should eq "<div class=\"progress\"><div class=\"progress-bar\"></div><div class=\"bb-progress-bar-text\">Test</div></div>"
71
85
  end
72
86
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- if ENV['CODECLIMATE_REPO_TOKEN']
1
+ if ENV["CODECLIMATE_REPO_TOKEN"]
2
2
  require "codeclimate-test-reporter"
3
3
  CodeClimate::TestReporter.start
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Johansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-04 00:00:00.000000000 Z
11
+ date: 2016-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: string-cases
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.8.4
75
+ version: '2.1'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.8.4
82
+ version: '2.1'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: best_practice_project
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  requirements: []
157
157
  rubyforge_project:
158
- rubygems_version: 2.4.0
158
+ rubygems_version: 2.5.1
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: A small framework for generating HTML.