persie 0.0.1.alpha1 → 0.0.1.alpha.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.
- checksums.yaml +4 -4
- data/lib/persie/asciidoctor_ext/htmlbook.rb +82 -79
- data/lib/persie/asciidoctor_ext/spine_item_processor.rb +4 -1
- data/lib/persie/book.rb +9 -3
- data/lib/persie/builder.rb +14 -4
- data/lib/persie/builders/epub.rb +15 -289
- data/lib/persie/builders/mobi.rb +13 -11
- data/lib/persie/builders/multiple_htmls.rb +87 -0
- data/lib/persie/builders/pdf.rb +15 -14
- data/lib/persie/builders/{site.rb → single_html.rb} +21 -38
- data/lib/persie/chunkable.rb +255 -0
- data/lib/persie/cli.rb +10 -6
- data/lib/persie/generator.rb +8 -8
- data/lib/persie/gepub_ext.rb +88 -0
- data/lib/persie/server.rb +2 -2
- data/lib/persie/ui.rb +13 -13
- data/lib/persie/version.rb +1 -1
- data/spec/build_epub_cmd_spec.rb +70 -0
- data/spec/{build_pdf_command_spec.rb → build_pdf_cmd_spec.rb} +7 -3
- data/spec/new_cmd_spec.rb +78 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/{version_command_spec.rb → version_cmd_spec.rb} +0 -0
- data/templates/{Gemfile.txt → Gemfile.erb} +1 -1
- data/templates/stylesheets/html.css +1 -0
- metadata +15 -12
- data/spec/new_command_spec.rb +0 -57
- data/spec/pdf_builder_spec.rb +0 -39
- data/templates/stylesheets/site.css +0 -1
data/lib/persie/cli.rb
CHANGED
@@ -41,7 +41,7 @@ module Persie
|
|
41
41
|
g.invoke_all
|
42
42
|
end
|
43
43
|
|
44
|
-
desc 'build FORMAT', 'Build a ebook format, including pdf, epub, mobi and
|
44
|
+
desc 'build FORMAT', 'Build a ebook format, including pdf, epub, mobi and html'
|
45
45
|
method_option :debug, aliases: '-d',
|
46
46
|
type: :boolean,
|
47
47
|
desc: 'Debug mode'
|
@@ -55,7 +55,7 @@ module Persie
|
|
55
55
|
desc: 'Base url for site'
|
56
56
|
method_option :multiple, aliases: '-m',
|
57
57
|
type: :boolean,
|
58
|
-
desc: 'Chunk
|
58
|
+
desc: 'Chunk HTML to multiple pages'
|
59
59
|
def build(format)
|
60
60
|
unless valid_book?
|
61
61
|
$stderr.puts 'Not a valid presie project.'.colorize(:red)
|
@@ -70,17 +70,21 @@ module Persie
|
|
70
70
|
book.build_epub(options)
|
71
71
|
when 'mobi'
|
72
72
|
book.build_mobi(options)
|
73
|
-
when '
|
74
|
-
|
73
|
+
when 'html'
|
74
|
+
if options.multiple?
|
75
|
+
book.build_multiple_htmls(options)
|
76
|
+
else
|
77
|
+
book.build_single_html(options)
|
78
|
+
end
|
75
79
|
else
|
76
80
|
$stderr.puts 'Do not support build this formats.'.colorize(:red)
|
77
81
|
end
|
78
82
|
end
|
79
83
|
|
80
|
-
desc 'preview [FORMAT]', 'Preview
|
84
|
+
desc 'preview [FORMAT]', 'Preview HTML on a local server'
|
81
85
|
def preview(format)
|
82
86
|
unless ['single', 'multiple'].include? format
|
83
|
-
$stderr.puts 'Only supports preview "single" page or "multiple" pages
|
87
|
+
$stderr.puts 'Only supports preview "single" page or "multiple" pages HTML'.colorize(:red)
|
84
88
|
exit 51
|
85
89
|
end
|
86
90
|
|
data/lib/persie/generator.rb
CHANGED
@@ -21,7 +21,7 @@ module Persie
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def copy_gemfile
|
24
|
-
|
24
|
+
template 'Gemfile.erb', 'Gemfile'
|
25
25
|
end
|
26
26
|
|
27
27
|
def copy_book_files
|
@@ -33,7 +33,7 @@ module Persie
|
|
33
33
|
def create_theme_dirs
|
34
34
|
empty_directory 'themes/pdf'
|
35
35
|
empty_directory 'themes/epub'
|
36
|
-
empty_directory 'themes/
|
36
|
+
empty_directory 'themes/html'
|
37
37
|
end
|
38
38
|
|
39
39
|
def create_build_dir
|
@@ -43,8 +43,8 @@ module Persie
|
|
43
43
|
def copy_stylesheets
|
44
44
|
copy_file 'stylesheets/pdf.css', 'themes/pdf/pdf.css'
|
45
45
|
copy_file 'stylesheets/epub.css', 'themes/epub/epub.css'
|
46
|
-
copy_file 'stylesheets/
|
47
|
-
copy_file 'stylesheets/
|
46
|
+
copy_file 'stylesheets/html.css', 'builds/html/single/style.css'
|
47
|
+
copy_file 'stylesheets/html.css', 'builds/html/multiple/style.css'
|
48
48
|
end
|
49
49
|
|
50
50
|
def create_tmp_dir
|
@@ -55,10 +55,6 @@ module Persie
|
|
55
55
|
empty_directory 'images'
|
56
56
|
end
|
57
57
|
|
58
|
-
def create_plugins_dir
|
59
|
-
empty_directory 'plugins'
|
60
|
-
end
|
61
|
-
|
62
58
|
private
|
63
59
|
|
64
60
|
def uuid
|
@@ -69,5 +65,9 @@ module Persie
|
|
69
65
|
Time.now.iso8601
|
70
66
|
end
|
71
67
|
|
68
|
+
def version
|
69
|
+
VERSION
|
70
|
+
end
|
71
|
+
|
72
72
|
end
|
73
73
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Persie
|
2
|
+
module GepubBuilderMixin
|
3
|
+
|
4
|
+
FromHtmlSpecialCharsMap = {
|
5
|
+
'<' => '<',
|
6
|
+
'>' => '>',
|
7
|
+
'&' => '&'
|
8
|
+
}
|
9
|
+
FromHtmlSpecialCharsRx = /(?:#{FromHtmlSpecialCharsMap.keys * '|'})/
|
10
|
+
WordJoinerRx = [65279].pack 'U*'
|
11
|
+
CsvDelimiterRx = /\s*,\s*/
|
12
|
+
|
13
|
+
def sanitized_title(title, target = :plain)
|
14
|
+
return (@doc.attr 'untitled-label') unless @doc.header?
|
15
|
+
|
16
|
+
builder = self
|
17
|
+
|
18
|
+
title = case target
|
19
|
+
when :attribute_cdata
|
20
|
+
builder.sanitize(title).gsub('"', '"')
|
21
|
+
when :element_cdata
|
22
|
+
builder.sanitize(title)
|
23
|
+
when :pcdata
|
24
|
+
title
|
25
|
+
when :plain
|
26
|
+
builder.sanitize(title).gsub(FromHtmlSpecialCharsRx, FromHtmlSpecialCharsMap)
|
27
|
+
end
|
28
|
+
|
29
|
+
title.gsub WordJoinerRx, ''
|
30
|
+
end
|
31
|
+
|
32
|
+
def sanitize(text)
|
33
|
+
if text.include?('<')
|
34
|
+
text.gsub(::Asciidoctor::XmlSanitizeRx, '').tr_s(' ', ' ').strip
|
35
|
+
else
|
36
|
+
text
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def authors
|
41
|
+
if (auts = @doc.attr 'authors')
|
42
|
+
auts.split(CsvDelimiterRx)
|
43
|
+
else
|
44
|
+
[]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_theme_assets
|
49
|
+
resources(workdir: @theme_dir) do
|
50
|
+
file 'epub.css' if File.exist?('epub.css')
|
51
|
+
glob 'fonts/*.*'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_cover_image
|
56
|
+
image = @doc.attr('epub-cover-image', 'cover.png')
|
57
|
+
image = File.basename(image) # incase you set this a path
|
58
|
+
|
59
|
+
resources(workdir: @theme_dir) do
|
60
|
+
cover_image image if File.exist? image
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
def add_images
|
66
|
+
resources(workdir: @base_dir) do
|
67
|
+
glob 'images/*.*'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_content
|
72
|
+
builder = self
|
73
|
+
spine_items = @spine_items
|
74
|
+
spine_item_titles = @spine_item_titles
|
75
|
+
resources(workdir: @tmp_dir) do
|
76
|
+
nav 'nav.xhtml' if @has_toc
|
77
|
+
|
78
|
+
ordered do
|
79
|
+
spine_items.each_with_index do |item, i|
|
80
|
+
file "#{item}.xhtml"
|
81
|
+
heading builder.sanitized_title(spine_item_titles[i])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
data/lib/persie/server.rb
CHANGED
@@ -6,14 +6,14 @@ module Persie
|
|
6
6
|
include WEBrick
|
7
7
|
|
8
8
|
def self.start(dir)
|
9
|
-
destination = File.join(Dir.pwd, 'builds', '
|
9
|
+
destination = File.join(Dir.pwd, 'builds', 'html', dir)
|
10
10
|
|
11
11
|
# recreate NondisclosureName under utf-8 circumstance
|
12
12
|
fh_option = WEBrick::Config::FileHandler
|
13
13
|
fh_option[:NondisclosureName] = ['.ht*','~*']
|
14
14
|
|
15
15
|
s = HTTPServer.new(
|
16
|
-
:Port => 9527,
|
16
|
+
:Port => 9527, # go to get Qiuxiang
|
17
17
|
:BindAddress => '0.0.0.0',
|
18
18
|
)
|
19
19
|
|
data/lib/persie/ui.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
require 'colorize'
|
2
2
|
|
3
3
|
module Persie
|
4
|
-
|
4
|
+
module UI
|
5
5
|
|
6
|
-
def
|
7
|
-
|
6
|
+
def info(msg, new_line=nil)
|
7
|
+
$stdout.puts msg
|
8
|
+
$stdout.puts if new_line
|
8
9
|
end
|
9
10
|
|
10
|
-
def
|
11
|
-
$stdout.puts msg
|
11
|
+
def confirm(msg, new_line=nil)
|
12
|
+
$stdout.puts msg.colorize(:green)
|
13
|
+
$stdout.puts if new_line
|
12
14
|
end
|
13
15
|
|
14
|
-
def
|
15
|
-
$
|
16
|
+
def error(msg, new_line=nil)
|
17
|
+
$stderr.puts msg.colorize(:red)
|
18
|
+
$stderr.puts if new_line
|
16
19
|
end
|
17
20
|
|
18
|
-
def
|
19
|
-
$
|
20
|
-
|
21
|
-
|
22
|
-
def warning(msg)
|
23
|
-
$stdout.puts msg.colorize(:yellow) unless @test_mode
|
21
|
+
def warning(msg, new_line=nil)
|
22
|
+
$stdout.puts msg.colorize(:yellow)
|
23
|
+
$stdout.puts if new_line
|
24
24
|
end
|
25
25
|
|
26
26
|
end
|
data/lib/persie/version.rb
CHANGED
@@ -0,0 +1,70 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Cli#build(epub)' do
|
4
|
+
|
5
|
+
it 'generates a epub file' do
|
6
|
+
FileUtils.cd(A_BOOK_PATH) do
|
7
|
+
persie_command 'build epub'
|
8
|
+
path = 'builds/epub/a-book.epub'
|
9
|
+
|
10
|
+
expect(path).to be_exists
|
11
|
+
|
12
|
+
FileUtils.remove_dir('tmp/epub')
|
13
|
+
FileUtils.remove_dir('builds/epub')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'generates a sample pdf file when setting -s flag' do
|
18
|
+
FileUtils.cd(A_BOOK_PATH) do
|
19
|
+
persie_command 'build epub -s'
|
20
|
+
path = 'builds/epub/a-book-sample.epub'
|
21
|
+
|
22
|
+
expect(path).to be_exists
|
23
|
+
|
24
|
+
FileUtils.remove_dir('tmp/epub')
|
25
|
+
FileUtils.remove_dir('builds/epub')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'in tmp/epub directory' do
|
30
|
+
|
31
|
+
before(:all) do
|
32
|
+
@pwd = Dir.pwd
|
33
|
+
FileUtils.cd(A_BOOK_PATH)
|
34
|
+
persie_command 'build epub'
|
35
|
+
FileUtils.cd('tmp/epub')
|
36
|
+
end
|
37
|
+
|
38
|
+
after(:all) do
|
39
|
+
FileUtils.cd A_BOOK_PATH
|
40
|
+
FileUtils.remove_dir 'tmp/epub'
|
41
|
+
FileUtils.remove_dir 'builds/epub'
|
42
|
+
FileUtils.cd @pwd
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'has a a-book.html' do
|
46
|
+
expect('a-book.html').to be_exists
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'has a preface.xhtml' do
|
50
|
+
expect('preface.xhtml').to be_exists
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'has a chapter1.xhtml' do
|
54
|
+
expect('chapter1.xhtml').to be_exists
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'has a chapter2.xhtml' do
|
58
|
+
expect('chapter2.xhtml').to be_exists
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'has a nav.xhtml' do
|
62
|
+
expect('nav.xhtml').to be_exists
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'has a titlepage.xhtml' do
|
66
|
+
expect('titlepage.xhtml').to be_exists
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -6,17 +6,21 @@ describe 'Cli#build(pdf)' do
|
|
6
6
|
FileUtils.cd(A_BOOK_PATH) do
|
7
7
|
persie_command 'build pdf'
|
8
8
|
path = 'builds/pdf/a-book.pdf'
|
9
|
-
|
9
|
+
|
10
|
+
expect(path).to be_exists
|
11
|
+
|
10
12
|
FileUtils.remove_dir('tmp/pdf')
|
11
13
|
FileUtils.remove_dir('builds/pdf')
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
15
|
-
it 'generates a sample pdf file' do
|
17
|
+
it 'generates a sample pdf file when setting -s flag' do
|
16
18
|
FileUtils.cd(A_BOOK_PATH) do
|
17
19
|
persie_command 'build pdf -s'
|
18
20
|
path = 'builds/pdf/a-book-sample.pdf'
|
19
|
-
|
21
|
+
|
22
|
+
expect(path).to be_exists
|
23
|
+
|
20
24
|
FileUtils.remove_dir('tmp/pdf')
|
21
25
|
FileUtils.remove_dir('builds/pdf')
|
22
26
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Cli#new' do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@book_slug = 'sample-book'
|
7
|
+
@tmp_dir = File.join(::Persie::GEM_ROOT, 'tmp')
|
8
|
+
@book_dir = File.join(@tmp_dir, @book_slug)
|
9
|
+
@pwd = Dir.pwd
|
10
|
+
|
11
|
+
FileUtils.mkdir_p(@tmp_dir) unless Dir.exist? @tmp_dir
|
12
|
+
|
13
|
+
FileUtils.cd(@tmp_dir) do
|
14
|
+
persie_command "new #{@book_slug}"
|
15
|
+
end
|
16
|
+
|
17
|
+
FileUtils.cd @book_dir
|
18
|
+
end
|
19
|
+
|
20
|
+
after(:all) do
|
21
|
+
FileUtils.remove_dir(@book_dir)
|
22
|
+
FileUtils.cd @pwd
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'generates a master file' do
|
26
|
+
expect(File.exist?('book.adoc')).to be true
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'generates a .gitignore' do
|
30
|
+
expect(File.exist?('.gitignore')).to be true
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'generates a Gemfile' do
|
34
|
+
expect(File.exist?('Gemfile')).to be true
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'puts correct persie version in Gemfile' do
|
38
|
+
content = File.read('Gemfile')
|
39
|
+
expect(content).to match(/gem 'persie', '(\d+\.\d+\.\d+\.?\w*?\.\d+)'/m)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'generates a themes directory' do
|
43
|
+
expect(Dir.exist?('themes')).to be true
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'generates a builds directory' do
|
47
|
+
expect(Dir.exist?('builds')).to be true
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'generates a images directory' do
|
51
|
+
expect(Dir.exist?('images')).to be true
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'generates a tmp directory' do
|
55
|
+
expect(Dir.exist?('tmp')).to be true
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'generates a pdf.css file' do
|
59
|
+
path = File.join 'themes', 'pdf', 'pdf.css'
|
60
|
+
expect(File.exist? path).to be true
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'generates a epub.css file' do
|
64
|
+
path = File.join 'themes', 'epub', 'epub.css'
|
65
|
+
expect(File.exist? path).to be true
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'generates a style.css file for single html' do
|
69
|
+
path = File.join 'builds', 'html', 'single', 'style.css'
|
70
|
+
expect(File.exist? path).to be true
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'generates a style.css file for multiple htmls' do
|
74
|
+
path = File.join 'builds', 'html', 'multiple', 'style.css'
|
75
|
+
expect(File.exist? path).to be true
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,10 +3,22 @@ require 'persie'
|
|
3
3
|
SPEC_FIXTURES_PATH = File.join(File.dirname(__FILE__), 'fixtures')
|
4
4
|
A_BOOK_PATH = File.join(SPEC_FIXTURES_PATH, 'a-book')
|
5
5
|
|
6
|
+
# add a custom matcher, named `be_exists'
|
7
|
+
RSpec::Matchers.define :be_exists do |expected|
|
8
|
+
match do |path|
|
9
|
+
File.exist?(path)
|
10
|
+
end
|
11
|
+
failure_message do |path|
|
12
|
+
"expected #{path} file/directory exists"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# run a persie command
|
6
17
|
def persie_command(cmd)
|
7
18
|
`#{::Persie::GEM_ROOT}/bin/persie #{cmd}`.chomp
|
8
19
|
end
|
9
20
|
|
21
|
+
# render inline Asciidoc string
|
10
22
|
def render_string(src, opts = {})
|
11
23
|
opts[:doctype] = 'inline' unless opts.has_key? :doctype
|
12
24
|
opts[:backend] = 'htmlbook' unless opts.has_key? :backend
|
File without changes
|