Module: Broadway::Helpers::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) ⇒ Object
- #show_code ⇒ Object
- #space(times = 1) ⇒ Object
Instance Method Details
#c(path) ⇒ Object
config helper method
6 7 8 9 10 |
# File 'lib/broadway/sinatra/helpers/text_helper.rb', line 6 def c(path) result = site.config path.to_s.split(".").each { |node| result = result[node.to_sym] if result } result.nil? ? [] : result end |
#code(code, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/broadway/sinatra/helpers/text_helper.rb', line 25 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
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/broadway/sinatra/helpers/text_helper.rb', line 34 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
13 14 15 |
# File 'lib/broadway/sinatra/helpers/text_helper.rb', line 13 def read(post, attribute = nil) post.read(attribute) end |
#read_excerpt(post, max_length = nil) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/broadway/sinatra/helpers/text_helper.rb', line 17 def read_excerpt(post, max_length = nil) result = read(post, "excerpt") result = read(post) if result.nil? || result.empty? max_length ||= result.length result[0..max_length] + "..." result end |
#show_code ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/broadway/sinatra/helpers/text_helper.rb', line 49 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
45 46 47 |
# File 'lib/broadway/sinatra/helpers/text_helper.rb', line 45 def space(times = 1) haml_concat("\n" * times) end |