codex 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +31 -0
- data/Manifest.txt +83 -62
- data/Rakefile +2 -0
- data/app_generators/codex/codex_generator.rb +35 -20
- data/app_generators/codex/templates/Rakefile +14 -53
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/CSS.html +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/CSharp.html +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/CollapseCode.html +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Cpp.html +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/CrashTest.html +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Delphi.html +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/FirstLine.html +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Index.html +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Java.html +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/JavaScript.html +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/NoControls.html +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/NoGutter.html +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/PHP.html +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Python.html +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Ruby.html +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/SQL.html +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Scripts/clipboard.swf +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Scripts/shBrushCSharp.js +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Scripts/shBrushCpp.js +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Scripts/shBrushCss.js +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Scripts/shBrushDelphi.js +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Scripts/shBrushJScript.js +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Scripts/shBrushJava.js +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Scripts/shBrushPhp.js +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Scripts/shBrushPython.js +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Scripts/shBrushRuby.js +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Scripts/shBrushSql.js +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Scripts/shBrushVb.js +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Scripts/shBrushXml.js +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Scripts/shCore.js +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Scripts/shCore.uncompressed.js +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/ShowColumns.html +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/SmartTabs.html +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Styles/SyntaxHighlighter.css +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Styles/TestPages.css +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/Templates/Test.dwt +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/VB.html +0 -0
- data/app_generators/codex/templates/{dp.SyntaxHighlighter → assets/dp.SyntaxHighlighter}/XML.html +0 -0
- data/{lib → app_generators/codex/templates/assets}/stylesheets/pressie.css +10 -7
- data/{lib → app_generators/codex/templates/assets}/stylesheets/print.css +0 -0
- data/{lib → app_generators/codex/templates/assets}/stylesheets/ruby.png +0 -0
- data/app_generators/codex/templates/{ui → assets/ui}/default/blank.gif +0 -0
- data/app_generators/codex/templates/{ui → assets/ui}/default/bodybg.gif +0 -0
- data/app_generators/codex/templates/{ui → assets/ui}/default/framing.css +0 -0
- data/app_generators/codex/templates/{ui → assets/ui}/default/iepngfix.htc +0 -0
- data/app_generators/codex/templates/{ui → assets/ui}/default/opera.css +0 -0
- data/app_generators/codex/templates/{ui → assets/ui}/default/outline.css +0 -0
- data/app_generators/codex/templates/{ui → assets/ui}/default/pretty.css +0 -0
- data/app_generators/codex/templates/{ui → assets/ui}/default/print.css +0 -0
- data/app_generators/codex/templates/{ui → assets/ui}/default/s5-core.css +0 -0
- data/app_generators/codex/templates/{ui → assets/ui}/default/slides.css +0 -0
- data/app_generators/codex/templates/{ui → assets/ui}/default/slides.js +0 -0
- data/app_generators/codex/templates/bin/build_all.rb +4 -3
- data/app_generators/codex/templates/code/graphviz/graph.dot +13 -0
- data/app_generators/codex/templates/{slides → config}/metadata.yml +1 -0
- data/app_generators/codex/templates/content/basics.textile +42 -0
- data/app_generators/codex/templates/{slides/building.slides → content/building.textile} +2 -2
- data/app_generators/codex/templates/{slides/example.slides → content/example.textile} +2 -1
- data/app_generators/codex/templates/content/graphviz.textile +35 -0
- data/app_generators/codex/templates/{slides/including_code.slides → content/including_code.textile} +9 -6
- data/app_generators/codex/templates/content/including_tex.textile +32 -0
- data/app_generators/codex/templates/{slides/table_of_contents.slides → content/table_of_contents.textile} +9 -0
- data/app_generators/codex/templates/content/user_defined.textile +83 -0
- data/app_generators/codex/templates/filters/example_filter.rb +13 -0
- data/app_generators/codex/templates/post_processors/change_code_urls.rb +16 -0
- data/app_generators/codex/templates/post_processors/upcase_titles.rb +15 -0
- data/app_generators/codex/templates/readme.txt +1 -1
- data/app_generators/codex/templates/templates/layout.erb +67 -0
- data/bin/codex +0 -0
- data/codex.gemspec +20 -7
- data/config/hoe.rb +2 -1
- data/config/requirements.rb +1 -1
- data/lib/codex.rb +16 -4
- data/lib/codex/content.rb +7 -151
- data/lib/codex/filter.rb +101 -0
- data/lib/codex/filters/code_filter.rb +92 -0
- data/lib/codex/filters/graphviz_filter.rb +112 -0
- data/lib/codex/filters/ritex_filter.rb +16 -0
- data/lib/codex/post_processor.rb +55 -0
- data/lib/codex/post_processors/01_slides_processor.rb +8 -0
- data/lib/codex/post_processors/02_add_title_slides.rb +11 -0
- data/lib/codex/pressie.rb +10 -97
- data/lib/codex/rake/codextask.rb +93 -0
- data/lib/codex/template_handler.rb +29 -0
- data/lib/codex/version.rb +2 -2
- data/test/codex/post_processor/test_add_title_slides_processor.rb +41 -0
- data/test/codex/post_processor/test_post_processors.rb +42 -0
- data/test/codex/post_processor/test_slides_processor.rb +31 -0
- data/test/codex/rake/test_codextask.rb +35 -0
- data/test/codex/test_pressie.rb +24 -0
- data/test/codex/test_template_handler.rb +28 -0
- data/test/test_codex_generator.rb +20 -26
- data/test/test_filter.rb +14 -0
- data/test/test_helper.rb +33 -1
- metadata +106 -70
- data/app_generators/codex/templates/bin/postprocess_all.rb +0 -5
- data/app_generators/codex/templates/bin/pressie.rb +0 -7
- data/app_generators/codex/templates/slides/basics.slides +0 -37
- data/test/test_codex.rb +0 -11
- data/test/test_generator_helper.rb +0 -29
@@ -0,0 +1,112 @@
|
|
1
|
+
# Graphviz filter
|
2
|
+
|
3
|
+
require 'digest/md5'
|
4
|
+
require 'facets/fileutils/which.rb'
|
5
|
+
|
6
|
+
module Codex::GraphvizFilter
|
7
|
+
OUTPUT_DIR="html/images/"
|
8
|
+
LINK_DIR="images/"
|
9
|
+
|
10
|
+
class Descriptor
|
11
|
+
attr_reader :engine, :width, :height, :file_name, :file_type
|
12
|
+
|
13
|
+
include FileUtils
|
14
|
+
|
15
|
+
raise "Graphviz ('dot') is not installed." unless which('dot')
|
16
|
+
|
17
|
+
def initialize(string)
|
18
|
+
@engine = "dot"
|
19
|
+
@file_type = "svg"
|
20
|
+
@width = nil
|
21
|
+
@height = nil
|
22
|
+
@file_name = nil
|
23
|
+
|
24
|
+
if string && string =~ /^\[(.*)\]/
|
25
|
+
@file_name = nil
|
26
|
+
parse_params($1.dup)
|
27
|
+
elsif string && string =~ /(.*?)\[(.*)\]/
|
28
|
+
@file_name = $1
|
29
|
+
parse_params($2.dup)
|
30
|
+
else
|
31
|
+
@file_name = string
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def parse_params(params)
|
36
|
+
params.split.each do |param|
|
37
|
+
if param =~ /(.*?)=(.*)/
|
38
|
+
case $1
|
39
|
+
when "engine"
|
40
|
+
@engine = $2
|
41
|
+
fail "Unknown engine value. Choices are: dot,neato,twopi and circo." unless @engine =~ /dot|neato|twopi|circo/
|
42
|
+
when "width"
|
43
|
+
@width = $2
|
44
|
+
when "height"
|
45
|
+
@height = $2
|
46
|
+
when "type"
|
47
|
+
@file_type = $2
|
48
|
+
fail "Unknown output format. Choices are: png,jpeg and svg" unless @file_type =~ /png|jpeg|svg/
|
49
|
+
when "options" # Additional options for graphviz
|
50
|
+
@extra_options = $2
|
51
|
+
else
|
52
|
+
fail "Unknown parameter #{$1} in '#{params}'"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def graphviz_cmd(outputfile)
|
59
|
+
exec = which(@engine)
|
60
|
+
file = (@file_name.nil? or @file_name.empty?)?"":File.expand_path(@file_name)
|
61
|
+
"#{exec} #{file} -T#{@file_type} -o#{outputfile} #{@extra_options}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class GraphViz < Codex::Filter
|
66
|
+
tag :graphviz
|
67
|
+
|
68
|
+
def filter_inline(text,args)
|
69
|
+
d = Descriptor.new(args)
|
70
|
+
output_file = "graphviz-" + Digest::MD5.hexdigest(text) + "." + d.file_type
|
71
|
+
IO.popen(d.graphviz_cmd(OUTPUT_DIR + output_file),"w") do |pipe|
|
72
|
+
pipe.write text
|
73
|
+
pipe.close_write
|
74
|
+
end
|
75
|
+
to_html(d,output_file)
|
76
|
+
end
|
77
|
+
|
78
|
+
def filter_single(args)
|
79
|
+
d = Descriptor.new(args)
|
80
|
+
output_file = File.basename(d.file_name) + "." + d.file_type
|
81
|
+
system d.graphviz_cmd(OUTPUT_DIR + output_file)
|
82
|
+
to_html(d,output_file)
|
83
|
+
end
|
84
|
+
|
85
|
+
def to_html(d,output_file)
|
86
|
+
if d.file_type == "svg"
|
87
|
+
%{<object type="image/svg+xml" name="graphviz" data="#{LINK_DIR + output_file}" #{width_html(d)} #{height_html(d)}">\n} +
|
88
|
+
%{If you a seeing this text, your browser probably doesn't support SVG. Try setting the filetype=png option instead.} +
|
89
|
+
%{</object>}
|
90
|
+
else
|
91
|
+
%{<img type="image/#{d.file_type}" name="#{d.file_name}" src="#{output_file}" #{width_html(d)} #{height_html(d)}">\n} +
|
92
|
+
%{</img>}
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def width_html(desc)
|
97
|
+
if desc.width.nil?
|
98
|
+
""
|
99
|
+
else
|
100
|
+
%{width="#{desc.width}"}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def height_html(desc)
|
105
|
+
if desc.height.nil?
|
106
|
+
""
|
107
|
+
else
|
108
|
+
%{width="#{desc.height}"}
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'ritex'
|
2
|
+
|
3
|
+
class RitexFilter < Codex::Filter
|
4
|
+
tag :webtex
|
5
|
+
|
6
|
+
# Expect something like
|
7
|
+
# :webtex \alpha\beta\gamma
|
8
|
+
def filter_single(text,args)
|
9
|
+
Ritex::Parser.new.parse(args)
|
10
|
+
end
|
11
|
+
|
12
|
+
# parse everythingenclosed in :inlinewebtex .. :end
|
13
|
+
def filter_inline(text,args)
|
14
|
+
Ritex::Parser.new.parse(text)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Codex
|
2
|
+
class PostProcessor
|
3
|
+
# Call this in your subclass to register the PostProcessor
|
4
|
+
def self.register
|
5
|
+
PostProcessors.instance << self
|
6
|
+
end
|
7
|
+
attr_reader :html
|
8
|
+
def initialize(html)
|
9
|
+
@html = html
|
10
|
+
end
|
11
|
+
def process
|
12
|
+
raise "Overwrite me!"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
class PostProcessors
|
16
|
+
include Singleton
|
17
|
+
def << (post_processor_class)
|
18
|
+
@post_processors << post_processor_class
|
19
|
+
end
|
20
|
+
def delete(post_processor_class)
|
21
|
+
@post_processors.delete(post_processor_class)
|
22
|
+
end
|
23
|
+
def process_all(html)
|
24
|
+
@new_html = html
|
25
|
+
@post_processors.each do |pp_class|
|
26
|
+
processor = pp_class.new(@new_html)
|
27
|
+
processor.process
|
28
|
+
@new_html = processor.html
|
29
|
+
end
|
30
|
+
@new_html
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def initialize
|
36
|
+
@post_processors = []
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
# Requires all Post Processores files inside the lib and the slides directory.
|
44
|
+
# Ignores errors so that processors that depend on external libs and gems
|
45
|
+
# that are not present won't break the app.
|
46
|
+
Dir.glob([
|
47
|
+
File.join(File.dirname(__FILE__), 'post_processors/*.rb'),
|
48
|
+
File.join(APP_ROOT, 'post_processors/*.rb')
|
49
|
+
]) do |post_processor|
|
50
|
+
begin
|
51
|
+
require(post_processor)
|
52
|
+
rescue Exception => e
|
53
|
+
;
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# This will divide the html in slides, surrounding <hN> tags
|
2
|
+
# plus the following text in @<div class="slide">(...)</div>@.
|
3
|
+
class Codex::SlidesProcessor < Codex::PostProcessor
|
4
|
+
register
|
5
|
+
def process
|
6
|
+
@html = @html.gsub(/(<h{1,6}.*?)(?=<h{1,6}|\z)/m, "\n<div class=\"slide\">\\1</div>")
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# This allows you to create title slides in the middle of presentations,
|
2
|
+
# using:
|
3
|
+
# h1(slide0). Slide that only has a title
|
4
|
+
# This is used by the @rake all@ task,
|
5
|
+
# that will build the @html/all.html@ file.
|
6
|
+
class Codex::AddTitleSlides < Codex::PostProcessor
|
7
|
+
register
|
8
|
+
def process
|
9
|
+
@html = @html.gsub(/<div class="slide">\s*<h1 class="slide0"/m, %{<div class="title slide">\n<h1})
|
10
|
+
end
|
11
|
+
end
|
data/lib/codex/pressie.rb
CHANGED
@@ -1,108 +1,21 @@
|
|
1
1
|
require 'yaml'
|
2
|
-
|
3
|
-
S5_HEAD = %{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
4
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
5
|
-
|
6
|
-
<html xmlns="http://www.w3.org/1999/xhtml">
|
7
|
-
|
8
|
-
<head>
|
9
|
-
<title>&title;</title>
|
10
|
-
<!-- metadata -->
|
11
|
-
<meta name="generator" content="S5" />
|
12
|
-
<meta name="version" content="S5 1.1" />
|
13
|
-
<meta name="presdate" content="&date" />
|
14
|
-
<meta name="author" content="&author;" />
|
15
|
-
<meta name="organization" content="&organization;" />
|
16
|
-
<meta name="company" content="&company;" />
|
17
|
-
<!-- configuration parameters -->
|
18
|
-
<meta name="defaultView" content="slideshow" />
|
19
|
-
<meta name="controlVis" content="hidden" />
|
20
|
-
<!-- style sheet links -->
|
21
|
-
<link rel="stylesheet" href="../ui/default/slides.css" type="text/css" media="projection" id="slideProj" />
|
22
|
-
<link rel="stylesheet" href="../ui/default/outline.css" type="text/css" media="screen" id="outlineStyle" />
|
23
|
-
<link rel="stylesheet" href="../lib/stylesheets/print.css" type="text/css" media="print" id="slidePrint" />
|
24
|
-
<link rel="stylesheet" href="../ui/default/opera.css" type="text/css" media="projection" id="operaFix" />
|
25
|
-
|
26
|
-
<link rel="stylesheet" href="../lib/stylesheets/pressie.css" type="text/css" />
|
27
|
-
|
28
|
-
<!-- S5 JS -->
|
29
|
-
<script src="../ui/default/slides.js" type="text/javascript"></script>
|
30
|
-
|
31
|
-
<!-- Syntax Highlighter -->
|
32
|
-
<link rel="stylesheet" href="../dp.SyntaxHighlighter/Styles/SyntaxHighlighter.css"></link>
|
33
|
-
|
34
|
-
</head>
|
35
|
-
<body>
|
36
|
-
|
37
|
-
<div class="layout">
|
38
|
-
<div id="controls"><!-- DO NOT EDIT --></div>
|
39
|
-
<div id="currentSlide"><!-- DO NOT EDIT --></div>
|
40
|
-
<div id="header"></div>
|
41
|
-
<div id="footer">
|
42
|
-
<h2>Copyright © ©right;</h2>
|
43
|
-
</div>
|
44
|
-
|
45
|
-
</div>
|
46
|
-
|
47
|
-
|
48
|
-
<div class="presentation">
|
49
|
-
}
|
50
|
-
|
51
|
-
S5_TAIL = %{
|
52
|
-
<!-- Syntax Highlighter -->
|
53
|
-
<script language="javascript" src="../dp.SyntaxHighlighter/Scripts/shCore.js"></script>
|
54
|
-
<script language="javascript" src="../dp.SyntaxHighlighter/Scripts/shBrushCpp.js"></script>
|
55
|
-
<script language="javascript" src="../dp.SyntaxHighlighter/Scripts/shBrushRuby.js"></script>
|
56
|
-
<script language="javascript" src="../dp.SyntaxHighlighter/Scripts/shBrushXml.js"></script>
|
57
|
-
<script language="javascript">
|
58
|
-
dp.SyntaxHighlighter.ClipboardSwf = '/flash/clipboard.swf';
|
59
|
-
dp.SyntaxHighlighter.HighlightAll('code');
|
60
|
-
</script>
|
61
|
-
</div>
|
62
|
-
</body>
|
63
|
-
</html>
|
64
|
-
}
|
65
|
-
|
2
|
+
require 'erb'
|
66
3
|
|
67
4
|
module Codex
|
68
5
|
class Pressie
|
69
|
-
|
70
|
-
def
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
def process
|
75
|
-
metadata_name = ARGV.shift || usage("Missing metadata file name")
|
76
|
-
load_metadata(metadata_name)
|
77
|
-
input_name = ARGV.shift || usage("Missing input file name")
|
78
|
-
content = Content.new(File.read(input_name)) rescue usage($!.message)
|
79
|
-
header = substitute_metadata_into(S5_HEAD)
|
80
|
-
puts header, content.to_html, S5_TAIL
|
81
|
-
end
|
82
|
-
|
83
|
-
|
84
|
-
private
|
85
|
-
|
86
|
-
def usage(msg = nil)
|
87
|
-
STDERR.puts "pressie.rb <metadatafile> <inputfile>"
|
88
|
-
if msg
|
89
|
-
STDERR.puts
|
90
|
-
STDERR.puts msg
|
6
|
+
|
7
|
+
def initialize(metadata)
|
8
|
+
YAML.load_file(metadata).each do |key, value|
|
9
|
+
instance_variable_set("@#{key}", value)
|
91
10
|
end
|
92
|
-
exit 1
|
93
11
|
end
|
94
12
|
|
95
|
-
def
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
def substitute_metadata_into(text)
|
100
|
-
text = text.dup
|
101
|
-
%w{author company organization date copyright title}.each do |key|
|
102
|
-
text.gsub!(/&#{key};/, @metadata[key]) if @metadata.has_key?(key)
|
13
|
+
def process(input, output)
|
14
|
+
content = Content.new(input).to_html
|
15
|
+
File.open(output, 'w') do |f|
|
16
|
+
f << ERB.new(File.read(File.join(Codex.root, 'templates', 'layout.erb'))).result(binding)
|
103
17
|
end
|
104
|
-
text
|
105
18
|
end
|
106
|
-
|
19
|
+
|
107
20
|
end
|
108
21
|
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'codex'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/tasklib'
|
4
|
+
|
5
|
+
module Codex
|
6
|
+
module Rake
|
7
|
+
class CodexTask < ::Rake::TaskLib
|
8
|
+
attr_accessor :name
|
9
|
+
|
10
|
+
# Directory of the source content. Defaults to 'content'
|
11
|
+
attr_accessor :content_dir
|
12
|
+
|
13
|
+
# Directory to output the built files into. Defaults to 'html'
|
14
|
+
attr_accessor :output_dir
|
15
|
+
|
16
|
+
# Metadata filename. Defaults to config/metadata.yml
|
17
|
+
attr_accessor :metadata
|
18
|
+
|
19
|
+
def initialize(name = :codex)
|
20
|
+
@name = name
|
21
|
+
@content_dir = 'content'
|
22
|
+
@output_dir = 'html'
|
23
|
+
@metadata = "config/metadata.yml"
|
24
|
+
yield self if block_given?
|
25
|
+
define
|
26
|
+
end
|
27
|
+
|
28
|
+
def content_path
|
29
|
+
File.join(*[Codex.root, content_dir].compact)
|
30
|
+
end
|
31
|
+
|
32
|
+
def output_path
|
33
|
+
File.join(*[Codex.root, output_dir].compact)
|
34
|
+
end
|
35
|
+
|
36
|
+
def contents
|
37
|
+
Dir.chdir(content_path) do
|
38
|
+
filelist = FileList["*"]
|
39
|
+
filelist.resolve
|
40
|
+
filelist
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def define
|
45
|
+
@output = []
|
46
|
+
pressie = Codex::Pressie.new(metadata)
|
47
|
+
|
48
|
+
contents.each do |file|
|
49
|
+
input_file = File.join(content_dir, file)
|
50
|
+
output_file = File.join(output_dir, file.ext('.html'))
|
51
|
+
@output << output_file
|
52
|
+
desc "Build #{output_file} from #{input_file}"
|
53
|
+
file output_file => [output_dir, input_file] do
|
54
|
+
pressie.process(input_file, output_file)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
task :default => name
|
59
|
+
|
60
|
+
desc "Build all the content"
|
61
|
+
task name => @output
|
62
|
+
|
63
|
+
# FIXME: clean up all this
|
64
|
+
all_html = File.join(output_dir, "all.html")
|
65
|
+
|
66
|
+
task :remove_tmp do
|
67
|
+
FileUtils.rm_rf("tmp")
|
68
|
+
end
|
69
|
+
|
70
|
+
desc "Build all based on the contents of content/table_of_contents.textile"
|
71
|
+
task :all => [ 'tmp', output_dir, all_html, :remove_tmp ]
|
72
|
+
|
73
|
+
desc "Remove all generated output and temporary files"
|
74
|
+
task :clean => "#{name}:remove_tmp" do
|
75
|
+
FileUtils.rm_rf output_path
|
76
|
+
end
|
77
|
+
|
78
|
+
task all_html => 'tmp/all.textile' do
|
79
|
+
pressie.process('tmp/all.textile', all_html)
|
80
|
+
end
|
81
|
+
|
82
|
+
task 'tmp/all.textile' => @output do
|
83
|
+
sh "ruby bin/build_all.rb #{metadata} #{content_dir}/table_of_contents.textile tmp/all.textile"
|
84
|
+
end
|
85
|
+
|
86
|
+
directory "tmp"
|
87
|
+
|
88
|
+
directory output_dir
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Codex
|
2
|
+
class TemplateHandler
|
3
|
+
include Singleton
|
4
|
+
|
5
|
+
attr_reader :handlers
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
# just return the content for unknown formats
|
9
|
+
@handlers = Hash.new(lambda {|c| c })
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.register(extension, &klass)
|
13
|
+
instance.handlers[extension.to_s] = klass
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.choose(file)
|
17
|
+
instance.handlers[File.extname(file.to_s).sub(/^\./, '')]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Codex::TemplateHandler.register :textile do |content|
|
23
|
+
require 'redcloth'
|
24
|
+
RedCloth.new(content).to_html
|
25
|
+
end
|
26
|
+
Codex::TemplateHandler.register :markdown do |content|
|
27
|
+
require 'bluecloth'
|
28
|
+
BlueCloth.new(content).to_html
|
29
|
+
end
|