Module: Broadway::Helpers::TextHelper
- Defined in:
- lib/broadway/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/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
36 37 38 39 40 41 42 43 |
# File 'lib/broadway/helpers/text_helper.rb', line 36 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
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/broadway/helpers/text_helper.rb', line 45 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 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/broadway/helpers/text_helper.rb', line 13 def read(post, attribute = nil) post.content = IO.read(post.path) if post.content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m if attribute output = YAML.load($1)[attribute] || "" return output end post.content = post.content[($1.size + $2.size)..-1] end post.render(site.layouts, site.site_payload) output = post.output post.content = post.output = nil output end |
#read_excerpt(post, max_length = nil) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/broadway/helpers/text_helper.rb', line 28 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
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/broadway/helpers/text_helper.rb', line 60 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
56 57 58 |
# File 'lib/broadway/helpers/text_helper.rb', line 56 def space(times = 1) haml_concat("\n" * times) end |