nora_mark_htmlbook 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 403414959bbd4bf8b12cef8aa17a1061a65819cd
4
+ data.tar.gz: d578f9279eed2e7449bb37d8823af5d488904db3
5
+ SHA512:
6
+ metadata.gz: dfaf59d0d286891453acd711dfa3d78548c89498fd7e58c7d3eafc43cb2834a4c7a1e1b4ad66fbf14f6296948d8c8d8db38c9197f69db0e5d1445789a03c8c0a
7
+ data.tar.gz: 3892e9b97b2cdc2bde71c3e0b5d83289a218f0aa6825b40e9b6611ed427840ef2adef5583acee5d7f22816e8bcfde6cee4a5a5b1df8154f7cee7caec5649421a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.0
5
+ script: bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nora_mark_htmlbook.gemspec
4
+ gemspec
5
+ gem 'coveralls', require: false
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 KOJIMA Satoshi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Satoshi KOJIMA
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # NoraMark_HTMLBook
2
+
3
+ [<img src="https://secure.travis-ci.org/skoji/nora_mark_htmlbook.png" />](http://travis-ci.org/skoji/nora_mark_htmlbook)
4
+ [<img src="https://coveralls.io/repos/skoji/nora_mark_htmlbook/badge.png" />](https://coveralls.io/r/skoji/nora_mark_htmlbook)
5
+ [![Dependency Status](https://gemnasium.com/skoji/nora_mark_htmlbook.svg)](https://gemnasium.com/skoji/nora_mark_htmlbook)
6
+
7
+
8
+ [HTMLBook](https://github.com/oreillymedia/HTMLBook) generator plugin for [NoraMark](https://github.com/skoji/noramark)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'nora_mark_htmlbook'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install nora_mark_htmlbook
23
+
24
+ ## Usage
25
+
26
+ ### Explicitly load your code
27
+
28
+ ```ruby
29
+ require 'nora_mark'
30
+ require 'nora_mark_htmlbook'
31
+
32
+ NoraMark::Extensions.register_generator(NoraMark::Htmlbook::Generator)
33
+ puts NoraMark::Document.parse(markup_text).htmlbook
34
+ ```
35
+
36
+ ### Specify in frontmatter in the markup text
37
+
38
+ ```
39
+ ---
40
+ title: document title
41
+ generator: htmlbook
42
+ ---
43
+
44
+ # Chapter 1
45
+
46
+ Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
47
+
48
+ ## Section 1
49
+
50
+ Donec hendrerit tempor tellus. Donec pretium posuere tellus. Proin quam nisl, tincidunt et, mattis eget, convallis nec, purus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla posuere. Donec vitae dolor. Nullam tristique diam non turpis. Cras placerat accumsan nulla. Nullam rutrum. Nam vestibulum accumsan nisl.
51
+
52
+ ```
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it ( http://github.com/<my-github-username>/nora_mark_htmlbook/fork )
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
data/bin/nora2htmlbook ADDED
@@ -0,0 +1,16 @@
1
+ require 'nora_mark'
2
+ require 'nokogiri'
3
+ require 'optparse'
4
+ require 'kconv'
5
+
6
+ auto_convert_encode = false
7
+ opt = OptionParser.new
8
+ opt.on('--kconv') {
9
+ auto_convert_encode = true
10
+ }
11
+
12
+ args = opt.parse(ARGV)
13
+ input = ARGF.read
14
+ input = Kconv.toutf8(input) if auto_convert_encode
15
+ NoraMark::Extensions.register_generator(:htmlbook)
16
+ puts Nokogiri::XML(NoraMark::Document::parse(input).htmlbook, &:noblanks).to_xml
@@ -0,0 +1,21 @@
1
+ require 'nora_mark_htmlbook/transformer.rb'
2
+
3
+ module NoraMark
4
+ module Htmlbook
5
+ class Generator
6
+
7
+ def self.name
8
+ :htmlbook
9
+ end
10
+
11
+ def initialize(param = {})
12
+ @param = param
13
+ end
14
+
15
+ def convert(parsed_result, render_parameter = {})
16
+ parsed_result = Htmlbook.transformer.transform parsed_result
17
+ return NoraMark::Html::Generator.new(@param).convert(parsed_result, render_parameter.merge({nonpaged: true}))[0]
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,99 @@
1
+ module NoraMark
2
+ module Htmlbook
3
+ def self.section_bookelements
4
+ ['chapter',
5
+ 'appendix',
6
+ 'afterword',
7
+ 'bibliography',
8
+ 'glossary',
9
+ 'preface',
10
+ 'foreword',
11
+ 'introduction',
12
+ 'halftitlepage',
13
+ "titlepage",
14
+ "copyright-page",
15
+ "dedication",
16
+ "colophon",
17
+ "acknowledgments",
18
+ "afterword",
19
+ "conclusion",
20
+ "index",
21
+ ]
22
+ end
23
+
24
+ def self.admotions_regexp
25
+ /\A(note)|(warning)|(tip)|(caution)|(important)\z/
26
+ end
27
+
28
+ def self.transformer
29
+ TransformerFactory.create do
30
+ # body and title
31
+ modify type: :Root do
32
+ first_page = @node.first_child
33
+ first_page.add_attr 'data-type' => [ 'book' ]
34
+ title = @frontmatter.nil? ? nil : @frontmatter['title']
35
+ first_page.prepend_child(
36
+ block('h1', title)
37
+ ) unless title.nil?
38
+
39
+ end
40
+
41
+ # book component
42
+ modify 'part' do
43
+ @node.name = 'div'
44
+ @node.add_attr 'data-type' => ['part']
45
+ end
46
+
47
+ modify type: :HeadedSection do
48
+ if @node.level == 1
49
+ node_type = @node.p[0] || "chapter"
50
+ node_type = node_type.text unless node_type.is_a? String
51
+ if (Htmlbook.section_bookelements.member? node_type)
52
+ @node.add_attr 'data-type' => [ node_type ]
53
+ end
54
+ else
55
+ @node.level = @node.level - 1
56
+ @node.add_attr 'data-type' => [ "sect#{@node.level}" ]
57
+ end
58
+ end
59
+
60
+ # block elements
61
+ modify "sidebar" do
62
+ @node.name = "aside"
63
+ @node.add_attr "data-type" => ["sidebar"]
64
+ if !@node.p[0].nil?
65
+ @node.prepend_child block('h5', @node.p[0].text)
66
+ end
67
+ end
68
+
69
+ modify Htmlbook.admotions_regexp do
70
+ @node.add_attr "data-type" => [ @node.name ]
71
+ @node.name = 'div'
72
+ if !@node.p[0].nil?
73
+ @node.prepend_child block('h1', @node.p[0].text)
74
+ end
75
+ end
76
+
77
+ modify 'example' do
78
+ @node.name = 'div'
79
+ @node.add_attr "data-type" => [ 'example' ]
80
+ if !@node.p[0].nil?
81
+ @node.prepend_child block('h1', @node.p[0].text)
82
+ end
83
+ end
84
+
85
+ modify ({type: :PreformattedBlock}) do
86
+ if @node.name == 'code'
87
+ @node.add_attr "data-type" => ['programlisting']
88
+ @node.name = 'pre'
89
+ end
90
+ end
91
+
92
+ modify 'footnote' do
93
+ @node.name = 'span'
94
+ @node.add_attr "data-type" => ['footnote']
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,5 @@
1
+ module NoraMark
2
+ module Htmlbook
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "nora_mark_htmlbook/version"
2
+ require "nora_mark_htmlbook/generator"
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nora_mark_htmlbook/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nora_mark_htmlbook"
8
+ spec.version = NoraMark::Htmlbook::VERSION
9
+ spec.authors = ["Satoshi KOJIMA"]
10
+ spec.email = ["skoji@mac.com"]
11
+ spec.summary = %q{HTMLBook Generator plugin for NoraMark.}
12
+ spec.description = %q{HTMLBook Generator plugin for NoraMark.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "nora_mark", ">= 0.2beta11"
22
+ spec.add_runtime_dependency "nokogiri", "~> 1.6.0"
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rspec", "~> 2.14"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "byebug"
27
+
28
+ end
@@ -0,0 +1,229 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'nora_mark'
3
+ require File.dirname(__FILE__) + '/spec_helper.rb'
4
+ require 'nokogiri'
5
+ require File.dirname(__FILE__) + '/nokogiri_test_helper.rb'
6
+
7
+ $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
8
+
9
+ describe 'html_book plugin' do
10
+ describe 'explicitly load extension' do
11
+ before(:all) do
12
+ NoraMark::Extensions.register_generator(:htmlbook)
13
+ end
14
+ describe 'book component elements' do
15
+ it 'generate body with data-book' do
16
+ text = "---\ntitle: the title.\n---\ndocument."
17
+ parsed = NoraMark::Document.parse(text, lang: 'ja')
18
+ xhtml = parsed.htmlbook
19
+ body = Nokogiri::XML::Document.parse(xhtml).root.at_xpath('xmlns:body')
20
+ expect(body.selector_and_children)
21
+ .to eq(
22
+ ["body[data-type='book']",
23
+ ['h1', 'the title.'],
24
+ ['div.pgroup',
25
+ ['p', 'document.']]]
26
+ )
27
+ end
28
+ it 'generate chapter ' do
29
+ text = "---\ntitle: the title.\n---\n# chapter title\ndocument."
30
+ parsed = NoraMark::Document.parse(text, lang: 'ja')
31
+ xhtml = parsed.htmlbook
32
+ body = Nokogiri::XML::Document.parse(xhtml).root.at_xpath('xmlns:body')
33
+ expect(body.selector_and_children)
34
+ .to eq(
35
+ ["body[data-type='book']",
36
+ ['h1', 'the title.'],
37
+ ["section[data-type='chapter']",
38
+ ['h1', 'chapter title'],
39
+ ['div.pgroup',
40
+ ['p', 'document.']]]]
41
+ )
42
+ end
43
+ it 'generate chapter and section' do
44
+ text = "---\ntitle: the title.\n---\n# chapter title\n## section title\ndocument."
45
+ parsed = NoraMark::Document.parse(text, lang: 'ja')
46
+ xhtml = parsed.htmlbook
47
+ body = Nokogiri::XML::Document.parse(xhtml).root.at_xpath('xmlns:body')
48
+ expect(body.selector_and_children)
49
+ .to eq(
50
+ ["body[data-type='book']",
51
+ ['h1', 'the title.'],
52
+ ["section[data-type='chapter']",
53
+ ['h1', 'chapter title'],
54
+ ["section[data-type='sect1']",
55
+ ['h1', 'section title'],
56
+ ['div.pgroup',
57
+ ['p', 'document.']]]]]
58
+ )
59
+ end
60
+ it 'generate appendix and section' do
61
+ text = "---\ntitle: the title.\n---\n#(appendix) appendix title\n## section title\ndocument."
62
+ parsed = NoraMark::Document.parse(text, lang: 'ja')
63
+ xhtml = parsed.htmlbook
64
+ body = Nokogiri::XML::Document.parse(xhtml).root.at_xpath('xmlns:body')
65
+ expect(body.selector_and_children)
66
+ .to eq(
67
+ ["body[data-type='book']",
68
+ ['h1', 'the title.'],
69
+ ["section[data-type='appendix']",
70
+ ['h1', 'appendix title'],
71
+ ["section[data-type='sect1']",
72
+ ['h1', 'section title'],
73
+ ['div.pgroup',
74
+ ['p', 'document.']]]]]
75
+ )
76
+ end
77
+ it 'generate part' do
78
+ text = "part {\n# Chapter 1\n## Section 1\ndocument\n}"
79
+ parsed = NoraMark::Document.parse(text, lang: 'ja')
80
+ xhtml = parsed.htmlbook
81
+ body = Nokogiri::XML::Document.parse(xhtml).root.at_xpath('xmlns:body')
82
+ expect(body.selector_and_children)
83
+ .to eq(
84
+ ["body[data-type='book']",
85
+ ["div[data-type='part']",
86
+ ["section[data-type='chapter']",
87
+ ['h1', 'Chapter 1'],
88
+ ["section[data-type='sect1']",
89
+ ['h1', 'Section 1'],
90
+ ['div.pgroup',
91
+ ['p', 'document']]]]]]
92
+ )
93
+
94
+ end
95
+ end
96
+ describe 'block elements' do
97
+ it 'generate sidebar' do
98
+ text = <<EOF
99
+ ---
100
+ title: the title.
101
+ ---
102
+ sidebar(Amusing Digression) {
103
+ Did you know that in Boston, they call it "soda", and in Chicago, they call it "pop"?
104
+ }
105
+ EOF
106
+ parsed = NoraMark::Document.parse(text)
107
+ xhtml = parsed.htmlbook
108
+ body = Nokogiri::XML::Document.parse(xhtml).root.at_xpath('xmlns:body')
109
+ expect(body.selector_and_children)
110
+ .to eq(
111
+ ["body[data-type='book']",
112
+ ['h1', 'the title.'],
113
+ ["aside[data-type='sidebar']",
114
+ ['h5', 'Amusing Digression'],
115
+ ['p', 'Did you know that in Boston, they call it "soda", and in Chicago, they call it "pop"?']]]
116
+ )
117
+ end
118
+ it 'generate admotions' do
119
+ text = <<EOF
120
+ note(Helpful Info) {
121
+ Please take note of this important information
122
+ }
123
+ warning {
124
+ Make sure to get your AsciiDoc markup right!
125
+ }
126
+ EOF
127
+ parsed = NoraMark::Document.parse(text)
128
+ xhtml = parsed.htmlbook
129
+ body = Nokogiri::XML::Document.parse(xhtml).root.at_xpath('xmlns:body')
130
+ expect(body.selector_and_children)
131
+ .to eq(
132
+ ["body[data-type='book']",
133
+ ["div[data-type='note']",
134
+ ['h1', 'Helpful Info'],
135
+ ['p', 'Please take note of this important information']],
136
+ ["div[data-type='warning']",
137
+ ['p', 'Make sure to get your AsciiDoc markup right!']]]
138
+ )
139
+ end
140
+ it 'generate example' do
141
+ text = <<EOF
142
+ example(Hello World in Ruby) {
143
+ puts 'Hello, World'
144
+ }
145
+
146
+ EOF
147
+ parsed = NoraMark::Document.parse(text)
148
+ xhtml = parsed.htmlbook
149
+ body = Nokogiri::XML::Document.parse(xhtml).root.at_xpath('xmlns:body')
150
+ expect(body.selector_and_children)
151
+ .to eq(
152
+ ["body[data-type='book']",
153
+ ["div[data-type='example']",
154
+ ['h1', 'Hello World in Ruby'],
155
+ ['p', 'puts \'Hello, World\'']]]
156
+ )
157
+ end
158
+ it 'generate code listing' do
159
+ text = <<EOF
160
+ example(Hello World in Ruby) {
161
+ code {//ruby
162
+ puts 'Hello, World'
163
+ //}
164
+ }
165
+
166
+ EOF
167
+ parsed = NoraMark::Document.parse(text)
168
+ xhtml = parsed.htmlbook
169
+ body = Nokogiri::XML::Document.parse(xhtml).root.at_xpath('xmlns:body')
170
+ expect(body.selector_and_children)
171
+ .to eq(
172
+ ["body[data-type='book']",
173
+ ["div[data-type='example']",
174
+ ['h1', 'Hello World in Ruby'],
175
+ ["pre.code-ruby[data-type='programlisting'][data-code-language='ruby']",
176
+ "puts 'Hello, World'"]]]
177
+ )
178
+ end
179
+ end
180
+ describe 'inline element' do
181
+ it 'generate strikethrough etc.' do
182
+ text = <<EOF
183
+ Use your own data-type or class attributes for custom styling for formatting like [span[data-type:strikethrough]{strikethrough}]
184
+ EOF
185
+ parsed = NoraMark::Document.parse(text)
186
+ xhtml = parsed.htmlbook
187
+ body = Nokogiri::XML::Document.parse(xhtml).root.at_xpath('xmlns:body')
188
+ expect(body.selector_and_children)
189
+ .to eq(
190
+ ["body[data-type='book']",
191
+ ["p", 'Use your own data-type or class attributes for custom styling for formatting like ',
192
+ ["span[data-type='strikethrough']", 'strikethrough']]]
193
+ )
194
+ end
195
+ it 'generate footnote' do
196
+ text = <<EOF
197
+ Five out of every six people who try AsciiDoc prefer it to Markdown [footnote{Totally made-up statistic}]
198
+ EOF
199
+ parsed = NoraMark::Document.parse(text)
200
+ xhtml = parsed.htmlbook
201
+ body = Nokogiri::XML::Document.parse(xhtml).root.at_xpath('xmlns:body')
202
+ expect(body.selector_and_children)
203
+ .to eq(
204
+ ["body[data-type='book']",
205
+ ["p", 'Five out of every six people who try AsciiDoc prefer it to Markdown ', ["span[data-type='footnote']", "Totally made-up statistic"]]]
206
+ )
207
+ end
208
+ end
209
+ end
210
+ describe 'declare generator in the frontmatter' do
211
+ before(:each) do
212
+ NoraMark::Extensions.unregister_generator(:htmlbook)
213
+ end
214
+ it 'generate body with data-book' do
215
+ text = "---\ntitle: the title.\ngenerator: htmlbook\n---\ndocument."
216
+ parsed = NoraMark::Document.parse(text, lang: 'ja')
217
+ xhtml = parsed.htmlbook
218
+ body = Nokogiri::XML::Document.parse(xhtml).root.at_xpath('xmlns:body')
219
+ expect(body.selector_and_children)
220
+ .to eq(
221
+ ["body[data-type='book']",
222
+ ['h1', 'the title.'],
223
+ ['div.pgroup',
224
+ ['p', 'document.']]]
225
+ )
226
+ end
227
+
228
+ end
229
+ end
@@ -0,0 +1,41 @@
1
+ module Nokogiri
2
+ module XML
3
+ class Element
4
+ def selector remove_id: true
5
+ sel = name
6
+ if !remove_id && !self['id'].nil?
7
+ sel = sel + '#' + self['id'].split(' ').join('#')
8
+ end
9
+ if !self['class'].nil?
10
+ sel = sel + '.' + self['class'].split(' ').join('.')
11
+ end
12
+ attributes.select{|k,v| k != 'class' && k != 'id'}.each {
13
+ |name, value|
14
+ sel = sel + "[#{name}='#{value}']"
15
+ }
16
+ sel
17
+ end
18
+ def selector_and_text remove_id: true
19
+ [selector(remove_id: remove_id), text]
20
+ end
21
+ alias a selector_and_text
22
+ def child_loop
23
+ yield self
24
+ end
25
+ def child_a(index)
26
+ element_children[index].selector_and_text
27
+ end
28
+ def selector_and_children remove_id: true
29
+ [selector(remove_id: remove_id)] + children.select{|c| c.elem? || c.text.strip.size > 0}.map{|c|
30
+ if !c.elem?
31
+ c.text
32
+ elsif c.element_children.size == 0
33
+ c.selector_and_text remove_id: remove_id
34
+ else
35
+ c.selector_and_children remove_id: remove_id
36
+ end
37
+ }
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,47 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'byebug'
5
+
6
+ begin
7
+ require 'rspec'
8
+ rescue LoadError
9
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
10
+ gem 'rspec'
11
+ require 'spec'
12
+ end
13
+
14
+ RSpec.configure do |config|
15
+ # Use color in STDOUT
16
+ config.color_enabled = true
17
+ # Use color not only in STDOUT but also in pagers and files
18
+ config.tty = true
19
+ # Use the specified formatter
20
+ config.formatter = :documentation # :progress, :html, :textmate
21
+
22
+ def capture(stream)
23
+ begin
24
+ stream = stream.to_s
25
+ eval "$#{stream} = StringIO.new"
26
+ yield
27
+ result = eval("$#{stream}").string
28
+ ensure
29
+ eval "$#{stream} = #{stream.upcase}"
30
+ end
31
+ result
32
+ end
33
+
34
+ end
35
+
36
+ require 'rspec/core/formatters/base_text_formatter'
37
+ module RSpec
38
+ module Core
39
+ module Formatters
40
+ class DocumentationFormatter < BaseTextFormatter
41
+ # def green(text); color(text, "\e[42m") end
42
+ def red(text); color(text, "\e[41m") end
43
+ # def magenta(text); color(text, "\e[45m") end
44
+ end
45
+ end
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nora_mark_htmlbook
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Satoshi KOJIMA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nora_mark
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2beta11
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2beta11
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: HTMLBook Generator plugin for NoraMark.
98
+ email:
99
+ - skoji@mac.com
100
+ executables:
101
+ - nora2htmlbook
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/nora2htmlbook
113
+ - lib/nora_mark_htmlbook.rb
114
+ - lib/nora_mark_htmlbook/generator.rb
115
+ - lib/nora_mark_htmlbook/transformer.rb
116
+ - lib/nora_mark_htmlbook/version.rb
117
+ - nora_mark_htmlbook.gemspec
118
+ - spec/htmlbook_spec.rb
119
+ - spec/nokogiri_test_helper.rb
120
+ - spec/spec_helper.rb
121
+ homepage: ''
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.2.0
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: HTMLBook Generator plugin for NoraMark.
145
+ test_files:
146
+ - spec/htmlbook_spec.rb
147
+ - spec/nokogiri_test_helper.rb
148
+ - spec/spec_helper.rb