Class: TextileParts

Inherits:
Object
  • Object
show all
Defined in:
lib/tiny_site.rb

Class Method Summary collapse

Class Method Details

.image_url_for(img_name) ⇒ Object



21
22
23
# File 'lib/tiny_site.rb', line 21

def self.image_url_for(img_name)
  @app.image_url_for img_name
end

.parse(tp, app) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/tiny_site.rb', line 8

def self.parse(tp, app)
  @app = app
  
  return {:title => '404 not found'} unless tp
  
  vars, *parts = tp.split(/^\+{4}([\w\d\-_]+)\+{4}$/)
  vars = YAML.load(vars) || {}
  
  parts = Hash[*parts]
  parts.each{|k,v| parts[k] = textilize(v)}
  
  vars.update(parts)
end

.textilize(string) ⇒ Object



24
25
26
27
28
# File 'lib/tiny_site.rb', line 24

def self.textilize(string)
  string.gsub!(%r{!([\w\d\-\._]+)!}){ |a| "!#{image_url_for $1}!" }
  
  RedCloth.new(string).to_html
end