bookchef 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,128 @@
1
+ Bookchef
2
+ =========
3
+ A library to convert bookchef.xml file tree into an actual book (currently HTML and PDF are supported).
4
+ bookchef.xml is A VERY SIMPLE xml format that I designed to write books. **Yes, I've actually written and successfully published a book with it.**
5
+
6
+
7
+ Installation
8
+ ------------
9
+
10
+ 1. Install **wkhtmltopdf** as explained in [this Wiki](https://github.com/pdfkit/pdfkit/wiki/Installing-WKHTMLTOPDF). It's a utility that converts html to pdf that Bookchef is going to need.
11
+
12
+ 2. `gem install bookchef`
13
+
14
+ Now a `bookchef` command is available on your system. Type it to see a short summary on how to use it. You will be able to do everything from the command line, but, of course, you may load necessary classes in your ruby program.
15
+
16
+
17
+ Bookchef XML basics
18
+ -------------------
19
+
20
+ Once I decided to write a book. I didn't want to use any propritary software -- I wanted to use git, my text-editor and a simple xml format (and I mean, really simple) that you can write by hand, so that later I could maybe build some kind of gui-editor around it. In order to make git useful, I realized that each chapter and each section of the chapter should be in a separate file and a seperate directory. Thus we have `<chapter>` and `<section>` tags, each may or may not have an `src=` attribute. Here's an example:
21
+
22
+ <book>
23
+ <chapter>
24
+ <section src="section1.xml"/>
25
+ <section src="section2.xml"/>
26
+ <section>And this one doesn't have a seperate file</section>
27
+ </chapter>
28
+
29
+ <!-- Automatically loads chapter2/index.xml
30
+ if file name is not specified, e.g. doesn't end on .xml -->
31
+ <chapter src="chapter2"></chapter>
32
+ </book>
33
+
34
+ Because chapters and sections may be in seperate files, it will be much easier to parse git diffs in the future, when and if this gui editor arrives. Also, it makes it easy to to manually navigate through the book with just your text editor. Assuming this file is called `index.xml` (and for now it is a requirement for a file which contains a `<book>` tag) I don't recommend using any kind of internal links (like footnotes and references, see below) in this file, because for now they will be broken. `index.xml` in the root book directory should source all the parts from other files.
35
+
36
+ Within the book, you may use various elements, listed below:
37
+
38
+ + `<title>` may appear once within a chapter or a section, but doesn't have to. While compiling, each chapter automatically gets a number before its title
39
+ + `<code-inline>` allows you to include an inline code
40
+ + `<code>` allow a multi-line block of code. Remember that within it other tags don't work.
41
+ + `<p>` is self-exlpanatory
42
+ + `<term>` - wrap a term with it, with standard styles used by compiler the text will appear in italics.
43
+ + `<filename>` is used to indicate either a filename or a url (when it's not supposed to be clicked, for example in the case of http://localhost:3000)
44
+
45
+ Then we also have two special blocks that may appear at the bottom of each section, which are called `<references>` and `<footnotes>`. Here's how it may look:
46
+
47
+ <section>
48
+ <title>Minimum wage: why it doesn't work</title>
49
+ <p><span reference="1">Minimum wage</span> doesn't work because people getting jobs for this wage are doing so at the expense of all others who didn't get the same job, when employers were either unable to pay for that many employees or simply went out of business. Or, they may indeed comply with the law and hire just the same number of employees, in which case they simply <span footnote="1">redistribute these costs on their customers</footnote>, who then redistribute these costs on their employers demanding more pay and the circle continues. This circle inevitably causes <span footnote="2">either inflation or loss of demand</span>. Thus, minimum wage always has its costs, but those costs are not payed by people who are expected to pay.</p>
50
+
51
+ <footnotes>
52
+ <footnote id="1">By raising prices</footnote>
53
+ <footnote id="2">People either start demanding more pay, causing businesses to borrow more from banks or, if it's government employees, causing government to print more money.</footnote>
54
+ </footnotes>
55
+
56
+ <references>
57
+ <reference id="1" type="article" url="http://en.wikipedia.org/wiki/Minimum_wage">Article about minimum wage on Wikipedia</reference>
58
+ </references>
59
+
60
+ </section>
61
+
62
+ As you can see, we referenced both footnotes and references by wrapping some text in `<span>` tags and using either a `footnote=` or `reference=` attributes. In fact, you can add those attributes to other tags, not just `<span>`, but also `<term>` or `<filename>`. It will look like this when compiled:
63
+
64
+ ![bookchef_compiled_example](https://github.com/snitko/frontend_notifier/raw/master/bookchef_compiled_example.png)
65
+
66
+ Of course, readers are able to click the links and go straight to the footnote or the reference they chose.
67
+
68
+ You can also link to other chapters and sections which are placed in a separate file, for example:
69
+
70
+ we discussed this in the chapter on <a href="../chapter2_supply_and_demand">supply and demand</a>
71
+
72
+ or you can even say this
73
+
74
+ we discussed this in the chapter on <a href="../chapter2_supply_and_demand"/>
75
+
76
+ in which case the content in the `<title>` tags from that section will be used to create a link.
77
+
78
+ You can have as many subdirectories as you want for each chapter, so if there's a large section within a chapter it makes sense to put it in a separate subdirectory. Just don't forget that each subdirectory must have its `index.xml` file.
79
+
80
+ That's basically it.
81
+
82
+
83
+ How to compile your XML into an actual book
84
+ -------------------------------------------
85
+
86
+ You've written a book using BookChef.xml tags, now you want to make a pdf out of it. That's rather simple to do from the command line:
87
+
88
+ ### Step 0
89
+ make sure there's a git repo in your book dir. Otherwise there will be an error (to be fixed).
90
+
91
+ ### Step 1: Merge xml files tree into one big .xml file
92
+ bookchef merge_tree path/to/your/book merged_book.xml
93
+
94
+ ### Step 2: Compile this file into an .html file using css styles
95
+ bookchef make_html merged_book.xml compiled_book.html
96
+
97
+ ### Step 3: Compile PDF out of this HTML:
98
+ bookchef make_pdf compiled_book.html compiled_book.pdf
99
+
100
+ Same steps can be achieved with Ruby code:
101
+
102
+ # Step 1
103
+ merger = BookChef::TreeMerger.new('path/to/your/book', "index.xml")
104
+ merger.run
105
+ merger.save_to "merged_book.xml"
106
+
107
+ # Step 2
108
+ html_compiler = BookChef::Compiler::HTML.new("merged_book.xml")
109
+ html_compiler.run
110
+ html_compiler.save_to "compiled_book.html"
111
+
112
+ # Step 3
113
+ BookChef::Compiler::PDF.new(
114
+ File.read('compiled_book.html'),
115
+ output_file: 'compiled_book.pdf',
116
+ footer_custom_html: "This text will appear in the footer of every page"
117
+ ).compile
118
+
119
+
120
+ Customizable styles and compiling to different formats
121
+ ------------------------------------------------------
122
+ There to directories that you might be interested in to customize the output. First, there's a `lib/bookchef/stylesheets/scss` where you may find a `default.scss` file. This file determines, obviously, what the HTML output will look like in a browser (use `rake compile_css` to create a correposnding css in `lib/bookchef/stylesheets/css`.
123
+
124
+ To tell compiler which css file to use you'd need to create a new xslt-stylesheet in `lib/bookchef/stylesheets/xslt`. Just copy the default one, find the part where it creates a stylesheet link tag and change the css filename. Then you can tell compiler to use your xslt instead of a default one:
125
+
126
+ BookChef::Compiler::HTML.new("merged_book.xml", "#{BookChef::LIB_PATH}/stylesheets/xslt/my_styles.xsl")
127
+
128
+ Because compiler mostly relies on xslt styles to convert xml into html, you can add you own xslt-styles to create any kind of resulting files, for instance epub or Kindle.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bookchef
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-10 00:00:00.000000000 Z
12
+ date: 2013-03-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pdfkit
@@ -178,14 +178,17 @@ executables:
178
178
  extensions: []
179
179
  extra_rdoc_files:
180
180
  - LICENSE.txt
181
+ - README.markdown
181
182
  files:
182
183
  - .document
183
184
  - Gemfile
184
185
  - Gemfile.lock
185
186
  - LICENSE.txt
187
+ - README.markdown
186
188
  - Rakefile
187
189
  - VERSION
188
190
  - bin/bookchef
191
+ - bookchef_compiled_example.png
189
192
  - lib/bookchef.rb
190
193
  - lib/bookchef/compilers/html.rb
191
194
  - lib/bookchef/compilers/pdf.rb
@@ -227,7 +230,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
227
230
  version: '0'
228
231
  segments:
229
232
  - 0
230
- hash: 997388749527007355
233
+ hash: 770680831178245341
231
234
  required_rubygems_version: !ruby/object:Gem::Requirement
232
235
  none: false
233
236
  requirements: