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.
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "asciidoc"
6
- s.version = "0.0.1"
6
+ s.version = "0.0.2"
7
7
  s.authors = ["Rune Madsen"]
8
8
  s.email = ["rune@runemadsen.com"]
9
9
  s.homepage = ""
@@ -1,3 +1,5 @@
1
+ require 'asciidoc/macrohelper'
2
+
1
3
  require 'asciidoc/asciiplugins'
2
4
  require 'asciidoc/asciicharplugins'
3
5
 
@@ -6,7 +6,6 @@ module AsciiDoc
6
6
 
7
7
  def self.register(plugin)
8
8
  CharPlugins << plugin
9
- puts "register char plugin baby: #{CharPlugins.size}"
10
9
  end
11
10
 
12
11
  def order_plugins
@@ -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
- def render(template, format)
24
+ private
25
+
26
+ # Specific Render Functions
27
+ # ----------------------------------------------------------------
28
+
29
+ def render_html(template_folder, output_folder)
14
30
  views = {}
15
- Dir["./templates/#{template}/#{format}/*.html.erb"].each { |file|
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
- result
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
@@ -26,6 +26,17 @@ module AsciiDoc
26
26
  end
27
27
  content
28
28
  end
29
+
30
+ # AsciiDoc Attributes
31
+ # ---------------------------------------------------
32
+
33
+ def attributes
34
+ @attributes
35
+ end
36
+
37
+ def attributes=(att)
38
+ @attributes = att
39
+ end
29
40
 
30
41
  end
31
42
 
@@ -5,7 +5,6 @@ module AsciiDoc
5
5
  Plugins = []
6
6
 
7
7
  def self.register(plugin)
8
- puts "register plugin baby: #{Plugins.size}"
9
8
  Plugins << plugin
10
9
  end
11
10
 
@@ -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
@@ -1,5 +1,3 @@
1
- puts "Bold is required"
2
-
3
1
  plugin = {
4
2
  :name => :bold,
5
3
  :regexp => /\*/,
@@ -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: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
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-04 00:00:00 Z
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/image.rb
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)