fnando-kitabu 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -120,8 +120,8 @@ Textile.
120
120
  To generate the TOC, you need to print a variable called `toc`, using the eRb
121
121
  tag `<%= toc %>`.
122
122
 
123
- Syntax Highlighting (Mac OS X)
124
- ==============================
123
+ Syntax Highlighting
124
+ ===================
125
125
 
126
126
  If you're using Textile, all you need to do is use the tag `syntax.`. For
127
127
  example, to highlight a code added right into your text, just do something like
@@ -176,9 +176,7 @@ or, if you have problem
176
176
  gem build kitabu.gemspec
177
177
  sudo gem install kitabu
178
178
 
179
- If you're a Mac user and have Textmate installed, you can
180
- generate HTML from your source code with syntax highlight,
181
- the same way you see in Textmate. First, you need to install
179
+ To have syntax highlighting support, you need to install
182
180
  Oniguruma regular expression library that can be found at
183
181
  [http://www.geocities.jp/kosako3/oniguruma/](http://www.geocities.jp/kosako3/oniguruma/)
184
182
 
@@ -186,6 +184,24 @@ Then, you need to install the Ultraviolet gem.
186
184
 
187
185
  sudo gem install ultraviolet
188
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
+
189
205
  REFERENCES:
190
206
  -----------
191
207
 
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ PKG_FILES = %w(Rakefile kitabu.gemspec README.markdown) + Dir["{bin,lib,template
4
4
 
5
5
  spec = Gem::Specification.new do |s|
6
6
  s.name = "kitabu"
7
- s.version = "0.3.1"
7
+ s.version = "0.3.2"
8
8
  s.summary = "A framework for creating e-books from Markdown/Textile text markup using Ruby."
9
9
  s.authors = ["Nando Vieira"]
10
10
  s.email = ["fnando.vieira@gmail.com"]
@@ -20,9 +20,10 @@ spec = Gem::Specification.new do |s|
20
20
  s.add_dependency "hpricot"
21
21
  s.add_dependency "unicode"
22
22
  s.add_dependency "main"
23
+ s.add_dependency "ultraviolet"
23
24
 
24
25
  # Requirements
25
- s.requirements << "Install the Oniguruma RE library and ultraviolet gem to get Syntax Highlighting (only for TextMate users)"
26
+ s.requirements << "Install the Oniguruma RE library"
26
27
  end
27
28
 
28
29
  namespace :gem do
data/kitabu.gemspec CHANGED
@@ -10,13 +10,14 @@ Gem::Specification.new do |s|
10
10
  s.bindir = "bin"
11
11
  s.executables = ["kitabu"]
12
12
  s.summary = "A framework for creating e-books from Markdown/Textile text markup using Ruby."
13
- s.requirements = ["Install the Oniguruma RE library and ultraviolet gem to get Syntax Highlighting (only for TextMate users)"]
13
+ s.requirements = ["Install the Oniguruma RE library"]
14
14
  s.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. Mac users that have Textmate installed can have source code highlighted with his favorite theme."
15
15
  s.add_dependency "discount", ">= 0"
16
16
  s.add_dependency "hpricot", ">= 0"
17
17
  s.add_dependency "unicode", ">= 0"
18
18
  s.add_dependency "main", ">= 0"
19
- s.version = "0.3.1"
19
+ s.add_dependency "ultraviolet", ">= 0"
20
+ s.version = "0.3.2"
20
21
  s.require_paths = ["lib"]
21
22
  s.files = ["Rakefile",
22
23
  "kitabu.gemspec",
@@ -25,9 +26,11 @@ Gem::Specification.new do |s|
25
26
  "lib/kitabu",
26
27
  "lib/kitabu/base.rb",
27
28
  "lib/kitabu/blackcloth.rb",
29
+ "lib/kitabu/markup.rb",
28
30
  "lib/kitabu/redcloth.rb",
29
31
  "lib/kitabu/tasks.rb",
30
32
  "lib/kitabu/templates.rb",
33
+ "lib/kitabu/toc.rb",
31
34
  "lib/kitabu.rb",
32
35
  "templates/config.yml",
33
36
  "templates/layouts",
data/lib/kitabu.rb CHANGED
@@ -1,15 +1,17 @@
1
- require 'rubygems'
2
- require 'yaml'
3
- require 'erb'
4
- require 'ostruct'
5
- require 'rexml/streamlistener'
6
- require 'rexml/document'
7
- require 'hpricot'
1
+ require "rubygems"
2
+ require "yaml"
3
+ require "erb"
4
+ require "ostruct"
5
+ require "rexml/streamlistener"
6
+ require "rexml/document"
7
+ require "hpricot"
8
8
 
9
- require 'kitabu/base'
9
+ require "kitabu/base"
10
+ require "kitabu/toc"
11
+ require "kitabu/markup"
10
12
 
11
13
  begin
12
- require 'ruby-debug'
14
+ require "ruby-debug"
13
15
  rescue LoadError => e
14
16
  nil
15
17
  end
data/lib/kitabu/base.rb CHANGED
@@ -1,66 +1,5 @@
1
1
  module Kitabu
2
- VERSION = "0.3.1"
3
-
4
- module Markup
5
- def self.content_for(options)
6
- source_file = File.join(KITABU_ROOT, 'code', options[:source_file].to_s)
7
- code = options[:code]
8
-
9
- if options[:source_file] && File.exists?(source_file)
10
- file = File.new(source_file)
11
-
12
- if options[:from_line] && options[:to_line]
13
- from_line = options[:from_line].to_i - 1
14
- to_line = options[:to_line].to_i
15
- offset = to_line - from_line
16
- code = file.readlines.slice(from_line, offset).join
17
- elsif block_name = options[:block_name]
18
- re = %r(# ?begin: ?\b#{block_name}\b ?(?:[^\r\n]+)?\r?\n(.*?)\r?\n([^\r\n]+)?# ?end: \b#{block_name}\b)sim
19
- file.read.gsub(re) { |block| code = $1 }
20
- else
21
- code = file.read
22
- code = code.gsub(/&lt;/, '<').gsub(/&gt;/, '>').gsub(/&amp;/, '&')
23
- end
24
- end
25
-
26
- # no code? set to default
27
- code ||= options[:code]
28
-
29
- # normalize indentation
30
- line = StringIO.new(code).readlines[0]
31
-
32
- if line =~ /^(\t+)/
33
- char = "\t"
34
- size = $1.length
35
- elsif line =~ /^( +)/
36
- char = " "
37
- size = $1.length
38
- end
39
-
40
- code.gsub! %r(^#{char}{#{size}}), "" if size.to_i > 0
41
-
42
- # remove all line stubs
43
- code.gsub! %r(^[\t ]*__$), ""
44
-
45
- # return
46
- code
47
- end
48
-
49
- def self.syntax(code, syntax='plain_text')
50
- # get chosen theme
51
- theme = Kitabu::Base.config['theme']
52
- theme = Kitabu::Base.default_theme unless Kitabu::Base.theme?(theme)
53
-
54
- # get syntax
55
- syntax = Kitabu::Base.default_syntax unless Kitabu::Base.syntax?(syntax)
56
-
57
- code = Uv.parse(code, "xhtml", syntax, false, theme)
58
- code.gsub!(/<pre class="(.*?)"/sim, %(<pre class="\\1 #{syntax}"))
59
- code.gsub!(/<pre>/sim, %(<pre class="#{syntax} #{theme}"))
60
-
61
- code
62
- end
63
- end
2
+ VERSION = "0.3.2"
64
3
 
65
4
  module Base
66
5
  DEFAULT_LAYOUT = 'boom'
@@ -98,7 +37,7 @@ module Kitabu
98
37
  cfg = config.merge(:contents => contents, :toc => toc)
99
38
  env = OpenStruct.new(cfg)
100
39
 
101
- ERB.new(template).result env.instance_eval{binding}
40
+ ERB.new(template).result env.instance_eval{ binding }
102
41
  end
103
42
 
104
43
  def self.table_of_contents(contents)
@@ -297,60 +236,4 @@ module Kitabu
297
236
  str
298
237
  end
299
238
  end
300
-
301
- class Toc
302
- include REXML::StreamListener
303
-
304
- def initialize
305
- @toc = ""
306
- @previous_level = 0
307
- @tag = nil
308
- @stack = []
309
- end
310
-
311
- def header?(tag=nil)
312
- tag ||= @tag_name
313
- return false unless tag.to_s =~ /h[2-6]/
314
- @tag_name = tag
315
- return true
316
- end
317
-
318
- def in_header?
319
- @in_header
320
- end
321
-
322
- def tag_start(name, attrs)
323
- @tag_name = name
324
- return unless header?(name)
325
- @in_header = true
326
- @current_level = name.gsub!(/[^2-6]/, '').to_i
327
- @stack << @current_level
328
- @id = attrs["id"]
329
-
330
- @toc << %(<ul class="level#{@current_level}">) if @current_level > @previous_level
331
- @toc << %(</li></ul>) * (@previous_level - @current_level) if @current_level < @previous_level
332
- @toc << %(</li>) if @current_level <= @previous_level
333
- @toc << %(<li>)
334
- end
335
-
336
- def tag_end(name)
337
- return unless header?(name)
338
- @in_header = false
339
- @previous_level = @current_level
340
- end
341
-
342
- def text(str)
343
- return unless in_header?
344
- @toc << %(<a href="##{@id}"><span>#{str}</span></a>)
345
- end
346
-
347
- def method_missing(*args)
348
- end
349
-
350
- def to_s
351
- @toc + (%(</li></ul>) * (@stack.last - 1))
352
- rescue
353
- ""
354
- end
355
- end
356
- end
239
+ end
@@ -0,0 +1,62 @@
1
+ module Kitabu
2
+ module Markup
3
+ def self.content_for(options)
4
+ source_file = File.join(KITABU_ROOT, 'code', options[:source_file].to_s)
5
+ code = options[:code]
6
+
7
+ if options[:source_file] && File.exists?(source_file)
8
+ file = File.new(source_file)
9
+
10
+ if options[:from_line] && options[:to_line]
11
+ from_line = options[:from_line].to_i - 1
12
+ to_line = options[:to_line].to_i
13
+ offset = to_line - from_line
14
+ code = file.readlines.slice(from_line, offset).join
15
+ elsif block_name = options[:block_name]
16
+ re = %r(# ?begin: ?\b#{block_name}\b ?(?:[^\r\n]+)?\r?\n(.*?)\r?\n([^\r\n]+)?# ?end: \b#{block_name}\b)sim
17
+ file.read.gsub(re) { |block| code = $1 }
18
+ else
19
+ code = file.read
20
+ code = code.gsub(/&lt;/, '<').gsub(/&gt;/, '>').gsub(/&amp;/, '&')
21
+ end
22
+ end
23
+
24
+ # no code? set to default
25
+ code ||= options[:code]
26
+
27
+ # normalize indentation
28
+ line = StringIO.new(code).readlines[0]
29
+
30
+ if line =~ /^(\t+)/
31
+ char = "\t"
32
+ size = $1.length
33
+ elsif line =~ /^( +)/
34
+ char = " "
35
+ size = $1.length
36
+ end
37
+
38
+ code.gsub! %r(^#{char}{#{size}}), "" if size.to_i > 0
39
+
40
+ # remove all line stubs
41
+ code.gsub! %r(^[\t ]*__$), ""
42
+
43
+ # return
44
+ code
45
+ end
46
+
47
+ def self.syntax(code, syntax='plain_text')
48
+ # get chosen theme
49
+ theme = Kitabu::Base.config['theme']
50
+ theme = Kitabu::Base.default_theme unless Kitabu::Base.theme?(theme)
51
+
52
+ # get syntax
53
+ syntax = Kitabu::Base.default_syntax unless Kitabu::Base.syntax?(syntax)
54
+
55
+ code = Uv.parse(code, "xhtml", syntax, false, theme)
56
+ code.gsub!(/<pre class="(.*?)"/sim, %(<pre class="\\1 #{syntax}"))
57
+ code.gsub!(/<pre>/sim, %(<pre class="#{syntax} #{theme}"))
58
+
59
+ code
60
+ end
61
+ end
62
+ end
data/lib/kitabu/tasks.rb CHANGED
@@ -11,7 +11,7 @@ require File.dirname(__FILE__) + "/redcloth"
11
11
  require File.dirname(__FILE__) + "/blackcloth"
12
12
 
13
13
  begin
14
- require "uv" if RUBY_PLATFORM =~ /darwin/
14
+ require "uv"
15
15
  rescue LoadError => e
16
16
  puts "\nUltraviolet gem not found. NO SYNTAX HIGHLIGHT for you.\n" +
17
17
  "Install using `sudo gem install ultraviolet`.\n\n"
data/lib/kitabu/toc.rb ADDED
@@ -0,0 +1,57 @@
1
+ module Kitabu
2
+ class Toc
3
+ include REXML::StreamListener
4
+
5
+ def initialize
6
+ @toc = ""
7
+ @previous_level = 0
8
+ @tag = nil
9
+ @stack = []
10
+ end
11
+
12
+ def header?(tag=nil)
13
+ tag ||= @tag_name
14
+ return false unless tag.to_s =~ /h[2-6]/
15
+ @tag_name = tag
16
+ return true
17
+ end
18
+
19
+ def in_header?
20
+ @in_header
21
+ end
22
+
23
+ def tag_start(name, attrs)
24
+ @tag_name = name
25
+ return unless header?(name)
26
+ @in_header = true
27
+ @current_level = name.gsub!(/[^2-6]/, '').to_i
28
+ @stack << @current_level
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
+ end
36
+
37
+ def tag_end(name)
38
+ return unless header?(name)
39
+ @in_header = false
40
+ @previous_level = @current_level
41
+ end
42
+
43
+ def text(str)
44
+ return unless in_header?
45
+ @toc << %(<a href="##{@id}"><span>#{str}</span></a>)
46
+ end
47
+
48
+ def method_missing(*args)
49
+ end
50
+
51
+ def to_s
52
+ @toc + (%(</li></ul>) * (@stack.last - 1))
53
+ rescue
54
+ ""
55
+ end
56
+ end
57
+ end
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.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
@@ -52,6 +52,16 @@ dependencies:
52
52
  - !ruby/object:Gem::Version
53
53
  version: "0"
54
54
  version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: ultraviolet
57
+ type: :runtime
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
55
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. Mac users that have Textmate installed can have source code highlighted with his favorite theme.
56
66
  email:
57
67
  - fnando.vieira@gmail.com
@@ -69,9 +79,11 @@ files:
69
79
  - lib/kitabu
70
80
  - lib/kitabu/base.rb
71
81
  - lib/kitabu/blackcloth.rb
82
+ - lib/kitabu/markup.rb
72
83
  - lib/kitabu/redcloth.rb
73
84
  - lib/kitabu/tasks.rb
74
85
  - lib/kitabu/templates.rb
86
+ - lib/kitabu/toc.rb
75
87
  - lib/kitabu.rb
76
88
  - templates/config.yml
77
89
  - templates/layouts
@@ -112,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
124
  version: "0"
113
125
  version:
114
126
  requirements:
115
- - Install the Oniguruma RE library and ultraviolet gem to get Syntax Highlighting (only for TextMate users)
127
+ - Install the Oniguruma RE library
116
128
  rubyforge_project:
117
129
  rubygems_version: 1.2.0
118
130
  signing_key: