Class: Booky::Textile::Table
- Inherits:
-
Object
- Object
- Booky::Textile::Table
- Includes:
- Precompiler
- Defined in:
- lib/booky/textile/table.rb
Instance Method Summary collapse
-
#compile_to(options) ⇒ Object
Replace the path with the contents of the file.
-
#matches(line) ⇒ Object
Does the current line need to be precompiled?.
-
#parse(options) ⇒ Object
Parses the options for a name and the file.
Methods included from Precompiler
Instance Method Details
#compile_to(options) ⇒ Object
Replace the path with the contents of the file
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/booky/textile/table.rb', line 12 def compile_to begin = parse() @output = "table#{[:header]}.\n" @spreadsheet = Spreadsheet.open "#{File.dirname(Booky.source)}/#{[:file]}" header = true @spreadsheet.worksheet(0).each do |row| # header if header @output += "|" row.each{ |cell| @output += "_. #{cell} |" } @output += "\n" header = false next end # cells @output += "|" row.each{ |cell| @output += "#{cell} |" } @output += "\n" end @output rescue raise Booky::LoadError.new "#{File.dirname(Booky.source)}/#{[:name]}".red end end |
#matches(line) ⇒ Object
Does the current line need to be precompiled?
6 7 8 9 |
# File 'lib/booky/textile/table.rb', line 6 def matches line return false unless line.match /^table.*\w+$/ line.gsub(/^table/, "").strip end |
#parse(options) ⇒ Object
Parses the options for a name and the file
44 45 46 47 48 49 |
# File 'lib/booky/textile/table.rb', line 44 def parse file = .scan(/[\w|\.|\/]+$/).to_a.first header = .scan(/{.*}/).to_a.first { :header => header, :file => file } end |