Module: Broadway::Sinatra::TextHelper

Defined in:
lib/broadway/sinatra/helpers/text_helper.rb

Instance Method Summary collapse

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, options = {})
  options[:lang] = extension_to_lang(options[:extension]) if options.has_key?(:extension)
  puts options.inspect
  options[:lang] ||= "plain_text" unless Uv.syntaxes.include?(options[:lang])
  options[:line_numbers] = false unless options.has_key?(:line_numbers)
  options[:theme] ||= "twilight"
  Uv.parse(code, "xhtml", options[:lang], options[:line_numbers], options[: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_codeObject



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.expand_path("public")
  file = params[:file]
  begin
  	path = File.expand_path(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