asciidoc 0.0.1

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/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in github-oauth.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,12 @@
1
+ Installation
2
+ ------------
3
+
4
+ NB: This is a super early version of this gem. Use only for testing purposes
5
+
6
+ To install the gem, simply run:
7
+
8
+ gem install 'asciidoc'
9
+
10
+ Or the bundler equivalent:
11
+
12
+ bundle install 'asciidoc'
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/asciidoc.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "asciidoc"
6
+ s.version = "0.0.1"
7
+ s.authors = ["Rune Madsen"]
8
+ s.email = ["rune@runemadsen.com"]
9
+ s.homepage = ""
10
+ s.summary = %q{A gem to parse AsciiDoc documents into Ruby models and convert to HTML / PDF }
11
+ s.description = %q{A gem to parse AsciiDoc documents into Ruby models and convert to HTML / PDF}
12
+
13
+ s.rubyforge_project = "asciidoc"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_development_dependency "rspec", "~> 2.6"
21
+ end
data/lib/asciidoc.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'asciidoc/asciiplugins'
2
+ require 'asciidoc/asciicharplugins'
3
+
4
+ require 'asciidoc/asciielement'
5
+ require 'asciidoc/asciilines'
6
+ require 'asciidoc/asciiblock'
7
+ require 'asciidoc/asciichars'
8
+
9
+ Dir[File.dirname(__FILE__) + '/asciidoc/plugins/lines/*.rb'].each {|file| require file }
10
+ Dir[File.dirname(__FILE__) + '/asciidoc/plugins/chars/*.rb'].each {|file| require file }
11
+
12
+ require 'asciidoc/asciidocument'
@@ -0,0 +1,48 @@
1
+ module AsciiDoc
2
+
3
+ class AsciiBlock
4
+
5
+ include AsciiDoc::AsciiCharPlugins
6
+
7
+ attr_accessor :element
8
+
9
+ def initialize(element)
10
+ @element = element
11
+ @chars = AsciiDoc::AsciiChars.new(@element.children[0]) # only works when passing an element with a single child (the whole paragraph)
12
+ @element.children[0] = ""
13
+ parse_chars
14
+ end
15
+
16
+ private
17
+
18
+ def parse_chars
19
+ order_plugins
20
+ detect_plugins
21
+ while @chars.shift_char do
22
+ detect_plugins
23
+ end
24
+ end
25
+
26
+ def detect_plugins
27
+ found = false
28
+ CharPlugins.each do |p|
29
+ if p[:regexp] =~ @chars.current_char
30
+ if p[:handler].call(@chars, @element)
31
+ found = true
32
+ break
33
+ end
34
+ end
35
+ end
36
+
37
+ unless found
38
+ if(not @element.children[@element.children.size].is_a?(String))
39
+ @element.children << ""
40
+ end
41
+ @element.children[@element.children.size - 1] << @chars.current_char
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+
48
+ end
@@ -0,0 +1,22 @@
1
+ module AsciiDoc
2
+
3
+ module AsciiCharPlugins
4
+
5
+ CharPlugins = []
6
+
7
+ def self.register(plugin)
8
+ CharPlugins << plugin
9
+ puts "register char plugin baby: #{CharPlugins.size}"
10
+ end
11
+
12
+ def order_plugins
13
+ CharPlugins.sort! do |x,y|
14
+ x_val = x.has_key?(:order) ? x[:order] : 99999999999
15
+ y_val = y.has_key?(:order) ? y[:order] : 99999999999
16
+ x_val <=> y_val
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,31 @@
1
+ module AsciiDoc
2
+
3
+ class AsciiChars
4
+
5
+ attr_accessor :current_index, :chars
6
+
7
+ def initialize(content)
8
+ @current_index = 0
9
+ @chars = content
10
+ end
11
+
12
+ def shift_char
13
+ @current_index += 1
14
+ current_char
15
+ end
16
+
17
+ def prev_char(num = 1)
18
+ @chars[@current_index - 1, num]
19
+ end
20
+
21
+ def next_char(num = 1)
22
+ @chars[@current_index + 1, num]
23
+ end
24
+
25
+ def current_char
26
+ @chars[@current_index, 1]
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,52 @@
1
+ module AsciiDoc
2
+
3
+ class AsciiDocument
4
+
5
+ include AsciiDoc::AsciiPlugins
6
+
7
+ def initialize(content)
8
+ @element = AsciiDoc::AsciiElement.new(:document)
9
+ @lines = AsciiDoc::AsciiLines.new(content)
10
+ parse_lines
11
+ end
12
+
13
+ def render(template, format)
14
+ views = {}
15
+ Dir["./templates/#{template}/#{format}/*.html.erb"].each { |file|
16
+ symbol = file.split("/").last.split(".").first.to_sym
17
+ views[symbol] = ERB.new(open(file).read)
18
+ }
19
+ result = @element.render(views)
20
+ result
21
+ end
22
+
23
+ private
24
+
25
+ def parse_lines
26
+ order_plugins
27
+ detect_plugins
28
+ while @lines.shift_line do
29
+ unless @lines.current_line =~ /^\s*$/
30
+ detect_plugins
31
+ end
32
+ end
33
+ end
34
+
35
+ def detect_plugins()
36
+ found = false
37
+ Plugins.each do |p|
38
+ if p[:regexp] =~ @lines.current_line
39
+ if p[:handler].call(@lines, @element)
40
+ found = true
41
+ break
42
+ end
43
+ end
44
+ end
45
+ unless found
46
+ @element.children << "NOT FOUND: " + @lines.current_line
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,32 @@
1
+ module AsciiDoc
2
+
3
+ class AsciiElement
4
+
5
+ attr_accessor :children, :type
6
+
7
+ def initialize(type)
8
+ @type = type
9
+ @children = []
10
+ end
11
+
12
+ def render(views)
13
+ element = self
14
+ raise Exception, "Template file doesn't exist: #{@type}" if views[@type].nil?
15
+ views[@type].result(binding)
16
+ end
17
+
18
+ def standard_render(views)
19
+ content = ""
20
+ @children.each do |child|
21
+ if(child.is_a? String)
22
+ content += child
23
+ else
24
+ content += child.render(views)
25
+ end
26
+ end
27
+ content
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,31 @@
1
+ module AsciiDoc
2
+
3
+ class AsciiLines
4
+
5
+ attr_accessor :current_index, :lines
6
+
7
+ def initialize(content)
8
+ @current_index = 0
9
+ @lines = content.gsub("\r","").split("\n")
10
+ end
11
+
12
+ def shift_line
13
+ @current_index += 1
14
+ current_line
15
+ end
16
+
17
+ def prev_line
18
+ @lines[@current_index - 1]
19
+ end
20
+
21
+ def next_line
22
+ @lines[@current_index + 1]
23
+ end
24
+
25
+ def current_line
26
+ @lines[@current_index]
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,22 @@
1
+ module AsciiDoc
2
+
3
+ module AsciiPlugins
4
+
5
+ Plugins = []
6
+
7
+ def self.register(plugin)
8
+ puts "register plugin baby: #{Plugins.size}"
9
+ Plugins << plugin
10
+ end
11
+
12
+ def order_plugins
13
+ Plugins.sort! do |x,y|
14
+ x_val = x.has_key?(:order) ? x[:order] : 99999999999
15
+ y_val = y.has_key?(:order) ? y[:order] : 99999999999
16
+ x_val <=> y_val
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,25 @@
1
+ puts "Bold is required"
2
+
3
+ plugin = {
4
+ :name => :bold,
5
+ :regexp => /\*/,
6
+ :handler => lambda { |chars, element|
7
+
8
+ if not chars.next_char =~ /\S/
9
+ return false
10
+ end
11
+
12
+ body = ""
13
+
14
+ while(chars.shift_char) do
15
+ break if chars.current_char =~ /\*/
16
+ body += chars.current_char
17
+ end
18
+
19
+ bold = AsciiDoc::AsciiElement.new(plugin[:name])
20
+ bold.children << body
21
+ element.children << AsciiDoc::AsciiBlock.new(bold).element
22
+ }
23
+ }
24
+
25
+ AsciiDoc::AsciiCharPlugins::register(plugin)
@@ -0,0 +1,23 @@
1
+ plugin = {
2
+ :name => :italic,
3
+ :regexp => /_/,
4
+ :handler => lambda { |chars, element|
5
+
6
+ if not chars.next_char =~ /\S/
7
+ return false
8
+ end
9
+
10
+ body = ""
11
+
12
+ while(chars.shift_char) do
13
+ break if chars.current_char =~ /_/
14
+ body += chars.current_char
15
+ end
16
+
17
+ italic = AsciiDoc::AsciiElement.new(plugin[:name])
18
+ italic.children << body
19
+ element.children << AsciiDoc::AsciiBlock.new(italic).element
20
+ }
21
+ }
22
+
23
+ AsciiDoc::AsciiCharPlugins::register(plugin)
@@ -0,0 +1,24 @@
1
+ plugin = {
2
+ :name => :bulleted_list,
3
+ :regexp => /^-\s{1}/,
4
+ :handler => lambda { |lines, element|
5
+
6
+ lis = []
7
+ e = AsciiDoc::AsciiElement.new(:li)
8
+ e.children << lines.current_line.gsub(/^-\s{1}/, "")
9
+ lis << AsciiDoc::AsciiBlock.new(e).element
10
+
11
+ while(lines.shift_line) do
12
+ break if not lines.current_line =~ /^-\s{1}/
13
+ e = AsciiDoc::AsciiElement.new(:li)
14
+ e.children << lines.current_line.gsub(/^-\s{1}/, "")
15
+ lis << AsciiDoc::AsciiBlock.new(e).element
16
+ end
17
+
18
+ bulleted_list = AsciiDoc::AsciiElement.new(plugin[:name])
19
+ bulleted_list.children = lis
20
+ element.children << bulleted_list
21
+ }
22
+ }
23
+
24
+ AsciiDoc::AsciiPlugins::register(plugin)
@@ -0,0 +1,21 @@
1
+ plugin = {
2
+ :order => 1,
3
+ :name => :heading,
4
+ :regexp => /^\w+/,
5
+ :handler => lambda { |lines, element|
6
+
7
+ # TODO: Regex should use lines size to determine how many === are needed
8
+ unless lines.next_line =~ /^={3,}$/
9
+ return false
10
+ end
11
+
12
+ heading = AsciiDoc::AsciiElement.new(plugin[:name])
13
+ heading.children << lines.current_line
14
+ element.children << heading
15
+
16
+ lines.shift_line
17
+ lines.shift_line
18
+ }
19
+ }
20
+
21
+ AsciiDoc::AsciiPlugins::register(plugin)
@@ -0,0 +1,13 @@
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)
@@ -0,0 +1,24 @@
1
+ plugin = {
2
+ :name => :ordered_list,
3
+ :regexp => /^.\s{1}/,
4
+ :handler => lambda { |lines, element|
5
+
6
+ lis = []
7
+ e = AsciiDoc::AsciiElement.new(:li)
8
+ e.children << lines.current_line.gsub(/^.\s{1}/, "")
9
+ lis << AsciiDoc::AsciiBlock.new(e).element
10
+
11
+ while(lines.shift_line) do
12
+ break if not lines.current_line =~ /^.\s{1}/
13
+ e = AsciiDoc::AsciiElement.new(:li)
14
+ e.children << lines.current_line.gsub(/^.\s{1}/, "")
15
+ lis << AsciiDoc::AsciiBlock.new(e).element
16
+ end
17
+
18
+ ordered_list = AsciiDoc::AsciiElement.new(plugin[:name])
19
+ ordered_list.children = lis
20
+ element.children << ordered_list
21
+ }
22
+ }
23
+
24
+ AsciiDoc::AsciiPlugins::register(plugin)
@@ -0,0 +1,19 @@
1
+ plugin = {
2
+ :name => :paragraph,
3
+ :regexp => /^\w+/,
4
+ :handler => lambda { |lines, element|
5
+
6
+ body = lines.current_line
7
+
8
+ while(lines.shift_line) do
9
+ break if lines.current_line =~ /^\s*$/
10
+ body += lines.current_line
11
+ end
12
+
13
+ paragraph = AsciiDoc::AsciiElement.new(plugin[:name])
14
+ paragraph.children << body
15
+ element.children << AsciiDoc::AsciiBlock.new(paragraph).element
16
+ }
17
+ }
18
+
19
+ AsciiDoc::AsciiPlugins::register(plugin)
@@ -0,0 +1,20 @@
1
+ plugin = {
2
+ :name => :quote,
3
+ :regexp => /^\[quote\]$/,
4
+ :handler => lambda { |lines, element|
5
+
6
+ body = ""
7
+
8
+ while(lines.shift_line) do
9
+ break if lines.current_line =~ /^\s*$/
10
+ body += lines.current_line
11
+ end
12
+
13
+ quote = AsciiDoc::AsciiElement.new(plugin[:name])
14
+ quote.children << body
15
+ element.children << quote
16
+
17
+ }
18
+ }
19
+
20
+ AsciiDoc::AsciiPlugins::register(plugin)
@@ -0,0 +1,28 @@
1
+ plugin = {
2
+ :name => :source,
3
+ :regexp => /^\[source,[a-z]+\]$/,
4
+ :handler => lambda { |lines, element|
5
+
6
+ lines.shift_line
7
+
8
+ unless lines.current_line =~ /^-{3,}$/
9
+ return false
10
+ end
11
+
12
+ body = ""
13
+
14
+ while(lines.shift_line) do
15
+ break if lines.current_line =~ /^-{3,}$/
16
+ body += lines.current_line
17
+ body += "\n"
18
+ end
19
+
20
+ source = AsciiDoc::AsciiElement.new(plugin[:name])
21
+ source.children << "Java"
22
+ source.children << body
23
+
24
+ element.children << source
25
+ }
26
+ }
27
+
28
+ AsciiDoc::AsciiPlugins::register(plugin)
@@ -0,0 +1,11 @@
1
+ plugin = {
2
+ :name => :title1,
3
+ :regexp => /^===== +(?<title0>[\S].*?)( +=====)?$/,
4
+ :handler => lambda { |lines, element|
5
+ title = AsciiDoc::AsciiElement.new(plugin[:name])
6
+ title.children << lines.current_line.gsub!(plugin[:regexp], '\k<title0>')
7
+ element.children << title
8
+ }
9
+ }
10
+
11
+ AsciiDoc::AsciiPlugins::register(plugin)
@@ -0,0 +1,11 @@
1
+ plugin = {
2
+ :name => :title1,
3
+ :regexp => /^== +(?<title1>[\S].*?)( +==)?$/,
4
+ :handler => lambda { |lines, element|
5
+ title = AsciiDoc::AsciiElement.new(plugin[:name])
6
+ title.children << lines.current_line.gsub!(plugin[:regexp], '\k<title1>')
7
+ element.children << title
8
+ }
9
+ }
10
+
11
+ AsciiDoc::AsciiPlugins::register(plugin)
@@ -0,0 +1,11 @@
1
+ plugin = {
2
+ :name => :title2,
3
+ :regexp => /^=== +(?<title2>[\S].*?)( +===)?$/,
4
+ :handler => lambda { |lines, element|
5
+ title = AsciiDoc::AsciiElement.new(plugin[:name])
6
+ title.children << lines.current_line.gsub!(plugin[:regexp], '\k<title2>')
7
+ element.children << title
8
+ }
9
+ }
10
+
11
+ AsciiDoc::AsciiPlugins::register(plugin)
@@ -0,0 +1,11 @@
1
+ plugin = {
2
+ :name => :title3,
3
+ :regexp => /^==== +(?<title3>[\S].*?)( +====)?$/,
4
+ :handler => lambda { |lines, element|
5
+ title = AsciiDoc::AsciiElement.new(plugin[:name])
6
+ title.children << lines.current_line.gsub!(plugin[:regexp], '\k<title3>')
7
+ element.children << title
8
+ }
9
+ }
10
+
11
+ AsciiDoc::AsciiPlugins::register(plugin)
@@ -0,0 +1,11 @@
1
+ plugin = {
2
+ :name => :title4,
3
+ :regexp => /^===== +(?<title4>[\S].*?)( +=====)?$/,
4
+ :handler => lambda { |lines, element|
5
+ title = AsciiDoc::AsciiElement.new(plugin[:name])
6
+ title.children << lines.current_line.gsub!(plugin[:regexp], '\k<title4>')
7
+ element.children << title
8
+ }
9
+ }
10
+
11
+ AsciiDoc::AsciiPlugins::register(plugin)
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asciidoc
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Rune Madsen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-04 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 2
31
+ - 6
32
+ version: "2.6"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: A gem to parse AsciiDoc documents into Ruby models and convert to HTML / PDF
36
+ email:
37
+ - rune@runemadsen.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .DS_Store
46
+ - .gitignore
47
+ - Gemfile
48
+ - README.md
49
+ - Rakefile
50
+ - asciidoc.gemspec
51
+ - lib/asciidoc.rb
52
+ - lib/asciidoc/asciiblock.rb
53
+ - lib/asciidoc/asciicharplugins.rb
54
+ - lib/asciidoc/asciichars.rb
55
+ - lib/asciidoc/asciidocument.rb
56
+ - lib/asciidoc/asciielement.rb
57
+ - lib/asciidoc/asciilines.rb
58
+ - lib/asciidoc/asciiplugins.rb
59
+ - lib/asciidoc/plugins/chars/bold.rb
60
+ - lib/asciidoc/plugins/chars/italic.rb
61
+ - lib/asciidoc/plugins/lines/bulleted_list.rb
62
+ - lib/asciidoc/plugins/lines/heading.rb
63
+ - lib/asciidoc/plugins/lines/image.rb
64
+ - lib/asciidoc/plugins/lines/ordered_list.rb
65
+ - lib/asciidoc/plugins/lines/paragraph.rb
66
+ - lib/asciidoc/plugins/lines/quote.rb
67
+ - lib/asciidoc/plugins/lines/source.rb
68
+ - lib/asciidoc/plugins/lines/title0.rb
69
+ - lib/asciidoc/plugins/lines/title1.rb
70
+ - lib/asciidoc/plugins/lines/title2.rb
71
+ - lib/asciidoc/plugins/lines/title3.rb
72
+ - lib/asciidoc/plugins/lines/title4.rb
73
+ homepage: ""
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options: []
78
+
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ requirements: []
100
+
101
+ rubyforge_project: asciidoc
102
+ rubygems_version: 1.8.6
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: A gem to parse AsciiDoc documents into Ruby models and convert to HTML / PDF
106
+ test_files: []
107
+