asciidoc 0.0.1 → 0.0.2
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/asciidoc.gemspec +1 -1
- data/lib/asciidoc.rb +2 -0
- data/lib/asciidoc/asciicharplugins.rb +0 -1
- data/lib/asciidoc/asciidocument.rb +39 -5
- data/lib/asciidoc/asciielement.rb +11 -0
- data/lib/asciidoc/asciiplugins.rb +0 -1
- data/lib/asciidoc/macrohelper.rb +23 -0
- data/lib/asciidoc/plugins/chars/bold.rb +0 -2
- data/lib/asciidoc/plugins/lines/macro.rb +13 -0
- metadata +6 -5
- data/lib/asciidoc/plugins/lines/image.rb +0 -13
data/asciidoc.gemspec
CHANGED
data/lib/asciidoc.rb
CHANGED
@@ -9,18 +9,52 @@ module AsciiDoc
|
|
9
9
|
@lines = AsciiDoc::AsciiLines.new(content)
|
10
10
|
parse_lines
|
11
11
|
end
|
12
|
+
|
13
|
+
def render(format, template_folder, output_folder)
|
14
|
+
case format
|
15
|
+
when :html
|
16
|
+
render_html(template_folder, output_folder)
|
17
|
+
when :pdf
|
18
|
+
render_pdf(template_folder, output_folder)
|
19
|
+
else
|
20
|
+
raise "Bad Render Format Specified"
|
21
|
+
end
|
22
|
+
end
|
12
23
|
|
13
|
-
|
24
|
+
private
|
25
|
+
|
26
|
+
# Specific Render Functions
|
27
|
+
# ----------------------------------------------------------------
|
28
|
+
|
29
|
+
def render_html(template_folder, output_folder)
|
14
30
|
views = {}
|
15
|
-
Dir["
|
31
|
+
Dir["./#{template_folder}/views/*.html.erb"].each { |file|
|
16
32
|
symbol = file.split("/").last.split(".").first.to_sym
|
17
33
|
views[symbol] = ERB.new(open(file).read)
|
18
34
|
}
|
19
35
|
result = @element.render(views)
|
20
|
-
|
36
|
+
|
37
|
+
# if output folder does not exist, create it
|
38
|
+
Dir.mkdir("./#{output_folder}") unless File.exists?("./#{output_folder}")
|
39
|
+
|
40
|
+
# render html into index.html file
|
41
|
+
html = File.new("./#{output_folder}/index.html", "w+")
|
42
|
+
html.puts(result)
|
43
|
+
|
44
|
+
# copy all content in /public to the output folder
|
45
|
+
FileUtils.cp_r "./#{template_folder}/public/.", "./#{output_folder}"
|
46
|
+
|
47
|
+
"#{output_folder}/index.html"
|
48
|
+
end
|
49
|
+
|
50
|
+
def render_pdf(template_folder, output_folder)
|
51
|
+
Dir.mkdir("./#{output_folder}") unless File.exists?("./#{output_folder}")
|
52
|
+
file_path = render_html(template_folder, "#{output_folder}/temp")
|
53
|
+
output_path = "#{output_folder}/index.pdf"
|
54
|
+
`wkhtmltopdf #{file_path} #{output_path}`
|
55
|
+
FileUtils.rm_rf "./#{output_folder}/temp"
|
56
|
+
"#{output_folder}/index.pdf"
|
21
57
|
end
|
22
|
-
|
23
|
-
private
|
24
58
|
|
25
59
|
def parse_lines
|
26
60
|
order_plugins
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module AsciiDoc
|
2
|
+
module MacroHelper
|
3
|
+
|
4
|
+
# parses a string of attributes into a hash
|
5
|
+
# string must look like this: "key=value,key=value"
|
6
|
+
def self.parse_attributes(attributes_string, nokey = "nokey")
|
7
|
+
parsed = {}
|
8
|
+
values = attributes_string.split(",")
|
9
|
+
values.each do |value|
|
10
|
+
split = value.split("=")
|
11
|
+
|
12
|
+
if split.size == 1
|
13
|
+
split << split[0]
|
14
|
+
split[0] = nokey
|
15
|
+
end
|
16
|
+
|
17
|
+
parsed[split[0]] = split[1]
|
18
|
+
end
|
19
|
+
parsed
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
plugin = {
|
2
|
+
:name => :macro,
|
3
|
+
:order => 2,
|
4
|
+
:regexp => /^(?<name>[\S]+):(?<target>[\S]+)\[(?<attrlist>[\S\s]+)\]$/,
|
5
|
+
:handler => lambda { |lines, element|
|
6
|
+
macro = AsciiDoc::AsciiElement.new(lines.current_line.gsub(plugin[:regexp], '\k<name>').to_sym)
|
7
|
+
macro.children << lines.current_line.gsub(plugin[:regexp], '\k<target>')
|
8
|
+
macro.attributes = AsciiDoc::MacroHelper.parse_attributes(lines.current_line.gsub(plugin[:regexp], '\k<attrlist>'), "alt")
|
9
|
+
element.children << macro
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
AsciiDoc::AsciiPlugins::register(plugin)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Rune Madsen
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-14 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|
@@ -56,11 +56,12 @@ files:
|
|
56
56
|
- lib/asciidoc/asciielement.rb
|
57
57
|
- lib/asciidoc/asciilines.rb
|
58
58
|
- lib/asciidoc/asciiplugins.rb
|
59
|
+
- lib/asciidoc/macrohelper.rb
|
59
60
|
- lib/asciidoc/plugins/chars/bold.rb
|
60
61
|
- lib/asciidoc/plugins/chars/italic.rb
|
61
62
|
- lib/asciidoc/plugins/lines/bulleted_list.rb
|
62
63
|
- lib/asciidoc/plugins/lines/heading.rb
|
63
|
-
- lib/asciidoc/plugins/lines/
|
64
|
+
- lib/asciidoc/plugins/lines/macro.rb
|
64
65
|
- lib/asciidoc/plugins/lines/ordered_list.rb
|
65
66
|
- lib/asciidoc/plugins/lines/paragraph.rb
|
66
67
|
- lib/asciidoc/plugins/lines/quote.rb
|
@@ -1,13 +0,0 @@
|
|
1
|
-
plugin = {
|
2
|
-
:name => :image,
|
3
|
-
:order => 2,
|
4
|
-
:regexp => /^image:{1}(?<path>[\S]+)\[(?<alt>[\S\s]+)\]$/,
|
5
|
-
:handler => lambda { |lines, element|
|
6
|
-
image = AsciiDoc::AsciiElement.new(plugin[:name])
|
7
|
-
image.children << lines.current_line.gsub(plugin[:regexp], '\k<path>')
|
8
|
-
image.children << lines.current_line.gsub(plugin[:regexp], '\k<alt>')
|
9
|
-
element.children << image
|
10
|
-
}
|
11
|
-
}
|
12
|
-
|
13
|
-
AsciiDoc::AsciiPlugins::register(plugin)
|