koara-html 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02ebb08b95d1da308309f5717b39479b63ff80c0
4
- data.tar.gz: fc16e33d4a9c6ecb8be06db555a270db7abba6ef
3
+ metadata.gz: 739e30bab2a27055ab39b935c21f8612acb27958
4
+ data.tar.gz: f76f2319a2f399d76bf4995113b8f44ffbca7245
5
5
  SHA512:
6
- metadata.gz: 2ac2552515a083be2dadc5970b402eacadae6424515a87b0606da2cf1661140af0a3143313a3c219e1a6dc2c58452db2198bb2360486f77ebd90622bcbad6e9b
7
- data.tar.gz: e61f9823ee8398fec1a8b98da0bb8ed2939073cba545e5259287e94950ac835b7d3e11b864742190a11d8dae0e3b1fb30a04481ffedaa7ec1786a209eacc0d48
6
+ metadata.gz: 409e1cf06d5ff6af81c46f4ded7594f7b96be04af506d4c6817f0ca4b1c54ec0e72dbcfdb1776ba8e72d85ea384b5214ce3e65d41cc8444102b9e331455c6c7c
7
+ data.tar.gz: 8b62c6a170fc9427ca8203dbcd7b35ba63eea6cfc727d0bcad6f370bdb2b999a60d5c211b071ad670f9adc06ea6f854824e8dbaa1607adb90a2bdd61a51e6894
@@ -4,5 +4,5 @@ rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
6
  - 2.1
7
- - jruby-19mode
8
- - rbx-2
7
+ - 2.2
8
+ - jruby-19mode
data/Gemfile CHANGED
@@ -1,6 +1,10 @@
1
1
  source "https://rubygems.org/"
2
2
 
3
3
  gem "koara", "~>0.13.0"
4
+ gem 'rake', '>= 0.9'
5
+ gem 'minitest', '5.10.1', require: false
4
6
  gem 'coveralls', '0.8.13', require: false
7
+ gem 'term-ansicolor', '1.3.2', require: false
5
8
 
6
9
  gemspec
10
+
data/README.md CHANGED
@@ -10,11 +10,10 @@
10
10
  The AST is created by the [core koara parser](https://github.com/koara/koara-rb).
11
11
 
12
12
  ## Getting started
13
- - Gem
14
13
 
15
- ```bash
16
- gem install koara-html
17
- ```
14
+ ```bash
15
+ gem install koara-html
16
+ ```
18
17
 
19
18
  ## Usage
20
19
 
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ require 'rake/testtask'
8
8
  Rake::TestTask.new('test:unit') do |t|
9
9
  t.libs << 'lib'
10
10
  t.libs << 'test'
11
- t.pattern = 'test/*.rb'
11
+ t.pattern = 'test/html*.rb'
12
12
  t.verbose = true
13
13
  t.warning = false
14
14
  end
@@ -20,5 +20,6 @@ Gem::Specification.new do |s|
20
20
  s.test_files = s.files.grep(%r{^(test|features)/})
21
21
  s.require_paths = ["lib"]
22
22
 
23
- s.add_development_dependency 'rake', '~> 10.4', '>= 10.4.2'
23
+ s.add_development_dependency 'rake', '~> 1.4'
24
+ s.add_development_dependency 'bundler', '~> 1.2'
24
25
  end
@@ -3,6 +3,6 @@ require 'koara/html/html5renderer'
3
3
 
4
4
  module Koara
5
5
  module Html
6
- VERSION = '0.13.0'
6
+ VERSION = '0.14.0'
7
7
  end
8
8
  end
@@ -3,21 +3,33 @@ module Koara
3
3
  module Html
4
4
  class Html5Renderer
5
5
  attr_accessor :partial
6
+ attr_accessor :hard_wrap
7
+ attr_accessor :heading_ids
6
8
 
7
9
  def initialize
8
10
  @partial = true
11
+ @hard_wrap = false
12
+ @heading_ids = false
9
13
  end
10
14
 
11
15
  def visit_document(node)
12
16
  @level = 0
13
17
  @list_sequence = Array.new
14
18
  @out = StringIO.new
15
- @hard_wrap = false
16
19
  node.children_accept(self)
17
20
  end
18
21
 
19
22
  def visit_heading(node)
20
- @out << indent + '<h' + node.value.to_s + '>'
23
+ @out << indent + '<h' + node.value.to_s
24
+ if @heading_ids
25
+ id = ''
26
+ node.children.each do |n|
27
+ id << n.value.to_s
28
+ end
29
+
30
+ @out << " id=\"" + id.downcase.gsub(/ /, '_') + "\""
31
+ end
32
+ @out << '>'
21
33
  node.children_accept(self)
22
34
  @out << '</h' + node.value.to_s + ">\n"
23
35
  unless node.nested
@@ -5,16 +5,23 @@ require 'minitest/autorun'
5
5
  class Html5RendererTest < MiniTest::Unit::TestCase
6
6
 
7
7
  def setup
8
- parser = Koara::Parser.new
9
- @document = parser.parse('Test')
8
+ @parser = Koara::Parser.new
10
9
  @renderer = Koara::Html::Html5Renderer.new()
11
10
  end
12
11
 
13
- def test_basic
12
+ def test_render
13
+ @document = @parser.parse('Test')
14
14
  @document.accept(@renderer)
15
15
  assert_equal("<p>Test</p>", @renderer.output)
16
16
  end
17
17
 
18
+ def test_render_hardwrap_true
19
+ @renderer.hard_wrap = true;
20
+ @document = @parser.parse("a\nb")
21
+ @document.accept(@renderer)
22
+ assert_equal("<p>a<br>\nb</p>", @renderer.output)
23
+ end
24
+
18
25
  def test_no_partial_result
19
26
  expected = "<!DOCTYPE html>\n"
20
27
  expected << "<html>\n";
@@ -24,8 +31,23 @@ class Html5RendererTest < MiniTest::Unit::TestCase
24
31
  expected << "</html>\n";
25
32
 
26
33
  @renderer.partial = false;
34
+ @document = @parser.parse('Test')
27
35
  @document.accept(@renderer)
28
36
  assert_equal(expected, @renderer.output)
29
37
  end
30
38
 
39
+ def test_heading_ids_true
40
+ @renderer.heading_ids = true;
41
+ @document = @parser.parse('= A')
42
+ @document.accept(@renderer)
43
+ assert_equal("<h1 id=\"a\">A</h1>", @renderer.output)
44
+ end
45
+
46
+ def test_heading_ids_true_multiple_words
47
+ @renderer.heading_ids = true;
48
+ @document = @parser.parse('= This is a test')
49
+ @document.accept(@renderer)
50
+ assert_equal("<h1 id=\"this_is_a_test\">This is a test</h1>", @renderer.output)
51
+ end
52
+
31
53
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koara-html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Van Den Heuvel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-15 00:00:00.000000000 Z
11
+ date: 2016-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -16,20 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '10.4'
20
- - - '>='
21
- - !ruby/object:Gem::Version
22
- version: 10.4.2
19
+ version: '1.4'
23
20
  type: :development
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
29
- version: '10.4'
30
- - - '>='
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
31
39
  - !ruby/object:Gem::Version
32
- version: 10.4.2
40
+ version: '1.2'
33
41
  description: Koara to HTML parser written in Ruby
34
42
  email:
35
43
  - andy.vandenheuvel@gmail.com