kitabu 0.4.6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +7 -7
- data/kitabu.gemspec +5 -4
- data/lib/kitabu.rb +7 -3
- data/lib/kitabu/blackcloth.rb +33 -28
- data/spec/kitabu/blackcloth_spec.rb +10 -5
- metadata +21 -11
data/Rakefile
CHANGED
@@ -4,22 +4,22 @@ require File.dirname(__FILE__) + "/lib/kitabu"
|
|
4
4
|
|
5
5
|
JEWEL = Jeweler::Tasks.new do |gem|
|
6
6
|
gem.name = "kitabu"
|
7
|
-
gem.version = Kitabu::VERSION
|
7
|
+
gem.version = ENV["VERSION"] || Kitabu::VERSION
|
8
8
|
gem.summary = "A framework for creating e-books from Markdown/Textile text markup using Ruby."
|
9
9
|
gem.description = <<-TXT
|
10
|
-
A framework for creating e-books from Markdown/Textile text markup using Ruby.
|
10
|
+
A framework for creating e-books from Markdown/Textile text markup using Ruby.
|
11
11
|
With Prince PDF generator, you'll be able to get high quality PDFs.
|
12
12
|
TXT
|
13
|
-
|
13
|
+
|
14
14
|
gem.authors = ["Nando Vieira"]
|
15
15
|
gem.email = "fnando.vieira@gmail.com"
|
16
16
|
gem.homepage = "http://fnando.github.com/public/kitabu.html"
|
17
|
-
|
17
|
+
|
18
18
|
gem.has_rdoc = false
|
19
19
|
gem.files = %w(Rakefile kitabu.gemspec VERSION README.markdown) + Dir["{bin,templates,lib}/**/*"]
|
20
20
|
gem.bindir = "bin"
|
21
21
|
gem.executables = "kitabu"
|
22
|
-
|
22
|
+
|
23
23
|
gem.add_dependency "activesupport", ">=2.3"
|
24
24
|
end
|
25
25
|
|
@@ -30,8 +30,8 @@ end
|
|
30
30
|
|
31
31
|
desc "Generate gemspec and build gem"
|
32
32
|
task :build_gem do
|
33
|
-
File.open("VERSION", "w+") {|f| f << Kitabu::VERSION.to_s }
|
34
|
-
|
33
|
+
File.open("VERSION", "w+") {|f| f << (ENV["VERSION"] || Kitabu::VERSION.to_s) }
|
34
|
+
|
35
35
|
Rake::Task["gemspec"].invoke
|
36
36
|
Rake::Task["build"].invoke
|
37
37
|
end
|
data/kitabu.gemspec
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{kitabu}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Nando Vieira"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-03-12}
|
13
13
|
s.default_executable = %q{kitabu}
|
14
|
-
s.description = %q{A framework for creating e-books from Markdown/Textile text markup using Ruby.
|
14
|
+
s.description = %q{A framework for creating e-books from Markdown/Textile text markup using Ruby.
|
15
15
|
With Prince PDF generator, you'll be able to get high quality PDFs.
|
16
16
|
}
|
17
17
|
s.email = %q{fnando.vieira@gmail.com}
|
@@ -465,10 +465,11 @@ With Prince PDF generator, you'll be able to get high quality PDFs.
|
|
465
465
|
"templates/themes/sunburst.css",
|
466
466
|
"templates/user.css"
|
467
467
|
]
|
468
|
+
s.has_rdoc = false
|
468
469
|
s.homepage = %q{http://fnando.github.com/public/kitabu.html}
|
469
470
|
s.rdoc_options = ["--charset=UTF-8"]
|
470
471
|
s.require_paths = ["lib"]
|
471
|
-
s.rubygems_version = %q{1.3.
|
472
|
+
s.rubygems_version = %q{1.3.6}
|
472
473
|
s.summary = %q{A framework for creating e-books from Markdown/Textile text markup using Ruby.}
|
473
474
|
s.test_files = [
|
474
475
|
"spec/exit_matcher.rb",
|
data/lib/kitabu.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require "rubygems"
|
3
2
|
require "yaml"
|
4
3
|
require "erb"
|
5
4
|
require "ostruct"
|
6
5
|
require "rexml/streamlistener"
|
7
6
|
require "rexml/document"
|
8
|
-
|
7
|
+
|
8
|
+
begin
|
9
|
+
require "active_support/all"
|
10
|
+
rescue LoadError
|
11
|
+
require "active_support"
|
12
|
+
end
|
9
13
|
|
10
14
|
$:.unshift File.dirname(__FILE__)
|
11
15
|
|
@@ -46,5 +50,5 @@ rescue LoadError => e
|
|
46
50
|
end
|
47
51
|
|
48
52
|
module Kitabu
|
49
|
-
VERSION = "0.4.
|
53
|
+
VERSION = "0.4.7"
|
50
54
|
end
|
data/lib/kitabu/blackcloth.rb
CHANGED
@@ -1,53 +1,53 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
class BlackCloth < RedCloth
|
3
3
|
@@syntax_blocks = []
|
4
|
-
|
4
|
+
|
5
5
|
FN_RE = /
|
6
6
|
(\s+)? # getting spaces
|
7
7
|
%\{ # opening
|
8
8
|
(.*?) # footnote
|
9
9
|
\}# # closing
|
10
10
|
/xm
|
11
|
-
|
11
|
+
|
12
12
|
# Usage: Writing some text with a footnote %{this is a footnote}
|
13
13
|
def inline_textile_fn(text)
|
14
14
|
text.gsub!( FN_RE ) do |m|
|
15
15
|
%(<span class="footnote">#{$2}</span>)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
text
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
FN_URL_LINK = /
|
22
22
|
<
|
23
23
|
((?:https?|ftp):\/\/.*?)
|
24
24
|
>
|
25
25
|
/x
|
26
|
-
|
26
|
+
|
27
27
|
# Usage: <http://google.com>
|
28
28
|
def inline_textile_url_link(text)
|
29
29
|
text.gsub!( FN_URL_LINK ) do |m|
|
30
30
|
%(<a href="#{$1}">#{$1}</a>)
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
# Usage:
|
35
35
|
# file. app/models/users.rb
|
36
36
|
#
|
37
37
|
# Remember to set `base_url` in your Kitabu configuration file
|
38
38
|
def textile_file(tag, attrs, cite, content)
|
39
39
|
base_url = Kitabu::Base.config["base_url"]
|
40
|
-
|
40
|
+
|
41
41
|
if base_url
|
42
42
|
url = File.join(base_url, content)
|
43
43
|
else
|
44
44
|
url = content
|
45
45
|
$stdout << "\nYou're using `file. #{content}` but didn't set base_url in your configuration file.\n"
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
%(<p class="file"><span><strong>Download</strong> <a href="#{url}">#{content}</a></span></p>)
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
# Usage:
|
52
52
|
# syntax(ruby). Some code
|
53
53
|
#
|
@@ -68,13 +68,13 @@ class BlackCloth < RedCloth
|
|
68
68
|
|
69
69
|
# set source
|
70
70
|
source_file = content
|
71
|
-
|
71
|
+
|
72
72
|
# get block name
|
73
73
|
m, block_name = *attrs.match(/id="(.*?)"/ms)
|
74
|
-
|
74
|
+
|
75
75
|
# get line interval
|
76
76
|
m, from_line, to_line = *attrs.match(/class=".*? ([0-9]+),([0-9]+)"/)
|
77
|
-
|
77
|
+
|
78
78
|
content = Kitabu::Syntax.content_for({
|
79
79
|
:code => content,
|
80
80
|
:syntax => syntax,
|
@@ -83,62 +83,67 @@ class BlackCloth < RedCloth
|
|
83
83
|
:from_line => from_line,
|
84
84
|
:to_line => to_line
|
85
85
|
})
|
86
|
-
|
86
|
+
|
87
87
|
@@syntax_blocks << [syntax, content]
|
88
88
|
position = @@syntax_blocks.size - 1
|
89
89
|
%(@syntax:#{position})
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
def syntax_blocks
|
93
93
|
@@syntax_blocks
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
# Usage: pre. Some code
|
97
97
|
def textile_pre(*args)
|
98
98
|
# Should I add the default theme as a class?
|
99
99
|
send(:textile_syntax, *args)
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
# Usage: note. Some text
|
103
103
|
def textile_note(tag, attrs, cite, content)
|
104
104
|
%(<p class="note">#{content}</p>)
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
|
+
# Usage: attention. Some text
|
108
|
+
def textile_attention(tag, attrs, cite, content)
|
109
|
+
%(<p class="attention">#{content}</p>)
|
110
|
+
end
|
111
|
+
|
107
112
|
# Usage: figure(This is the caption). some_image.jpg
|
108
113
|
def textile_figure(tag, attrs, cite, content)
|
109
114
|
m, title = *attrs.match(/class="(.*?)"/)
|
110
|
-
|
115
|
+
|
111
116
|
width, height = image_size(content)
|
112
|
-
|
117
|
+
|
113
118
|
%(<p class="figure"><img style="width: #{width}px; height: #{height}px" src="../images/#{content}" alt="#{title}" /><br/><span class="caption">#{title}</span></p>)
|
114
119
|
end
|
115
|
-
|
120
|
+
|
116
121
|
def image_size(img)
|
117
122
|
IO.popen("file #{Kitabu::Base.root_path}/images/#{img}") do |io|
|
118
123
|
m, width, height = *io.read.match(/([0-9]+) x ([0-9]+)/)
|
119
124
|
return [width.to_i, height.to_i]
|
120
125
|
end
|
121
126
|
end
|
122
|
-
|
127
|
+
|
123
128
|
# overriding inline method
|
124
|
-
def inline( text )
|
129
|
+
def inline( text )
|
125
130
|
@rules += [:inline_textile_fn, :inline_textile_url_link]
|
126
131
|
super
|
127
132
|
end
|
128
|
-
|
133
|
+
|
129
134
|
# overriding to_html method
|
130
135
|
def to_html( *rules )
|
131
136
|
rules = DEFAULT_RULES if rules.empty?
|
132
137
|
# make our working copy
|
133
138
|
text = self.dup
|
134
|
-
|
139
|
+
|
135
140
|
@urlrefs = {}
|
136
141
|
@shelf = []
|
137
142
|
textile_rules = [:refs_textile, :block_textile_table, :block_textile_lists,
|
138
143
|
:block_textile_prefix, :inline_textile_image, :inline_textile_link,
|
139
144
|
:inline_textile_code, :inline_textile_span, :glyphs_textile]
|
140
145
|
markdown_rules = [:refs_markdown, :block_markdown_setext, :block_markdown_atx, :block_markdown_rule,
|
141
|
-
:block_markdown_bq, :block_markdown_lists,
|
146
|
+
:block_markdown_bq, :block_markdown_lists,
|
142
147
|
:inline_markdown_reflink, :inline_markdown_link]
|
143
148
|
@rules = rules.collect do |rule|
|
144
149
|
case rule
|
@@ -152,14 +157,14 @@ class BlackCloth < RedCloth
|
|
152
157
|
end.flatten
|
153
158
|
|
154
159
|
# standard clean up
|
155
|
-
incoming_entities text
|
156
|
-
clean_white_space text
|
160
|
+
incoming_entities text
|
161
|
+
clean_white_space text
|
157
162
|
|
158
163
|
# start processor
|
159
164
|
@pre_list = []
|
160
165
|
rip_offtags text
|
161
166
|
no_textile text
|
162
|
-
hard_break text
|
167
|
+
hard_break text
|
163
168
|
unless @lite_mode
|
164
169
|
refs text
|
165
170
|
blocks text
|
@@ -9,26 +9,31 @@ describe "BlackCloth" do
|
|
9
9
|
p.should have_tag("span.caption", "The Rails logo")
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it "should parse note tag" do
|
14
14
|
@html = BlackCloth.new("note. Some important note!").to_html
|
15
15
|
@html.should have_tag("p.note", "Some important note!")
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
|
+
it "should parse attention tag" do
|
19
|
+
@html = BlackCloth.new("attention. Some warning note!").to_html
|
20
|
+
@html.should have_tag("p.attention", "Some warning note!")
|
21
|
+
end
|
22
|
+
|
18
23
|
it "should link to file" do
|
19
24
|
Kitabu::Base.should_receive(:config).and_return("base_url" => "http://example.com")
|
20
25
|
@html = BlackCloth.new("file. app/models/users.rb").to_html
|
21
|
-
|
26
|
+
|
22
27
|
@html.should have_tag("p.file") do |p|
|
23
28
|
p.should have_tag("a[@href=http://example.com/app/models/users.rb]", "app/models/users.rb")
|
24
29
|
end
|
25
30
|
end
|
26
|
-
|
31
|
+
|
27
32
|
it "should create footnote" do
|
28
33
|
@html = BlackCloth.new("Writing some text with a footnote %{this is a footnote}").to_html
|
29
34
|
@html.should == %(<p>Writing some text with a footnote<span class="footnote">this is a footnote</span></p>)
|
30
35
|
end
|
31
|
-
|
36
|
+
|
32
37
|
it "should link url" do
|
33
38
|
@html = BlackCloth.new("<http://example.com>").to_html
|
34
39
|
@html.should == %(<a href="http://example.com">http://example.com</a>)
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitabu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 4
|
8
|
+
- 7
|
9
|
+
version: 0.4.7
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Nando Vieira
|
@@ -9,21 +14,24 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-03-12 00:00:00 -03:00
|
13
18
|
default_executable: kitabu
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: activesupport
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 3
|
23
30
|
version: "2.3"
|
24
|
-
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
25
33
|
description: |
|
26
|
-
A framework for creating e-books from Markdown/Textile text markup using Ruby.
|
34
|
+
A framework for creating e-books from Markdown/Textile text markup using Ruby.
|
27
35
|
With Prince PDF generator, you'll be able to get high quality PDFs.
|
28
36
|
|
29
37
|
email: fnando.vieira@gmail.com
|
@@ -478,7 +486,7 @@ files:
|
|
478
486
|
- templates/themes/slush_poppies.css
|
479
487
|
- templates/themes/sunburst.css
|
480
488
|
- templates/user.css
|
481
|
-
has_rdoc:
|
489
|
+
has_rdoc: false
|
482
490
|
homepage: http://fnando.github.com/public/kitabu.html
|
483
491
|
licenses: []
|
484
492
|
|
@@ -491,18 +499,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
491
499
|
requirements:
|
492
500
|
- - ">="
|
493
501
|
- !ruby/object:Gem::Version
|
502
|
+
segments:
|
503
|
+
- 0
|
494
504
|
version: "0"
|
495
|
-
version:
|
496
505
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
497
506
|
requirements:
|
498
507
|
- - ">="
|
499
508
|
- !ruby/object:Gem::Version
|
509
|
+
segments:
|
510
|
+
- 0
|
500
511
|
version: "0"
|
501
|
-
version:
|
502
512
|
requirements: []
|
503
513
|
|
504
514
|
rubyforge_project:
|
505
|
-
rubygems_version: 1.3.
|
515
|
+
rubygems_version: 1.3.6
|
506
516
|
signing_key:
|
507
517
|
specification_version: 3
|
508
518
|
summary: A framework for creating e-books from Markdown/Textile text markup using Ruby.
|