bookshelf 1.2.1 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ca72a0bb5534f5505ce7a5a4ae4c20711b083ec7
4
+ data.tar.gz: c979a59886cf912e078431ef202da4256c03d7bc
5
+ SHA512:
6
+ metadata.gz: 378336cfdd6f6658858b0a03c8a29efac014a33b6812ab3aa868c230e0ad572f6baa4b4df5357381f94803b37825ca1c5f83226d994bc1c2820889880dae6d63
7
+ data.tar.gz: e4094652e1759e850c1e14a79f89bc8e798e6c9ab28f74642c2ff2b65d030ab0a1735a1f76f7dd9b06460e29a14c3308e68d02309436ef717849282029da5187
@@ -1,35 +1,36 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bookshelf (1.0.4)
5
- RedCloth
4
+ bookshelf (1.2.3)
6
5
  activesupport
7
- coderay
8
- eeepub-with-cover-support
9
6
  i18n
7
+ maruku
10
8
  nokogiri
11
9
  notifier
12
- rdiscount
10
+ rubyzip
11
+ sass
13
12
  thor
14
13
 
15
14
  GEM
16
15
  remote: https://rubygems.org/
17
16
  specs:
18
- RedCloth (4.2.9)
19
- activesupport (3.2.12)
20
- i18n (~> 0.6)
21
- multi_json (~> 1.0)
17
+ activesupport (4.1.0)
18
+ i18n (~> 0.6, >= 0.6.9)
19
+ json (~> 1.7, >= 1.7.7)
20
+ minitest (~> 5.1)
21
+ thread_safe (~> 0.1)
22
+ tzinfo (~> 1.1)
22
23
  awesome_print (1.1.0)
23
- builder (3.2.0)
24
24
  coderay (1.0.9)
25
25
  diff-lcs (1.2.2)
26
- eeepub-with-cover-support (0.8.7)
27
- builder
28
- rubyzip
29
- i18n (0.6.4)
26
+ i18n (0.6.9)
27
+ json (1.8.1)
28
+ maruku (0.7.0)
30
29
  method_source (0.8.1)
31
- multi_json (1.7.2)
32
- nokogiri (1.5.9)
30
+ mini_portile (0.5.3)
31
+ minitest (5.3.2)
32
+ nokogiri (1.6.1)
33
+ mini_portile (~> 0.5.0)
33
34
  notifier (0.4.1)
34
35
  pry (0.9.12)
35
36
  coderay (~> 1.0.5)
@@ -38,7 +39,6 @@ GEM
38
39
  pry-nav (0.2.3)
39
40
  pry (~> 0.9.10)
40
41
  rake (10.0.4)
41
- rdiscount (2.0.7.1)
42
42
  rspec (2.13.0)
43
43
  rspec-core (~> 2.13.0)
44
44
  rspec-expectations (~> 2.13.0)
@@ -47,11 +47,15 @@ GEM
47
47
  rspec-expectations (2.13.0)
48
48
  diff-lcs (>= 1.1.3, < 2.0)
49
49
  rspec-mocks (2.13.0)
50
- rubyzip (0.9.9)
50
+ rubyzip (1.1.3)
51
+ sass (3.3.4)
51
52
  slop (3.4.4)
52
53
  test_notifier (1.0.1)
53
54
  notifier
54
- thor (0.18.1)
55
+ thor (0.19.1)
56
+ thread_safe (0.3.3)
57
+ tzinfo (1.1.0)
58
+ thread_safe (~> 0.1)
55
59
 
56
60
  PLATFORMS
57
61
  ruby
data/README.md CHANGED
@@ -3,9 +3,9 @@
3
3
  Bookshelf is a tool for the self-publishing of books. It is inspired by (and heavily based off) the excellent Kitabu gem [https://github.com/fnando/kitabu]().
4
4
 
5
5
  ## Features
6
- * Generate HTML, PDF, e-Pub, Mobi and Text files
6
+ * Generate HTML, PDF and ePub files
7
7
  * Multi book support
8
- * Write using Markdown, Textile or plain HTML
8
+ * Write using Markdown or plain HTML
9
9
  * Book layout support
10
10
  * Custom font support
11
11
  * SCSS support
@@ -26,12 +26,6 @@ dependencies.
26
26
  Prince XML: Converts HTML files into PDF files.
27
27
  Installed.
28
28
 
29
- KindleGen: Converts ePub e-books into .mobi files.
30
- Installed.
31
-
32
- html2text: Converts HTML documents into plain text.
33
- Not installed.
34
-
35
29
  There's no requirements here; just make sure you cleared the correct dependency based
36
30
  on the formats you want to export to.
37
31
 
@@ -60,31 +54,13 @@ This command creates a directory `my_book` with the following structure:
60
54
  │ ├── page.erb
61
55
  └── html
62
56
  └── layout.erb
63
-
57
+
64
58
 
65
59
  Update `my_book/config/config.yml` to reflect the books title, author and other attributes.
66
60
 
67
61
  ## Authoring
68
62
 
69
- Now, create the content for your book by creating markdown or textile files into the `my_bookshelf/books/my_book` directory. You have two options here but both are dependent on the numeric prefix assigned to the file to determine their order.
70
-
71
- *Option 1 - Directories for chapters:*
72
-
73
- my_book
74
- └── text
75
- ├── 01_introduction
76
- │ ├── 01_section_1.markdown
77
- │ ├── 02_section_2.markdown
78
- │ └── ...
79
- ├── 02_chapter_1
80
- │ ├── 01_section_1.markdown
81
- │ ├── 02_section_2.markdown
82
- │ └── ...
83
- ├── 03_chapter_2
84
- ├── 04_chapter_3
85
- └── ...
86
-
87
- *Option 2 - Files for chapters:*
63
+ Now, create the content for your book by creating markdown or html files into the `my_book/text` directory. The order is determined by the numeric prefix assigned to the file.
88
64
 
89
65
  my_book
90
66
  └── text
@@ -96,33 +72,20 @@ Now, create the content for your book by creating markdown or textile files into
96
72
 
97
73
  Note that you if the number of chapters in your book is likely to exceed 10, you should add an extra 0 to the front of the chapter directory/file names
98
74
 
99
- Note that you can use any format you want at the same time. Just use one of the following extensions: `.html`, `.markdown`, `.mkdn` or `.textile`.
75
+ Note that you can use any format you want at the same time. Just use one of the following extensions: `.html`, `.markdown`, `.mkdn` or `.md`
100
76
 
101
77
  ## Exporting
102
78
 
103
79
  You'll want to see your progress eventually; it's time for you to generate the book PDF. Just run the command `bookshelf export` and your book will be created in the `output` directory.
104
80
 
105
- Bookshelf can generate a Table of Contents (TOC) based on your `h2-h6` tags. The `h1` tag is discarded because it's meant to be the book title.
81
+ Bookshelf can generate a Table of Contents (TOC) based on your `h2` tags.
106
82
 
107
83
  To print the TOC, you need to print a variable called `toc`, using the eRb tag.
108
84
 
109
85
  <%= toc %>
110
86
 
111
- ## Markdown Processors
112
-
113
- By default, RDiscount[http://github.com/rtomayko/rdiscount/tree/master] is the Markdown processor. However, you can switch to different implementations by simply installing any of the following processors:
114
-
115
- * Maruku: https://rubygems.org/gems/maruku
116
- * PEGMarkdown: https://rubygems.org/gems/rpeg-markdown
117
- * BlueCloth: https://rubygems.org/gems/bluecloth
118
- * Redcarpet: https://rubygems.org/gems/redcarpet
119
-
120
- Note: RDiscount will always be installed as Bookshelf's dependency but only used when no
121
- alternative library is available.
122
-
123
87
  ## References
124
88
 
125
- * Textile: http://hobix.com/textile
126
89
  * Markdown: http://daringfireball.net/projects/markdown/syntax
127
90
 
128
91
  ## License
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.authors = ["Brad Crawford"]
11
11
  s.email = ["brad.robert.crawford@gmail.com"]
12
12
  s.homepage = "https://bitbucket.org/bradcrawford/bookshelf"
13
- s.summary = "A framework that generates PDF and e-Pub from Markdown, Textile, and HTML files."
13
+ s.summary = "A framework that generates PDF and e-Pub from Markdown, and HTML files."
14
14
  s.description = s.summary
15
15
  s.license = "MIT"
16
16
 
@@ -21,13 +21,12 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.add_dependency "activesupport"
23
23
  s.add_dependency "nokogiri"
24
- s.add_dependency "RedCloth"
25
- s.add_dependency "rdiscount"
24
+ s.add_dependency "maruku"
26
25
  s.add_dependency "i18n"
27
26
  s.add_dependency "thor"
28
- s.add_dependency "eeepub-with-cover-support"
29
27
  s.add_dependency "notifier"
30
28
  s.add_dependency "sass"
29
+ s.add_dependency "rubyzip"
31
30
 
32
31
  s.add_development_dependency "rspec"
33
32
  s.add_development_dependency "test_notifier"
@@ -1,6 +1,5 @@
1
1
  require "active_support/all"
2
2
  require "digest/md5"
3
- require "eeepub"
4
3
  require "erb"
5
4
  require "logger"
6
5
  require "nokogiri"
@@ -8,42 +7,26 @@ require "notifier"
8
7
  require "open3"
9
8
  require "optparse"
10
9
  require "ostruct"
11
- require "RedCloth"
12
10
  require "tempfile"
13
11
  require "pathname"
14
12
  require "thor"
15
13
  require "thor/group"
16
14
  require "yaml"
17
15
  require "cgi"
18
-
19
- %w[maruku peg_markdown bluecloth redcarpet rdiscount].each do |lib|
20
- begin
21
- require lib
22
- break
23
- rescue LoadError => e
24
- next
25
- end
26
- end
16
+ require "maruku"
27
17
 
28
18
  Encoding.default_internal = "utf-8"
29
19
  Encoding.default_external = "utf-8"
30
20
 
31
21
  module Bookshelf
32
- require "bookshelf/extensions/string"
33
- require "bookshelf/extensions/redcloth"
34
- require "bookshelf/errors"
35
-
36
22
  ROOT = Pathname.new(File.dirname(__FILE__) + "/..")
37
23
 
38
24
  autoload :Version, "bookshelf/version"
39
25
  autoload :Generator, "bookshelf/generator"
40
- autoload :TOC, "bookshelf/toc"
41
26
  autoload :Cli, "bookshelf/cli"
42
27
  autoload :Markdown, "bookshelf/adapters/markdown"
43
28
  autoload :Parser, "bookshelf/parser"
44
29
  autoload :Exporter, "bookshelf/exporter"
45
- autoload :Syntax, "bookshelf/syntax"
46
- autoload :Stream, "bookshelf/stream"
47
30
  autoload :Dependency, "bookshelf/dependency"
48
31
  autoload :Stats, "bookshelf/stats"
49
32
 
@@ -61,4 +44,8 @@ module Bookshelf
61
44
  def self.root_dir
62
45
  @root_dir ||= Pathname.new(Dir.pwd)
63
46
  end
47
+
48
+ def self.render_template(file, locals = {})
49
+ ERB.new(File.read(file)).result OpenStruct.new(locals).instance_eval{ binding }
50
+ end
64
51
  end
@@ -1,34 +1,16 @@
1
1
  module Bookshelf
2
2
  class Markdown
3
3
  # Supported Markdown libraries
4
- #
5
- MARKDOWN_LIBRARIES = %w[Maruku BlueCloth PEGMarkdown Redcarpet RDiscount]
4
+ MARKDOWN_LIBRARIES = %w[Maruku]
6
5
 
7
6
  # Retrieve preferred Markdown processor.
8
- # You'll need one of the following libraries:
9
- #
10
- # # RDiscount: https://rubygems.org/gems/rdiscount
11
- # # Maruku: https://rubygems.org/gems/maruku
12
- # # PEGMarkdown: https://rubygems.org/gems/rpeg-markdown
13
- # # BlueCloth: https://rubygems.org/gems/bluecloth
14
- # # Redcarpet: https://rubygems.org/gems/redcarpet
15
- #
16
- # Note: RDiscount will always be installed as Bookshelf's dependency but only used when no
17
- # alternative library is available.
18
- #
19
7
  def self.engine
20
8
  @engine ||= Object.const_get(MARKDOWN_LIBRARIES.find {|lib| Object.const_defined?(lib)})
21
9
  end
22
10
 
23
11
  # Convert Markdown to HTML.
24
12
  def self.to_html(content)
25
- case engine.name
26
- when "Redcarpet"
27
- render = Redcarpet::Render::HTML.new(:hard_wrap => true, :xhtml => true)
28
- Redcarpet::Markdown.new(render).render(content)
29
- else
30
- engine.new(content).to_html
31
- end
13
+ engine.new(content).to_html
32
14
  end
33
15
  end
34
16
  end
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  module Bookshelf
3
3
  class Cli < Thor
4
- FORMATS = %w[pdf html epub mobi txt]
4
+ FORMATS = %w[pdf html epub]
5
5
  check_unknown_options!
6
6
 
7
7
  def self.exit_on_failure?
@@ -53,16 +53,6 @@ module Bookshelf
53
53
  :installed => Bookshelf::Dependency.prince?
54
54
  }
55
55
 
56
- result << {
57
- :description => "KindleGen: Converts ePub e-books into .mobi files.",
58
- :installed => Bookshelf::Dependency.kindlegen?
59
- }
60
-
61
- result << {
62
- :description => "html2text: Converts HTML documents into plain text.",
63
- :installed => Bookshelf::Dependency.html2text?
64
- }
65
-
66
56
  result.each do |result|
67
57
  text = color(result[:name], :blue)
68
58
  text << "\n" << result[:description]
@@ -73,24 +63,6 @@ module Bookshelf
73
63
  end
74
64
  end
75
65
 
76
- desc "permalinks", "List title permalinks"
77
-
78
- def permalinks
79
- html = Bookshelf::Parser::HTML.new(Bookshelf.root_dir).content
80
- toc = Bookshelf::TOC::HTML.generate(html)
81
-
82
- toc.toc.each do |options|
83
- level = options[:level] - 1
84
- title = " #{options[:text]}: "
85
- permalink = "##{options[:permalink]}"
86
-
87
- text = "*" * level
88
- text << color(title, :blue)
89
- text << color(permalink, :yellow)
90
- say(text)
91
- end
92
- end
93
-
94
66
  desc "stats", "Display some stats about your e-book"
95
67
  def stats
96
68
  stats = Bookshelf::Stats.new(Bookshelf.root_dir)
@@ -99,9 +71,7 @@ module Bookshelf
99
71
  "Chapters: #{stats.chapters}",
100
72
  "Words: #{stats.words}",
101
73
  "Images: #{stats.images}",
102
- "Links: #{stats.links}",
103
- "Footnotes: #{stats.footnotes}",
104
- "Code blocks: #{stats.code_blocks}"
74
+ "Links: #{stats.links}"
105
75
  ].join("\n")
106
76
  end
107
77
 
@@ -1,15 +1,7 @@
1
1
  module Bookshelf
2
2
  class Dependency
3
- def self.kindlegen?
4
- @kindlegen ||= `which kindlegen` && $?.success?
5
- end
6
-
7
3
  def self.prince?
8
4
  @prince ||= `which prince` && $?.success?
9
5
  end
10
-
11
- def self.html2text?
12
- @html2text ||= `which html2text` && $?.success?
13
- end
14
6
  end
15
7
  end
@@ -34,16 +34,12 @@ module Bookshelf
34
34
 
35
35
  export_assets
36
36
  export_pdf = [nil, "pdf"].include?(options[:only])
37
- export_epub = [nil, "mobi", "epub"].include?(options[:only])
38
- export_mobi = [nil, "mobi"].include?(options[:only])
39
- export_txt = [nil, "txt"].include?(options[:only])
37
+ export_epub = [nil, "epub"].include?(options[:only])
40
38
 
41
39
  exported = []
42
40
  exported << Parser::HTML.parse(book_dir)
43
41
  exported << Parser::PDF.parse(book_dir) if export_pdf && Dependency.prince?
44
42
  exported << Parser::Epub.parse(book_dir) if export_epub
45
- exported << Parser::Mobi.parse(book_dir) if export_mobi && Dependency.kindlegen?
46
- exported << Parser::Txt.parse(book_dir) if export_txt && Dependency.html2text?
47
43
 
48
44
  if exported.all?
49
45
  color = :green
@@ -20,9 +20,9 @@ module Bookshelf
20
20
  end
21
21
 
22
22
  def copy_assets
23
- copy_file "epub.scss" , "assets/styles/epub.scss"
24
- copy_file "html.scss" , "assets/styles/html.scss"
25
- copy_file "html.scss" , "assets/styles/_fonts.scss"
23
+ copy_file "epub.scss", "assets/styles/epub.scss"
24
+ copy_file "html.scss", "assets/styles/html.scss"
25
+ copy_file "_fonts.scss", "assets/styles/_fonts.scss"
26
26
  empty_directory "assets/fonts"
27
27
  empty_directory "assets/images"
28
28
  end
@@ -36,9 +36,10 @@ module Bookshelf
36
36
  end
37
37
 
38
38
  def copy_templates
39
- copy_file "layout.erb" , "templates/html/layout.erb"
40
- copy_file "cover.erb" , "templates/epub/cover.erb"
41
- copy_file "epub.erb" , "templates/epub/page.erb"
39
+ copy_file "layout.erb", "templates/html/layout.erb"
40
+ copy_file "cover.erb", "templates/epub/cover.erb"
41
+ copy_file "epub.erb", "templates/epub/page.erb"
42
+ copy_file "toc.erb", "templates/epub/toc.erb"
42
43
  end
43
44
 
44
45
  def create_empty_directories
@@ -5,14 +5,12 @@ module Bookshelf
5
5
  autoload :HTML , "bookshelf/parser/html"
6
6
  autoload :PDF , "bookshelf/parser/pdf"
7
7
  autoload :Epub , "bookshelf/parser/epub"
8
- autoload :Mobi , "bookshelf/parser/mobi"
9
- autoload :Txt , "bookshelf/parser/txt"
10
8
 
11
9
  class Base
12
10
  # The e-book directory.
13
11
  #
14
12
  attr_accessor :book_dir
15
-
13
+
16
14
  def self.parse(book_dir)
17
15
  new(book_dir).parse
18
16
  end
@@ -33,12 +31,6 @@ module Bookshelf
33
31
  Bookshelf.config
34
32
  end
35
33
 
36
- # Render a eRb template using +locals+ as data seed.
37
- #
38
- def render_template(file, locals = {})
39
- ERB.new(File.read(file)).result OpenStruct.new(locals).instance_eval{ binding }
40
- end
41
-
42
34
  def spawn_command(cmd)
43
35
  begin
44
36
  stdout_and_stderr, status = Open3.capture2e(*cmd)