Permalink
Browse files

Now markup files can be created outside a chapter folder.

Bug fix: Textile footnote extension wasn't considering breaklines.
Now the syntax.css file contains all syntaxes; easier to change theme.
  • Loading branch information...
fnando committed Jan 5, 2009
1 parent db14b86 commit cd3009922f7a4fc8e3bfa7a694876f5a4abf50e0
Showing with 1,120 additions and 33 deletions.
  1. +7 −0 README.markdown
  2. +1 −1 Rakefile
  3. +1 −1 kitabu.gemspec
  4. +27 −12 lib/kitabu/base.rb
  5. +1 −10 lib/kitabu/blackcloth.rb
  6. +10 −1 lib/kitabu/templates.rb
  7. +8 −8 templates/layouts/boom/layout.html
  8. +1,065 −0 templates/syntax.css
View
@@ -85,6 +85,13 @@ to use a sequential numbering as the name. Here's a sample:
- 03\_Windows\_instructions.markdown
- 04\_Ubuntu\_Linux\_instructions.markdown
+If you prefer, you can add a chapter per file:
+
+- text
+ - 01\_Introduction.markdown
+ - 02\_What\_is\_Ruby\_on\_Rails.markdown
+ - 03\_Installing\_Ruby\_on\_Rails.markdown
+
Note that you can use Textile or Markdown at the same time. Just use the
`.markdown` or `.textile` file extension.
View
@@ -38,7 +38,7 @@ namespace :gem do
spec.instance_variables.each do |ivar|
value = spec.instance_variable_get(ivar)
name = ivar.split("@").last
- value = Time.now if name == "date"
+ next if name == "date"
if name == 'version'
base_file = File.join(File.dirname(__FILE__), 'lib/kitabu/base.rb')
View
@@ -2,7 +2,6 @@
# RUN : 'rake gem:update_gemspec'
Gem::Specification.new do |s|
- s.date = "Thu Dec 25 12:29:24 -0200 2008"
s.authors = ["Nando Vieira"]
s.require_paths = ["lib"]
s.required_rubygems_version = ">= 0"
@@ -24,6 +23,7 @@ Gem::Specification.new do |s|
"templates/layouts/boom/layout.css",
"templates/layouts/boom/layout.html",
"templates/Rakefile",
+ "templates/syntax.css",
"templates/themes",
"templates/themes/active4d.css",
"templates/themes/blackboard.css",
View
@@ -54,7 +54,11 @@ def self.syntax(code, syntax='plain_text')
# get syntax
syntax = Kitabu::Base.default_syntax unless Kitabu::Base.syntax?(syntax)
- Uv.parse(code, "xhtml", syntax, false, theme)
+ code = Uv.parse(code, "xhtml", syntax, false, theme)
+ code.gsub!(/<pre class="(.*?)"/sim, %(<pre class="\\1 #{syntax}"))
+ code.gsub!(/<pre>/sim, %(<pre class="#{syntax} #{theme}"))
+
+ code
end
end
@@ -131,28 +135,39 @@ def self.generate_pdf
end
def self.generate_html
- # all parsed markdown file holder
+ # parsed file holder
contents = ""
+ entries = Dir.entries(text_dir).sort.reject do |entry|
+ %w(. .. .svn .git).include?(entry) || (File.file?(entry) && entry !~ /\.(markdown|textile)$/)
+ end
+
+ raise "No markup files found! Stopping PDF generation" if entries.empty?
+
# first, get all chapters; then, get all parsed markdown
# files from this chapter and group them into a <div class="chapter"> tag
- Dir.entries(text_dir).sort.each do |dirname|
- # ignore files and some directories
- next if %w(. .. .svn .git).include?(dirname) || File.file?(text_dir + "/#{dirname}")
-
+ entries.each do |entry|
# gets all parsed markdown files to wrap in a
# chapter element
chapter = ""
- # merge all markdown and textile files into a single list
- markup_files = Dir["#{text_dir}/#{dirname}/**/*.markdown"] + Dir["#{text_dir}/#{dirname}/**/*.textile"]
+ # entry can be a file outside chapter folder
+ file = "#{text_dir}/#{entry}"
+
+ if File.file?(file)
+ markup_files = [file]
+ else
+ # merge all markdown and textile files into a single list
+ markup_files = Dir["#{text_dir}/#{entry}/**/*.markdown"] +
+ Dir["#{text_dir}/#{entry}/**/*.textile"]
+ end
# no files, so skip it!
next if markup_files.empty?
markup_files.sort.each do |markup_file|
# get the file contents
- markup_contents = File.new(markup_file).read
+ markup_contents = File.read(markup_file)
# instantiate a markup object
begin
@@ -207,9 +222,9 @@ def self.generate_html
:block_name => block_name,
:source_file => source_file
})
-
- Kitabu::Markup.syntax(code, syntax)
end
+
+ Kitabu::Markup.syntax(code, syntax)
end
end
end
@@ -221,7 +236,7 @@ def self.generate_html
end
# create output directory if is missing
- FileUtils.mkdir(File.dirname(html_path))
+ FileUtils.mkdir(File.dirname(html_path)) unless File.exists?(File.dirname(html_path))
# save html file
File.open(html_path, 'w+') do |f|
View
@@ -6,7 +6,7 @@ class BlackCloth < RedCloth
%\{ # opening
(.*?) # footnote
\}# # closing
- /x
+ /xms
# Usage: Writing some text with a footnote %{this is a footnote}
def inline_textile_fn(text)
@@ -57,15 +57,6 @@ def textile_syntax(tag, attrs, cite, content)
# get line interval
m, from_line, to_line = *attrs.match(/class=".*? ([0-9]+),([0-9]+)"/)
- # code = Kitabu::Markup.syntax({
- # :code => content,
- # :syntax => syntax,
- # :source_file => source_file,
- # :block_name => block_name,
- # :from_line => from_line,
- # :to_line => to_line
- # })
-
content = Kitabu::Markup.content_for({
:code => content,
:syntax => syntax,
View
@@ -5,6 +5,7 @@ module Templates
def self.process!(options)
directories!(options)
+ bundle_css!(options)
files!(options)
config!(options)
end
@@ -18,7 +19,7 @@ def self.directories!(options)
end
def self.files!(options)
- copy_file "css/#{options[:theme]}.css", "#{options[:path]}/templates/syntax.css"
+ copy_file "Rakefile", "#{options[:path]}/Rakefile"
copy_file "layouts/#{options[:layout]}/layout.css", "#{options[:path]}/templates/layout.css"
copy_file "layouts/#{options[:layout]}/layout.html", "#{options[:path]}/templates/layout.html"
copy_file "user.css", "#{options[:path]}/templates/user.css"
@@ -32,6 +33,14 @@ def self.config!(options)
File.open(File.join(options[:path], 'config.yml'), 'w+') << contents
end
+ def self.bundle_css!(options)
+ contents = Dir["#{TEMPLATES_ROOT}/themes/*.css"].collect do |file|
+ File.read(file)
+ end
+
+ File.open("#{options[:path]}/templates/syntax.css", "w+") << contents.join("\n\n")
+ end
+
private
def self.copy_file(from, to)
FileUtils.cp File.join(TEMPLATES_ROOT, from), to
@@ -7,27 +7,27 @@
<link rel="stylesheet" type="text/css" href="../templates/syntax.css"/>
<link rel="stylesheet" type="text/css" href="../templates/user.css"/>
- <meta name="author" content="<%%= authors.join(', ') %>" />
- <meta name="subject" content="<%%= subject %>" />
- <meta name="keywords" content="<%%= keywords %>" />
+ <meta name="author" content="<%= authors.join(', ') %>" />
+ <meta name="subject" content="<%= subject %>" />
+ <meta name="keywords" content="<%= keywords %>" />
</head>
<body>
<div class="frontcover"></div>
<div class="halftitlepage">
- <h1 class="no-toc"><%%= title %></h1>
+ <h1 class="no-toc"><%= title %></h1>
</div>
<div class="titlepage">
- <h1 class="no-toc"><%%= title %></h1>
- <p class="no-toc"><%%= authors.join('<br/>') %></p>
+ <h1 class="no-toc"><%= title %></h1>
+ <p class="no-toc"><%= authors.join('<br/>') %></p>
</div>
<div class="imprint">
- <p><%%= copyright %></p>
+ <p><%= copyright %></p>
</div>
<div class="chapters">
- <%%= contents %>
+ <%= contents %>
</div>
<div class="white_page"></div>
Oops, something went wrong.

0 comments on commit cd30099

Please sign in to comment.