fnando-kitabu 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +4 -187
- data/Rakefile +34 -83
- data/VERSION +1 -0
- data/kitabu.gemspec +77 -51
- data/lib/kitabu.rb +6 -0
- data/lib/kitabu/base.rb +36 -36
- data/lib/kitabu/blackcloth.rb +13 -2
- data/lib/kitabu/markup.rb +4 -2
- data/lib/kitabu/tasks.rb +1 -1
- data/lib/kitabu/templates.rb +8 -6
- data/lib/kitabu/toc.rb +2 -9
- data/templates/config.yml +8 -7
- metadata +19 -22
data/README.markdown
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
Kitabu
|
2
2
|
======
|
3
3
|
|
4
|
-
*
|
4
|
+
* <http://fnando.github.com/kitabu.html>
|
5
5
|
|
6
6
|
DESCRIPTION:
|
7
7
|
------------
|
8
8
|
|
9
9
|
A framework for creating e-books from Markdown/Textile text markup using Ruby.
|
10
10
|
Using the Prince PDF generator, you'll be able to get high quality PDFs.
|
11
|
-
Mac users that have [Textmate](http://macromates.com) installed can have source
|
12
|
-
code highlighted with his/her favorite theme.
|
13
11
|
|
14
12
|
While Prince is too expensive (495USD for a single user license), the
|
15
13
|
free version available at [http://www.princexml.com/download/](http://www.princexml.com/download/) generates
|
@@ -25,198 +23,17 @@ FEATURES:
|
|
25
23
|
* Generate a PDF with a single rake task
|
26
24
|
* Table of Contents automatically generated from chapter titles
|
27
25
|
|
28
|
-
|
29
|
-
---------
|
30
|
-
|
31
|
-
Create a new book with `kitabu mybook`. Kitabu has support for book
|
32
|
-
layout and syntax highlight theme. You can specify other settings:
|
33
|
-
|
34
|
-
kitabu mybook --theme=mac_classic
|
35
|
-
kitabu mybook --layout=boom
|
36
|
-
|
37
|
-
You can check available layouts and themes with `kitabu --help`
|
38
|
-
|
39
|
-
The `kitabu` command creates a directory "mybook" with the
|
40
|
-
following structure:
|
41
|
-
|
42
|
-
- book
|
43
|
-
- config.yml
|
44
|
-
- images
|
45
|
-
- output
|
46
|
-
- Rakefile
|
47
|
-
- templates
|
48
|
-
- layout.css
|
49
|
-
- layout.html
|
50
|
-
- syntax.css
|
51
|
-
- user.css
|
52
|
-
- text
|
53
|
-
|
54
|
-
The `config.yml` file holds some information about your book; so you'll always
|
55
|
-
change it. This is the default generated file:
|
56
|
-
|
57
|
-
title: [Your Book Title]
|
58
|
-
copyright: Copyright (c) 2008 [Your Name], All Rights Reserved
|
59
|
-
authors:
|
60
|
-
- [Your Name]
|
61
|
-
- [Other Name]
|
62
|
-
subject: [Write down what your book is about]
|
63
|
-
keywords: [The keywords related to your book]
|
64
|
-
theme: eiffel
|
65
|
-
|
66
|
-
If you're writing on a different language, the `user.css` file can override all
|
67
|
-
the messages added by the `layout.css`. Examples on doing this coming soon.
|
68
|
-
|
69
|
-
Now it's time to write your book. All your book content will be placed on the
|
70
|
-
text directory. Kitabu requires you to separate your book into chapters.
|
71
|
-
A chapter is nothing but a directory that holds lots of Markdown/Textile files.
|
72
|
-
The book will be generated using every folder/file alphabetically. So be sure
|
73
|
-
to use a sequential numbering as the name. Here's a sample:
|
74
|
-
|
75
|
-
- text
|
76
|
-
- 01_Introduction
|
77
|
-
- 01\_introduction.markdown
|
78
|
-
- 02\_What\_is\_Ruby\_on\_Rails
|
79
|
-
- 01\_MVC.markdown
|
80
|
-
- 02\_DRY.markdown
|
81
|
-
- 03\_Convention\_Over\_Configuration.markdown
|
82
|
-
- 03\_Installing\_Ruby\_on\_Rails
|
83
|
-
- 01\_Installing.textile
|
84
|
-
- 02\_Mac\_OS\_X\_instructions.textile
|
85
|
-
- 03\_Windows\_instructions.markdown
|
86
|
-
- 04\_Ubuntu\_Linux\_instructions.markdown
|
87
|
-
|
88
|
-
If you prefer, you can add a chapter per file:
|
89
|
-
|
90
|
-
- text
|
91
|
-
- 01\_Introduction.markdown
|
92
|
-
- 02\_What\_is\_Ruby\_on\_Rails.markdown
|
93
|
-
- 03\_Installing\_Ruby\_on\_Rails.markdown
|
94
|
-
|
95
|
-
Note that you can use Textile or Markdown at the same time. Just use the
|
96
|
-
`.markdown` or `.textile` file extension.
|
97
|
-
|
98
|
-
You'll want to see your progress eventually; it's time for you to generate
|
99
|
-
the book PDF. Just run the command `rake kitabu:pdf` and your book will be
|
100
|
-
created on the output directory.
|
101
|
-
|
102
|
-
There are other rake tasks you can use:
|
103
|
-
|
104
|
-
* `kitabu:html` - generate a html from your content
|
105
|
-
* `kitabu:syntaxes` - list all available syntaxes
|
106
|
-
* `kitabu:themes` - list all available themes
|
107
|
-
* `kitabu:titles` - list all titles and its permalinks
|
108
|
-
* `kitabu:watch` - watch `text` for any change and automatically generate html
|
109
|
-
|
110
|
-
Kitabu can generate a Table of Contents (TOC) based on your h2-h6 tags. The
|
111
|
-
h1 tag is discarded because it's meant to be the book title.
|
112
|
-
|
113
|
-
If you need to link to a specific chapter, you can use the `kitabu:titles` rake
|
114
|
-
task to know what's the permalink that you need. For example, a title
|
115
|
-
`Installing Mac OS X` will have a permalink `installing-mac-os-x` and you can
|
116
|
-
link to this chapter by writing
|
117
|
-
`"See more on Installing Mac OS X":#installing-mac-os-x` when using
|
118
|
-
Textile.
|
119
|
-
|
120
|
-
To generate the TOC, you need to print a variable called `toc`, using the eRb
|
121
|
-
tag `<%= toc %>`.
|
122
|
-
|
123
|
-
Syntax Highlighting
|
124
|
-
===================
|
125
|
-
|
126
|
-
If you're using Textile, all you need to do is use the tag `syntax.`. For
|
127
|
-
example, to highlight a code added right into your text, just do something like
|
128
|
-
|
129
|
-
syntax(ruby_on_rails). class User < ActiveRecord::Base
|
130
|
-
validates_presence_of :login, :password, :email
|
131
|
-
__
|
132
|
-
validates_uniqueness_of :login, :email
|
133
|
-
end
|
134
|
-
|
135
|
-
To keep multiple line breaks into a single code block, add a line `__`;
|
136
|
-
Kitabu will replace it when generating the HTML file.
|
137
|
-
|
138
|
-
If you want to highlight a file, you need to place it into the `code`
|
139
|
-
directory and call it like this:
|
140
|
-
|
141
|
-
syntax(ruby_on_rails). some_file.rb
|
142
|
-
|
143
|
-
You can specify the lines you want to highlight; the example below will
|
144
|
-
highlight lines 10-17 from some_file.rb.
|
145
|
-
|
146
|
-
syntax(ruby_on_rails 10,17). some_file.rb
|
147
|
-
|
148
|
-
You can also specify named blocks to highlight. Named blocks are identified
|
149
|
-
by `#begin` and `#end` marks. If some_file.rb has the following code
|
150
|
-
|
151
|
-
require "rubygems"
|
152
|
-
require "hpricot"
|
153
|
-
require "open"
|
154
|
-
|
155
|
-
# begin: get_all_h2_tags
|
156
|
-
doc = Hpricot(open('http://simplesideias.com.br'))
|
157
|
-
(doc/"h2").each {|h2| puts h2.inner_text }
|
158
|
-
# end: get_all_h2_tags
|
159
|
-
|
160
|
-
you can get the code between `get_all_h2_tags` using
|
161
|
-
|
162
|
-
syntax(ruby#get_all_h2_tags). some_file.rb
|
163
|
-
|
164
|
-
*Note:* Makdown uses the same syntax above. You just need to indent your code
|
165
|
-
(as usual) and add the `syntax.` thing as the first line.
|
166
|
-
|
167
|
-
INSTALL:
|
168
|
-
--------
|
169
|
-
|
170
|
-
sudo gem install fnando-kitabu --source http://gems.github.com
|
171
|
-
|
172
|
-
or, if you have problem
|
173
|
-
|
174
|
-
git clone git://github.com/fnando/kitabu.git
|
175
|
-
cd kitabu
|
176
|
-
gem build kitabu.gemspec
|
177
|
-
sudo gem install kitabu
|
178
|
-
|
179
|
-
To have syntax highlighting support, you need to install
|
180
|
-
Oniguruma regular expression library that can be found at
|
181
|
-
[http://www.geocities.jp/kosako3/oniguruma/](http://www.geocities.jp/kosako3/oniguruma/)
|
182
|
-
|
183
|
-
Then, you need to install the Ultraviolet gem.
|
184
|
-
|
185
|
-
sudo gem install ultraviolet
|
186
|
-
|
187
|
-
TROUBLESHOOTING
|
188
|
-
---------------
|
189
|
-
|
190
|
-
You might get this error (specially on Linux):
|
191
|
-
|
192
|
-
require 'uv'
|
193
|
-
LoadError: libonig.so.2: cannot open shared object file: No such file or directory - /usr/lib/ruby/gems/1.8/gems/oniguruma-1.1.0/lib/oregexp.so
|
194
|
-
|
195
|
-
It means Ruby can’t find `libonig.so.2`. Add the path to the directory where the file is located to `/etc/ld.so.conf`:
|
196
|
-
|
197
|
-
include /etc/ld.so.conf.d/*.conf
|
198
|
-
include /usr/local/lib
|
199
|
-
|
200
|
-
Then run:
|
201
|
-
|
202
|
-
ldconfig
|
203
|
-
|
204
|
-
|
205
|
-
REFERENCES:
|
206
|
-
-----------
|
207
|
-
|
208
|
-
- Textile: [http://hobix.com/textile/](http://hobix.com/textile/)
|
209
|
-
- Markdown: [http://daringfireball.net/projects/markdown/syntax](http://daringfireball.net/projects/markdown/syntax)
|
26
|
+
Check it out <http://fnando.github.com/kitabu.html> for details.
|
210
27
|
|
211
28
|
MAINTAINER
|
212
29
|
----------
|
213
30
|
|
214
|
-
* Nando Vieira (
|
31
|
+
* Nando Vieira (<http://simplesideias.com.br>)
|
215
32
|
|
216
33
|
CONTRIBUTORS
|
217
34
|
------------
|
218
35
|
|
219
|
-
* Arthur Zapparoli (
|
36
|
+
* Arthur Zapparoli (<http://arthurgeek.net>)
|
220
37
|
|
221
38
|
LICENSE:
|
222
39
|
--------
|
data/Rakefile
CHANGED
@@ -1,89 +1,40 @@
|
|
1
|
-
require
|
1
|
+
require "rake"
|
2
|
+
require "jeweler"
|
3
|
+
require File.dirname(__FILE__) + "/lib/kitabu"
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
5
|
+
JEWEL = Jeweler::Tasks.new do |gem|
|
6
|
+
gem.name = "kitabu"
|
7
|
+
gem.version = Kitabu::VERSION
|
8
|
+
gem.summary = "A framework for creating e-books from Markdown/Textile text markup using Ruby."
|
9
|
+
gem.description = <<-TXT
|
10
|
+
A framework for creating e-books from Markdown/Textile text markup using Ruby.
|
11
|
+
Using the Prince PDF generator, you'll be able to get high quality PDFs.
|
12
|
+
TXT
|
13
|
+
|
14
|
+
gem.authors = ["Nando Vieira"]
|
15
|
+
gem.email = "fnando.vieira@gmail.com"
|
16
|
+
gem.homepage = "http://fnando.github.com/kitabu.html"
|
17
|
+
|
18
|
+
gem.has_rdoc = false
|
19
|
+
gem.files = %w(Rakefile kitabu.gemspec VERSION README.markdown) + Dir["{bin,lib,templates}/**/*"]
|
20
|
+
gem.bindir = "bin"
|
21
|
+
gem.executables = "kitabu"
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
s.add_dependency "ultraviolet"
|
23
|
+
gem.add_dependency "discount"
|
24
|
+
gem.add_dependency "hpricot"
|
25
|
+
gem.add_dependency "unicode"
|
26
|
+
gem.add_dependency "main"
|
27
|
+
gem.add_dependency "ultraviolet"
|
24
28
|
|
25
|
-
|
26
|
-
s.requirements << "Install the Oniguruma RE library"
|
29
|
+
gem.requirements << "Install the Oniguruma RE library"
|
27
30
|
end
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
skip_fields = %w(new_platform original_platform specification_version loaded required_ruby_version rubygems_version platform )
|
34
|
-
|
35
|
-
result = "# WARNING : RAKE AUTO-GENERATED FILE. DO NOT MANUALLY EDIT!\n"
|
36
|
-
result << "# RUN : 'rake gem:update_gemspec'\n\n"
|
37
|
-
result << "Gem::Specification.new do |s|\n"
|
38
|
-
|
39
|
-
spec.instance_variables.each do |ivar|
|
40
|
-
value = spec.instance_variable_get(ivar)
|
41
|
-
name = ivar.split("@").last
|
42
|
-
next if name == "date"
|
43
|
-
|
44
|
-
if name == 'version'
|
45
|
-
base_file = File.join(File.dirname(__FILE__), 'lib/kitabu/base.rb')
|
46
|
-
contents = File.read(base_file)
|
47
|
-
contents.gsub!(/VERSION = "[\d\.]+"/sim, %(VERSION = "#{value}"))
|
48
|
-
File.open(base_file, 'w+') do |f|
|
49
|
-
f << contents
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
next if skip_fields.include?(name) || value.nil? || value == "" || (value.respond_to?(:empty?) && value.empty?)
|
54
|
-
if name == "dependencies"
|
55
|
-
value.each do |d|
|
56
|
-
dep, *ver = d.to_s.split(" ")
|
57
|
-
result << " s.add_dependency #{dep.inspect}, #{ver.join(" ").inspect.gsub(/[()]/, "").gsub(", runtime", "")}\n"
|
58
|
-
end
|
59
|
-
else
|
60
|
-
case value
|
61
|
-
when Array
|
62
|
-
value = name != "files" ? value.inspect : value.inspect.split(",").join(",\n")
|
63
|
-
when FalseClass
|
64
|
-
when TrueClass
|
65
|
-
when Fixnum
|
66
|
-
when String
|
67
|
-
value = value.inspect
|
68
|
-
else
|
69
|
-
value = value.to_s.inspect
|
70
|
-
end
|
71
|
-
result << " s.#{name} = #{value}\n"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
result << "end"
|
76
|
-
File.open(File.join(File.dirname(__FILE__), "#{spec.name}.gemspec"), "w"){|f| f << result}
|
77
|
-
end
|
32
|
+
desc "Generate gemspec, build and install the gem"
|
33
|
+
task :package do
|
34
|
+
File.open("VERSION", "w+") {|f| f << Kitabu::VERSION.to_s }
|
35
|
+
FileUtils.cp "VERSION", File.expand_path("~/Sites/github/glue-pages/views/version/_#{JEWEL.gemspec.name}.haml")
|
78
36
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
desc "Install gem"
|
86
|
-
task :install => :build do
|
87
|
-
system "sudo gem install #{spec.instance_variable_get('@name')}"
|
88
|
-
end
|
89
|
-
end
|
37
|
+
Rake::Task["gemspec"].invoke
|
38
|
+
Rake::Task["build"].invoke
|
39
|
+
Rake::Task["install"].invoke
|
40
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.4
|
data/kitabu.gemspec
CHANGED
@@ -1,55 +1,81 @@
|
|
1
|
-
#
|
2
|
-
# RUN : 'rake gem:update_gemspec'
|
1
|
+
# -*- encoding: utf-8 -*-
|
3
2
|
|
4
3
|
Gem::Specification.new do |s|
|
5
|
-
s.
|
6
|
-
s.
|
7
|
-
|
8
|
-
s.
|
9
|
-
s.
|
10
|
-
s.
|
4
|
+
s.name = %q{kitabu}
|
5
|
+
s.version = "0.3.4"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Nando Vieira"]
|
9
|
+
s.date = %q{2009-08-02}
|
10
|
+
s.default_executable = %q{kitabu}
|
11
|
+
s.description = %q{A framework for creating e-books from Markdown/Textile text markup using Ruby.
|
12
|
+
Using the Prince PDF generator, you'll be able to get high quality PDFs.
|
13
|
+
}
|
14
|
+
s.email = %q{fnando.vieira@gmail.com}
|
11
15
|
s.executables = ["kitabu"]
|
12
|
-
s.
|
13
|
-
|
14
|
-
|
15
|
-
s.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"README.markdown",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"bin/kitabu",
|
24
|
+
"kitabu.gemspec",
|
25
|
+
"lib/kitabu.rb",
|
26
|
+
"lib/kitabu/base.rb",
|
27
|
+
"lib/kitabu/blackcloth.rb",
|
28
|
+
"lib/kitabu/markup.rb",
|
29
|
+
"lib/kitabu/redcloth.rb",
|
30
|
+
"lib/kitabu/tasks.rb",
|
31
|
+
"lib/kitabu/templates.rb",
|
32
|
+
"lib/kitabu/toc.rb",
|
33
|
+
"templates/Rakefile",
|
34
|
+
"templates/config.yml",
|
35
|
+
"templates/layouts/boom/layout.css",
|
36
|
+
"templates/layouts/boom/layout.html",
|
37
|
+
"templates/syntax.css",
|
38
|
+
"templates/themes/active4d.css",
|
39
|
+
"templates/themes/blackboard.css",
|
40
|
+
"templates/themes/dawn.css",
|
41
|
+
"templates/themes/eiffel.css",
|
42
|
+
"templates/themes/idle.css",
|
43
|
+
"templates/themes/iplastic.css",
|
44
|
+
"templates/themes/lazy.css",
|
45
|
+
"templates/themes/mac_classic.css",
|
46
|
+
"templates/themes/slush_poppies.css",
|
47
|
+
"templates/themes/sunburst.css",
|
48
|
+
"templates/user.css"
|
49
|
+
]
|
50
|
+
s.homepage = %q{http://fnando.github.com/kitabu.html}
|
51
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
21
52
|
s.require_paths = ["lib"]
|
22
|
-
s.
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
"
|
32
|
-
"
|
33
|
-
"
|
34
|
-
"
|
35
|
-
"
|
36
|
-
|
37
|
-
"
|
38
|
-
"
|
39
|
-
"
|
40
|
-
"
|
41
|
-
"
|
42
|
-
|
43
|
-
|
44
|
-
"
|
45
|
-
"
|
46
|
-
"
|
47
|
-
"
|
48
|
-
"
|
49
|
-
|
50
|
-
|
51
|
-
"templates/themes/slush_poppies.css",
|
52
|
-
"templates/themes/sunburst.css",
|
53
|
-
"templates/user.css"]
|
54
|
-
s.authors = ["Nando Vieira"]
|
55
|
-
end
|
53
|
+
s.requirements = ["Install the Oniguruma RE library"]
|
54
|
+
s.rubygems_version = %q{1.3.5}
|
55
|
+
s.summary = %q{A framework for creating e-books from Markdown/Textile text markup using Ruby.}
|
56
|
+
|
57
|
+
if s.respond_to? :specification_version then
|
58
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
59
|
+
s.specification_version = 3
|
60
|
+
|
61
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
62
|
+
s.add_runtime_dependency(%q<discount>, [">= 0"])
|
63
|
+
s.add_runtime_dependency(%q<hpricot>, [">= 0"])
|
64
|
+
s.add_runtime_dependency(%q<unicode>, [">= 0"])
|
65
|
+
s.add_runtime_dependency(%q<main>, [">= 0"])
|
66
|
+
s.add_runtime_dependency(%q<ultraviolet>, [">= 0"])
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<discount>, [">= 0"])
|
69
|
+
s.add_dependency(%q<hpricot>, [">= 0"])
|
70
|
+
s.add_dependency(%q<unicode>, [">= 0"])
|
71
|
+
s.add_dependency(%q<main>, [">= 0"])
|
72
|
+
s.add_dependency(%q<ultraviolet>, [">= 0"])
|
73
|
+
end
|
74
|
+
else
|
75
|
+
s.add_dependency(%q<discount>, [">= 0"])
|
76
|
+
s.add_dependency(%q<hpricot>, [">= 0"])
|
77
|
+
s.add_dependency(%q<unicode>, [">= 0"])
|
78
|
+
s.add_dependency(%q<main>, [">= 0"])
|
79
|
+
s.add_dependency(%q<ultraviolet>, [">= 0"])
|
80
|
+
end
|
81
|
+
end
|
data/lib/kitabu.rb
CHANGED
@@ -6,6 +6,8 @@ require "rexml/streamlistener"
|
|
6
6
|
require "rexml/document"
|
7
7
|
require "hpricot"
|
8
8
|
|
9
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)
|
10
|
+
|
9
11
|
require "kitabu/base"
|
10
12
|
require "kitabu/toc"
|
11
13
|
require "kitabu/markup"
|
@@ -15,3 +17,7 @@ begin
|
|
15
17
|
rescue LoadError => e
|
16
18
|
nil
|
17
19
|
end
|
20
|
+
|
21
|
+
module Kitabu
|
22
|
+
VERSION = "0.3.4"
|
23
|
+
end
|
data/lib/kitabu/base.rb
CHANGED
@@ -1,37 +1,37 @@
|
|
1
1
|
module Kitabu
|
2
|
-
VERSION = "0.3.3"
|
3
|
-
|
4
2
|
module Base
|
5
3
|
DEFAULT_LAYOUT = 'boom'
|
6
4
|
DEFAULT_THEME = 'eiffel'
|
7
5
|
DEFAULT_SYNTAX = 'plain_text'
|
8
6
|
GEM_ROOT = File.expand_path(File.dirname(__FILE__) + "/../../")
|
9
7
|
|
10
|
-
|
8
|
+
extend self
|
9
|
+
|
10
|
+
def html_path
|
11
11
|
KITABU_ROOT + "/output/#{app_name}.html"
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def pdf_path
|
15
15
|
KITABU_ROOT + "/output/#{app_name}.pdf"
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
18
|
+
def template_path
|
19
19
|
KITABU_ROOT + "/templates/layout.html"
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def config_path
|
23
23
|
KITABU_ROOT + "/config.yml"
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
26
|
+
def text_dir
|
27
27
|
KITABU_ROOT + "/text"
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
30
|
+
def config
|
31
31
|
@config ||= YAML::load_file(config_path)
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
34
|
+
def parse_layout(contents)
|
35
35
|
template = File.new(template_path).read
|
36
36
|
contents, toc = self.table_of_contents(contents)
|
37
37
|
cfg = config.merge(:contents => contents, :toc => toc)
|
@@ -40,8 +40,8 @@ module Kitabu
|
|
40
40
|
ERB.new(template).result env.instance_eval{ binding }
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
44
|
-
return [contents, nil] unless
|
43
|
+
def table_of_contents(contents)
|
44
|
+
return [contents, nil] unless defined?('Hpricot') && defined?('Unicode')
|
45
45
|
|
46
46
|
doc = Hpricot(contents)
|
47
47
|
counter = {}
|
@@ -64,16 +64,16 @@ module Kitabu
|
|
64
64
|
contents = doc.to_html
|
65
65
|
io = StringIO.new(contents)
|
66
66
|
toc = Toc.new
|
67
|
-
REXML::Document.parse_stream(io, toc)
|
67
|
+
REXML::Document.parse_stream(io, toc) rescue nil
|
68
68
|
|
69
69
|
[contents, toc.to_s]
|
70
70
|
end
|
71
71
|
|
72
|
-
def
|
72
|
+
def generate_pdf
|
73
73
|
IO.popen('prince %s -o %s' % [html_path, pdf_path])
|
74
74
|
end
|
75
75
|
|
76
|
-
def
|
76
|
+
def generate_html
|
77
77
|
# parsed file holder
|
78
78
|
contents = ""
|
79
79
|
|
@@ -81,7 +81,7 @@ module Kitabu
|
|
81
81
|
%w(. .. .svn .git).include?(entry) || (File.file?(entry) && entry !~ /\.(markdown|textile)$/)
|
82
82
|
end
|
83
83
|
|
84
|
-
|
84
|
+
$stdout << "\nNo markup files found!\n" if entries.empty?
|
85
85
|
|
86
86
|
# first, get all chapters; then, get all parsed markdown
|
87
87
|
# files from this chapter and group them into a <div class="chapter"> tag
|
@@ -116,14 +116,14 @@ module Kitabu
|
|
116
116
|
markup = Discount.new(markup_contents)
|
117
117
|
end
|
118
118
|
rescue Exception => e
|
119
|
-
|
119
|
+
$stdout << "\nSkipping #{markup_file} (#{e.message})"
|
120
120
|
next
|
121
121
|
end
|
122
122
|
|
123
123
|
# convert the markup into html
|
124
124
|
parsed_contents = markup.to_html
|
125
125
|
|
126
|
-
if
|
126
|
+
if defined?(Uv)
|
127
127
|
if markup.respond_to?(:syntax_blocks)
|
128
128
|
# textile
|
129
129
|
parsed_contents.gsub!(/@syntax:([0-9]+)/m) do |m|
|
@@ -136,24 +136,24 @@ module Kitabu
|
|
136
136
|
code = $1.gsub(/</, '<').gsub(/>/, '>').gsub(/&/, '&')
|
137
137
|
code_lines = StringIO.new(code).readlines
|
138
138
|
syntax_settings = code_lines.first
|
139
|
-
|
139
|
+
|
140
140
|
syntax = 'plain_text'
|
141
|
-
|
141
|
+
|
142
142
|
if syntax_settings =~ /syntax\(.*?\)\./
|
143
143
|
code = code_lines.slice(1, code_lines.size).join
|
144
|
-
|
144
|
+
|
145
145
|
# syntax
|
146
146
|
m, syntax = *syntax_settings.match(/syntax\(([^ #]+).*?\)./)
|
147
|
-
|
147
|
+
|
148
148
|
# file name
|
149
149
|
m, source_file = *syntax_settings.match(/syntax\(.*?\)\. +(.*?)$/)
|
150
|
-
|
150
|
+
|
151
151
|
# get line interval
|
152
152
|
m, from_line, to_line = *syntax_settings.match(/syntax\(.*? ([0-9]+),([0-9]+)\)/)
|
153
|
-
|
153
|
+
|
154
154
|
# get block name
|
155
155
|
m, block_name = *syntax_settings.match(/syntax\(.*?#([0-9a-z_]+)\)/)
|
156
|
-
|
156
|
+
|
157
157
|
code = Kitabu::Markup.content_for({
|
158
158
|
:code => code,
|
159
159
|
:from_line => from_line,
|
@@ -162,7 +162,7 @@ module Kitabu
|
|
162
162
|
:source_file => source_file
|
163
163
|
})
|
164
164
|
end
|
165
|
-
|
165
|
+
|
166
166
|
Kitabu::Markup.syntax(code, syntax)
|
167
167
|
end
|
168
168
|
end
|
@@ -183,53 +183,53 @@ module Kitabu
|
|
183
183
|
end
|
184
184
|
end
|
185
185
|
|
186
|
-
def
|
186
|
+
def app_name
|
187
187
|
ENV['KITABU_NAME'] || 'kitabu'
|
188
188
|
end
|
189
189
|
|
190
|
-
def
|
190
|
+
def theme?(theme_name)
|
191
191
|
themes.include?(theme_name)
|
192
192
|
end
|
193
193
|
|
194
|
-
def
|
194
|
+
def syntax?(syntax_name)
|
195
195
|
syntaxes.include?(syntax_name)
|
196
196
|
end
|
197
197
|
|
198
|
-
def
|
198
|
+
def layout?(layout_name)
|
199
199
|
layouts.include?(layout_name)
|
200
200
|
end
|
201
201
|
|
202
|
-
def
|
202
|
+
def default_theme
|
203
203
|
DEFAULT_THEME
|
204
204
|
end
|
205
205
|
|
206
|
-
def
|
206
|
+
def default_syntax
|
207
207
|
DEFAULT_SYNTAX
|
208
208
|
end
|
209
209
|
|
210
|
-
def
|
210
|
+
def default_layout
|
211
211
|
DEFAULT_LAYOUT
|
212
212
|
end
|
213
213
|
|
214
|
-
def
|
214
|
+
def syntaxes
|
215
215
|
Uv.syntaxes
|
216
216
|
end
|
217
217
|
|
218
|
-
def
|
218
|
+
def layouts
|
219
219
|
@layouts ||= begin
|
220
220
|
dir = File.join(GEM_ROOT, "templates/layouts")
|
221
221
|
Dir.entries(dir).reject{|p| p =~ /^\.+$/ }.sort
|
222
222
|
end
|
223
223
|
end
|
224
224
|
|
225
|
-
def
|
225
|
+
def themes
|
226
226
|
@themes ||= begin
|
227
227
|
filter = File.join(GEM_ROOT, "templates/themes/*.css")
|
228
228
|
Dir[filter].collect{|path| File.basename(path).gsub(/\.css$/, '') }.sort
|
229
229
|
end
|
230
230
|
end
|
231
231
|
|
232
|
-
def
|
232
|
+
def to_permalink(str)
|
233
233
|
str = Unicode.normalize_KD(str).gsub(/[^\x00-\x7F]/n,'')
|
234
234
|
str = str.gsub(/[^-_\s\w]/, ' ').downcase.squeeze(' ').tr(' ', '-')
|
235
235
|
str = str.gsub(/-+/, '-').gsub(/^-+/, '').gsub(/-+$/, '')
|
data/lib/kitabu/blackcloth.rb
CHANGED
@@ -41,7 +41,7 @@ class BlackCloth < RedCloth
|
|
41
41
|
url = File.join(base_url, content)
|
42
42
|
else
|
43
43
|
url = content
|
44
|
-
|
44
|
+
$stdout << "\nYou're using `file. #{content}` but didn't set base_url in your configuration file.\n"
|
45
45
|
end
|
46
46
|
|
47
47
|
%(<p class="file"><span><strong>Download</strong> <a href="#{url}">#{content}</a></span></p>)
|
@@ -105,7 +105,18 @@ class BlackCloth < RedCloth
|
|
105
105
|
# Usage: figure(This is the caption). some_image.jpg
|
106
106
|
def textile_figure(tag, attrs, cite, content)
|
107
107
|
m, title = *attrs.match(/class="(.*?)"/)
|
108
|
-
|
108
|
+
|
109
|
+
width, height = image_size(content)
|
110
|
+
|
111
|
+
%(<p class="figure"><img style="width: #{width}px; height: #{height}px" src="../images/#{content}" alt="#{title}" /><br/><span class="caption">#{title}</span></p>)
|
112
|
+
end
|
113
|
+
|
114
|
+
def image_size(img)
|
115
|
+
puts File.expand_path(img)
|
116
|
+
output = IO.popen("file images/#{img}").read
|
117
|
+
m, width, height = *output.match(/([0-9]+) x ([0-9]+)/)
|
118
|
+
|
119
|
+
[width.to_i, height.to_i]
|
109
120
|
end
|
110
121
|
|
111
122
|
# overriding inline method
|
data/lib/kitabu/markup.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Kitabu
|
2
2
|
module Markup
|
3
|
-
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def content_for(options)
|
4
6
|
source_file = File.join(KITABU_ROOT, 'code', options[:source_file].to_s)
|
5
7
|
code = options[:code]
|
6
8
|
|
@@ -44,7 +46,7 @@ module Kitabu
|
|
44
46
|
code
|
45
47
|
end
|
46
48
|
|
47
|
-
def
|
49
|
+
def syntax(code, syntax='plain_text')
|
48
50
|
# get chosen theme
|
49
51
|
theme = Kitabu::Base.config['theme']
|
50
52
|
theme = Kitabu::Base.default_theme unless Kitabu::Base.theme?(theme)
|
data/lib/kitabu/tasks.rb
CHANGED
@@ -36,7 +36,7 @@ namespace :kitabu do
|
|
36
36
|
task :pdf => :html do
|
37
37
|
Kitabu::Base.generate_pdf
|
38
38
|
puts "Your PDF has been generated. Check it out the output directory!"
|
39
|
-
sleep(1) && system("open #{Kitabu::Base.pdf_path}") if RUBY_PLATFORM =~ /darwin/
|
39
|
+
sleep(1) && system("open #{Kitabu::Base.pdf_path}") if RUBY_PLATFORM =~ /darwin/ && ENV["AUTO_OPEN"] == "1"
|
40
40
|
end
|
41
41
|
|
42
42
|
desc "Generate HTML from markup files"
|
data/lib/kitabu/templates.rb
CHANGED
@@ -3,14 +3,16 @@ module Kitabu
|
|
3
3
|
TEMPLATES_ROOT = File.join(Kitabu::Base::GEM_ROOT, 'templates')
|
4
4
|
DIRECTORIES = %w(text templates output)
|
5
5
|
|
6
|
-
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def process!(options)
|
7
9
|
directories!(options)
|
8
10
|
bundle_css!(options)
|
9
11
|
files!(options)
|
10
12
|
config!(options)
|
11
13
|
end
|
12
14
|
|
13
|
-
def
|
15
|
+
def directories!(options)
|
14
16
|
FileUtils.mkdir(options[:path])
|
15
17
|
|
16
18
|
DIRECTORIES.each do |d|
|
@@ -18,14 +20,14 @@ module Kitabu
|
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
|
-
def
|
23
|
+
def files!(options)
|
22
24
|
copy_file "Rakefile", "#{options[:path]}/Rakefile"
|
23
25
|
copy_file "layouts/#{options[:layout]}/layout.css", "#{options[:path]}/templates/layout.css"
|
24
26
|
copy_file "layouts/#{options[:layout]}/layout.html", "#{options[:path]}/templates/layout.html"
|
25
27
|
copy_file "user.css", "#{options[:path]}/templates/user.css"
|
26
28
|
end
|
27
29
|
|
28
|
-
def
|
30
|
+
def config!(options)
|
29
31
|
template = File.new(File.join(TEMPLATES_ROOT, 'config.yml')).read
|
30
32
|
env = OpenStruct.new(options)
|
31
33
|
contents = ERB.new(template).result env.instance_eval{binding}
|
@@ -33,7 +35,7 @@ module Kitabu
|
|
33
35
|
File.open(File.join(options[:path], 'config.yml'), 'w+') << contents
|
34
36
|
end
|
35
37
|
|
36
|
-
def
|
38
|
+
def bundle_css!(options)
|
37
39
|
contents = Dir["#{TEMPLATES_ROOT}/themes/*.css"].collect do |file|
|
38
40
|
File.read(file)
|
39
41
|
end
|
@@ -42,7 +44,7 @@ module Kitabu
|
|
42
44
|
end
|
43
45
|
|
44
46
|
private
|
45
|
-
def
|
47
|
+
def copy_file(from, to)
|
46
48
|
FileUtils.cp File.join(TEMPLATES_ROOT, from), to
|
47
49
|
end
|
48
50
|
end
|
data/lib/kitabu/toc.rb
CHANGED
@@ -27,11 +27,6 @@ module Kitabu
|
|
27
27
|
@current_level = name.gsub!(/[^2-6]/, '').to_i
|
28
28
|
@stack << @current_level
|
29
29
|
@id = attrs["id"]
|
30
|
-
|
31
|
-
@toc << %(<ul class="level#{@current_level}">) if @current_level > @previous_level
|
32
|
-
@toc << %(</li></ul>) * (@previous_level - @current_level) if @current_level < @previous_level
|
33
|
-
@toc << %(</li>) if @current_level <= @previous_level
|
34
|
-
@toc << %(<li>)
|
35
30
|
end
|
36
31
|
|
37
32
|
def tag_end(name)
|
@@ -42,16 +37,14 @@ module Kitabu
|
|
42
37
|
|
43
38
|
def text(str)
|
44
39
|
return unless in_header?
|
45
|
-
@toc << %(<a href="##{@id}"><span>#{str}</span></a>)
|
40
|
+
@toc << %(<div class="level#{@current_level} #{@id}"><a href="##{@id}"><span>#{str}</span></a></div>)
|
46
41
|
end
|
47
42
|
|
48
43
|
def method_missing(*args)
|
49
44
|
end
|
50
45
|
|
51
46
|
def to_s
|
52
|
-
@toc
|
53
|
-
rescue
|
54
|
-
""
|
47
|
+
@toc
|
55
48
|
end
|
56
49
|
end
|
57
50
|
end
|
data/templates/config.yml
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
title: [Your Book Title]
|
2
|
-
|
1
|
+
title: "[Your Book Title]"
|
2
|
+
year: 2009
|
3
3
|
authors:
|
4
|
-
- [Your Name]
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
- "[Your Name]"
|
5
|
+
subject: "[Your book description]"
|
6
|
+
keywords: "[Your book keywords (comma-separated)]"
|
7
|
+
theme: idle
|
8
|
+
base_url: http://example.com
|
9
|
+
copyright: "[Your copyright info]"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fnando-kitabu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
@@ -9,8 +9,8 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
13
|
-
default_executable:
|
12
|
+
date: 2009-08-02 00:00:00 -07:00
|
13
|
+
default_executable: kitabu
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: discount
|
@@ -62,21 +62,21 @@ dependencies:
|
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: "0"
|
64
64
|
version:
|
65
|
-
description: A framework for creating e-books from Markdown/Textile text markup using Ruby.
|
66
|
-
email:
|
67
|
-
- fnando.vieira@gmail.com
|
65
|
+
description: A framework for creating e-books from Markdown/Textile text markup using Ruby. Using the Prince PDF generator, you'll be able to get high quality PDFs.
|
66
|
+
email: fnando.vieira@gmail.com
|
68
67
|
executables:
|
69
68
|
- kitabu
|
70
69
|
extensions: []
|
71
70
|
|
72
|
-
extra_rdoc_files:
|
73
|
-
|
71
|
+
extra_rdoc_files:
|
72
|
+
- README.markdown
|
74
73
|
files:
|
75
|
-
- Rakefile
|
76
|
-
- kitabu.gemspec
|
77
74
|
- README.markdown
|
75
|
+
- Rakefile
|
76
|
+
- VERSION
|
78
77
|
- bin/kitabu
|
79
|
-
-
|
78
|
+
- kitabu.gemspec
|
79
|
+
- lib/kitabu.rb
|
80
80
|
- lib/kitabu/base.rb
|
81
81
|
- lib/kitabu/blackcloth.rb
|
82
82
|
- lib/kitabu/markup.rb
|
@@ -84,15 +84,11 @@ files:
|
|
84
84
|
- lib/kitabu/tasks.rb
|
85
85
|
- lib/kitabu/templates.rb
|
86
86
|
- lib/kitabu/toc.rb
|
87
|
-
-
|
87
|
+
- templates/Rakefile
|
88
88
|
- templates/config.yml
|
89
|
-
- templates/layouts
|
90
|
-
- templates/layouts/boom
|
91
89
|
- templates/layouts/boom/layout.css
|
92
90
|
- templates/layouts/boom/layout.html
|
93
|
-
- templates/Rakefile
|
94
91
|
- templates/syntax.css
|
95
|
-
- templates/themes
|
96
92
|
- templates/themes/active4d.css
|
97
93
|
- templates/themes/blackboard.css
|
98
94
|
- templates/themes/dawn.css
|
@@ -104,11 +100,12 @@ files:
|
|
104
100
|
- templates/themes/slush_poppies.css
|
105
101
|
- templates/themes/sunburst.css
|
106
102
|
- templates/user.css
|
107
|
-
has_rdoc:
|
108
|
-
homepage: http://github.com/
|
103
|
+
has_rdoc: false
|
104
|
+
homepage: http://fnando.github.com/kitabu.html
|
105
|
+
licenses:
|
109
106
|
post_install_message:
|
110
|
-
rdoc_options:
|
111
|
-
|
107
|
+
rdoc_options:
|
108
|
+
- --charset=UTF-8
|
112
109
|
require_paths:
|
113
110
|
- lib
|
114
111
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -126,9 +123,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
123
|
requirements:
|
127
124
|
- Install the Oniguruma RE library
|
128
125
|
rubyforge_project:
|
129
|
-
rubygems_version: 1.
|
126
|
+
rubygems_version: 1.3.5
|
130
127
|
signing_key:
|
131
|
-
specification_version:
|
128
|
+
specification_version: 3
|
132
129
|
summary: A framework for creating e-books from Markdown/Textile text markup using Ruby.
|
133
130
|
test_files: []
|
134
131
|
|