Permalink
Browse files

moved asciidoc to gem

  • Loading branch information...
1 parent 9357448 commit 2f6b17e3aa0db07a1943ac501390d096989035d4 @runemadsen committed Nov 4, 2011
View
@@ -1,3 +1,4 @@
source :rubygems
-gem 'sinatra'
+gem 'sinatra'
+gem 'asciidoc', :path => '/Users/rune/Projects/gems/asciidoc'
View
@@ -1,3 +1,8 @@
+PATH
+ remote: /Users/rune/Projects/gems/asciidoc
+ specs:
+ asciidoc (0.0.1)
+
GEM
remote: http://rubygems.org/
specs:
@@ -11,4 +16,5 @@ PLATFORMS
ruby
DEPENDENCIES
+ asciidoc!
sinatra
View
@@ -1,8 +1,6 @@
require 'rubygems'
require 'bundler'
Bundler.require
-require './parser/asciidoc.rb'
-require 'yaml'
class Application < Sinatra::Base
@@ -11,7 +9,7 @@ class Application < Sinatra::Base
end
get '/parse' do
- @document = AsciiDoc.new(open("public/test.asciidoc").read)
+ @document = AsciiDoc::AsciiDocument.new(open("public/test.asciidoc").read)
erb :parse
end
View
@@ -1,34 +0,0 @@
-class AsciiDoc
-
- attr_accessor :html, :config
-
- # TODO: Parse all content in AsciiDoc
- # TODO: Make tags templatable
-
- # pass templates in a templates hash
- def initialize(content)
- @config = YAML::load(open("config.yml").read)
- @html = content
- parse_titles
- # header
- # header attributes
- # table of contents
- # underlined headings
- # paragraphs
- # blocks
- # text
- # macros
- # lists
- # tables
- end
-
- private
-
- def parse_titles
- @config["titles"].each do |k,v|
- #@html.gsub!(v, template(k))
- @html.gsub!(v, '<h1>\k<title></h1>')
- end
- end
-
-end
View
@@ -1,7 +0,0 @@
-titles:
- level0: !ruby/regexp '/^= +(?<title>[\S].*?)( +=)?$/'
- level1: !ruby/regexp '/^== +(?<title>[\S].*?)( +==)?$/'
- level2: !ruby/regexp '/^=== +(?<title>[\S].*?)( +===)?$/'
- level3: !ruby/regexp '/^==== +(?<title>[\S].*?)( +====)?$/'
- level4: !ruby/regexp '/^===== +(?<title>[\S].*?)( +=====)?$/'
- blocktitle: !ruby/regexp '/^\.(?<title>([^.\s].*)|(\.[^.\s].*))$/'
View
@@ -1,19 +0,0 @@
-class Parse
-
- attr_accessor :parsed_content, :config
-
- def initialize(content)
- @config = YAML::load(open("config.yml").read)
- @parsed_content = content
- parse_titles
- end
-
- private
-
- def parse_titles
- @config["titles"].each do |k,v|
- @parsed_content.gsub!(v, '<h1>\k<title></h1>')
- end
- end
-
-end
View
@@ -1,45 +0,0 @@
-require './parser/asciicharplugins.rb'
-
-class AsciiBlock
-
- include AsciiCharPlugins
-
- attr_accessor :element
-
- def initialize(element)
- @element = element
- @chars = AsciiChars.new(@element.children[0]) # only works when passing an element with a single child (the whole paragraph)
- @element.children[0] = ""
- parse_chars
- end
-
- private
-
- def parse_chars
- order_plugins
- detect_plugins
- while @chars.shift_char do
- detect_plugins
- end
- end
-
- def detect_plugins
- found = false
- CharPlugins.each do |p|
- if p[:regexp] =~ @chars.current_char
- if p[:handler].call(@chars, @element)
- found = true
- break
- end
- end
- end
-
- unless found
- if(not @element.children[@element.children.size].is_a?(String))
- @element.children << ""
- end
- @element.children[@element.children.size - 1] << @chars.current_char
- end
- end
-
-end
@@ -1,17 +0,0 @@
-module AsciiCharPlugins
-
- CharPlugins = []
-
- def self.register(plugin)
- CharPlugins << plugin
- end
-
- def order_plugins
- CharPlugins.sort! do |x,y|
- x_val = x.has_key?(:order) ? x[:order] : 99999999999
- y_val = y.has_key?(:order) ? y[:order] : 99999999999
- x_val <=> y_val
- end
- end
-
-end
View
@@ -1,27 +0,0 @@
-class AsciiChars
-
- attr_accessor :current_index, :chars
-
- def initialize(content)
- @current_index = 0
- @chars = content
- end
-
- def shift_char
- @current_index += 1
- current_char
- end
-
- def prev_char(num = 1)
- @chars[@current_index - 1, num]
- end
-
- def next_char(num = 1)
- @chars[@current_index + 1, num]
- end
-
- def current_char
- @chars[@current_index, 1]
- end
-
-end
View
@@ -1,57 +0,0 @@
-require './parser/asciielement.rb'
-require './parser/asciilines.rb'
-require './parser/asciiblock.rb'
-require './parser/asciichars.rb'
-require './parser/asciiplugins.rb'
-Dir["./parser/custom/*.rb"].each {|file| require file }
-Dir["./parser/standard/*.rb"].each {|file| require file }
-Dir["./parser/char/*.rb"].each {|file| require file }
-
-class AsciiDoc
-
- include AsciiPlugins
-
- def initialize(content)
- @element = AsciiElement.new(:document)
- @lines = AsciiLines.new(content)
- parse_lines
- end
-
- def render(template, format)
- views = {}
- Dir["./templates/#{template}/#{format}/*.html.erb"].each { |file|
- symbol = file.split("/").last.split(".").first.to_sym
- views[symbol] = ERB.new(open(file).read)
- }
- result = @element.render(views)
- result
- end
-
- private
-
- def parse_lines
- order_plugins
- detect_plugins
- while @lines.shift_line do
- unless @lines.current_line =~ /^\s*$/
- detect_plugins
- end
- end
- end
-
- def detect_plugins()
- found = false
- Plugins.each do |p|
- if p[:regexp] =~ @lines.current_line
- if p[:handler].call(@lines, @element)
- found = true
- break
- end
- end
- end
- unless found
- @element.children << "NOT FOUND: " + @lines.current_line
- end
- end
-
-end
@@ -1,28 +0,0 @@
-class AsciiElement
-
- attr_accessor :children, :type
-
- def initialize(type)
- @type = type
- @children = []
- end
-
- def render(views)
- element = self
- raise Exception, "Template file doesn't exist: #{@type}" if views[@type].nil?
- views[@type].result(binding)
- end
-
- def standard_render(views)
- content = ""
- @children.each do |child|
- if(child.is_a? String)
- content += child
- else
- content += child.render(views)
- end
- end
- content
- end
-
-end
View
@@ -1,27 +0,0 @@
-class AsciiLines
-
- attr_accessor :current_index, :lines
-
- def initialize(content)
- @current_index = 0
- @lines = content.gsub("\r","").split("\n")
- end
-
- def shift_line
- @current_index += 1
- current_line
- end
-
- def prev_line
- @lines[@current_index - 1]
- end
-
- def next_line
- @lines[@current_index + 1]
- end
-
- def current_line
- @lines[@current_index]
- end
-
-end
@@ -1,17 +0,0 @@
-module AsciiPlugins
-
- Plugins = []
-
- def self.register(plugin)
- Plugins << plugin
- end
-
- def order_plugins
- Plugins.sort! do |x,y|
- x_val = x.has_key?(:order) ? x[:order] : 99999999999
- y_val = y.has_key?(:order) ? y[:order] : 99999999999
- x_val <=> y_val
- end
- end
-
-end
View
@@ -1,23 +0,0 @@
-plugin = {
- :name => :bold,
- :regexp => /\*/,
- :handler => lambda { |chars, element|
-
- if not chars.next_char =~ /\S/
- return false
- end
-
- body = ""
-
- while(chars.shift_char) do
- break if chars.current_char =~ /\*/
- body += chars.current_char
- end
-
- bold = AsciiElement.new(plugin[:name])
- bold.children << body
- element.children << AsciiBlock.new(bold).element
- }
-}
-
-AsciiCharPlugins::register(plugin)
View
@@ -1,23 +0,0 @@
-plugin = {
- :name => :italic,
- :regexp => /_/,
- :handler => lambda { |chars, element|
-
- if not chars.next_char =~ /\S/
- return false
- end
-
- body = ""
-
- while(chars.shift_char) do
- break if chars.current_char =~ /_/
- body += chars.current_char
- end
-
- italic = AsciiElement.new(plugin[:name])
- italic.children << body
- element.children << AsciiBlock.new(italic).element
- }
-}
-
-AsciiCharPlugins::register(plugin)
View
@@ -1,7 +0,0 @@
-titles:
- level0: !ruby/regexp '/^= +(?<title>[\S].*?)( +=)?$/'
- level1: !ruby/regexp '/^== +(?<title>[\S].*?)( +==)?$/'
- level2: !ruby/regexp '/^=== +(?<title>[\S].*?)( +===)?$/'
- level3: !ruby/regexp '/^==== +(?<title>[\S].*?)( +====)?$/'
- level4: !ruby/regexp '/^===== +(?<title>[\S].*?)( +=====)?$/'
- blocktitle: !ruby/regexp '/^\.(?<title>([^.\s].*)|(\.[^.\s].*))$/'
Oops, something went wrong.

0 comments on commit 2f6b17e

Please sign in to comment.