Class: Booky::Textile::Source
- Inherits:
-
Object
- Object
- Booky::Textile::Source
- Includes:
- Precompiler
- Defined in:
- lib/booky/textile/source.rb
Constant Summary collapse
- EXTENSIONS =
{ '.txt' => 'text', '.rb' => 'ruby', '.java' => 'java', '.html' => 'html', '.htm' => 'html', '.js' => 'javascript', '.coffee' => 'javascript', '.css' => 'css', '.c' => 'c', '.cpp' => 'cpp', '.pl' => 'perl', '.py' => 'python', '.php' => 'php', '.sql' => 'sql' }
Instance Method Summary collapse
-
#compile_to(options) ⇒ Object
Replace the path with the contents of the file.
-
#language(file) ⇒ Object
Returns the language from the file extension.
-
#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
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/booky/textile/source.rb', line 29 def compile_to begin = parse() if @lang = language("#{File.dirname(Booky.source)}/#{[:file]}") @output = "bc{name: #{[:name]};language: #{@lang}}.. " else @output = "bc{name: #{[:name]};}.. " end @output += File.open("#{File.dirname(Booky.source)}/#{[:file]}", 'rb:UTF-8') { |f| f.read } @output += "\n\np. \n" @output rescue raise "Couldn't find source file: #{File.dirname(Booky.source)}/#{[:name]}".red end end |
#language(file) ⇒ Object
Returns the language from the file extension
59 60 61 |
# File 'lib/booky/textile/source.rb', line 59 def language file EXTENSIONS[File.extname(file)] rescue nil end |
#matches(line) ⇒ Object
Does the current line need to be precompiled?
23 24 25 26 |
# File 'lib/booky/textile/source.rb', line 23 def matches line return false unless line.match /^source/ line.gsub(/^source/, "").strip end |
#parse(options) ⇒ Object
Parses the options for a name and the file
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/booky/textile/source.rb', line 46 def parse if name_match = .match(/{(.*?)}/) = .gsub(name_match[0], "") name = name_match[1] end file = [1..-1].strip #name = File.basename("#{File.dirname(Booky.source)}/#{file}") unless name { :name => name, :file => file } end |