Module: Broadway::Sinatra::TextHelper
- Defined in:
- lib/broadway/sinatra/helpers/text_helper.rb
Instance Method Summary collapse
-
#c(path) ⇒ Object
config helper method.
- #code(code, options = {}) ⇒ Object
- #extension_to_lang(ext) ⇒ Object
-
#read(post, attribute = nil) ⇒ Object
read the post and parse it with Liquid.
- #read_excerpt(post, max_length = nil, format = nil, strip = true) ⇒ Object
- #show_code ⇒ Object
- #space(times = 1) ⇒ Object
Instance Method Details
#c(path) ⇒ Object
config helper method
6 7 8 |
# File 'lib/broadway/sinatra/helpers/text_helper.rb', line 6 def c(path) site.configuration.get(path) end |
#code(code, options = {}) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/broadway/sinatra/helpers/text_helper.rb', line 19 def code(code, = {}) [:lang] = extension_to_lang([:extension]) if .has_key?(:extension) puts .inspect [:lang] ||= "plain_text" unless Uv.syntaxes.include?([:lang]) [:line_numbers] = false unless .has_key?(:line_numbers) [:theme] ||= "twilight" Uv.parse(code, "xhtml", [:lang], [:line_numbers], [:theme]) end |
#extension_to_lang(ext) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/broadway/sinatra/helpers/text_helper.rb', line 28 def extension_to_lang(ext) { "js" => "javascript", "rb" => "ruby", "as" => "actionscript", "mxml" => "mxml", "xml" => "xml", "css" => "css" }[ext.gsub(/\./, "")] end |
#read(post, attribute = nil) ⇒ Object
read the post and parse it with Liquid
11 12 13 |
# File 'lib/broadway/sinatra/helpers/text_helper.rb', line 11 def read(post, attribute = nil) post.read(attribute) end |
#read_excerpt(post, max_length = nil, format = nil, strip = true) ⇒ Object
15 16 17 |
# File 'lib/broadway/sinatra/helpers/text_helper.rb', line 15 def read_excerpt(post, max_length = nil, format = nil, strip = true) post.read_excerpt(max_length, format, strip) end |
#show_code ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/broadway/sinatra/helpers/text_helper.rb', line 43 def show_code root = File.("public") file = params[:file] begin path = File.(File.join(root, file)).untaint if (File.dirname(path).split("/").length >= root.split("/").length) data = IO.read(path)#.gsub(/[']/, '\\\\\'') code(data, :extension => File.extname(path)) else #only happens when someone tries to go outside your root directory... "You are way out of your league" end rescue "Internal Error" end end |
#space(times = 1) ⇒ Object
39 40 41 |
# File 'lib/broadway/sinatra/helpers/text_helper.rb', line 39 def space(times = 1) haml_concat("\n" * times) end |