tiny_site 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tiny_site/version.rb +1 -1
- data/lib/tiny_site.rb +11 -8
- metadata +1 -1
data/lib/tiny_site/version.rb
CHANGED
data/lib/tiny_site.rb
CHANGED
@@ -5,13 +5,16 @@ require 'haml'
|
|
5
5
|
|
6
6
|
class TextileParts
|
7
7
|
def self.parse(tp, image_path='')
|
8
|
-
|
8
|
+
return [{:title => '404 not found'},{}] unless tp
|
9
|
+
|
10
|
+
vars, *parts = tp.split(/^\+{4}|\+{4}$/)
|
9
11
|
|
10
12
|
vars = YAML.load(vars) || {}
|
13
|
+
|
11
14
|
parts = Hash[*parts]
|
12
15
|
parts.each{|k,v| parts[k] = textilize(v,image_path)}
|
13
16
|
|
14
|
-
|
17
|
+
vars.update(parts)
|
15
18
|
end
|
16
19
|
def self.textilize(string, image_path)
|
17
20
|
string.gsub!(%r{!([\w\d\-\._]+)!}){ |a| "!#{image_path}/#{$1}!" }
|
@@ -68,12 +71,13 @@ end
|
|
68
71
|
class TinySite
|
69
72
|
def initialize(opts)
|
70
73
|
@file_path = opts[:file_path]
|
74
|
+
@file_ending = opts[:file_ending] || 'textile'
|
71
75
|
@image_path = opts[:image_path] || File.join(@file_path, 'images')
|
72
76
|
@cache_buster = opts[:cache_buster] || 'bust'
|
73
77
|
end
|
74
78
|
|
75
79
|
def remote_file_url_for(filename)
|
76
|
-
File.join @file_path, "#{filename}
|
80
|
+
File.join @file_path, "#{filename}.#{@file_ending}"
|
77
81
|
end
|
78
82
|
|
79
83
|
def render
|
@@ -83,15 +87,14 @@ class TinySite
|
|
83
87
|
_, page_file = CachedHttpFile.get remote_file_url_for(@status) if @status != 200
|
84
88
|
global_file_fetch_tread.join
|
85
89
|
|
86
|
-
|
87
|
-
|
90
|
+
global = TextileParts.parse @global_file, @image_path
|
91
|
+
page = TextileParts.parse page_file, @image_path
|
88
92
|
|
89
|
-
render_layout :
|
90
|
-
:page_vars => page_vars, :page_parts => page_parts
|
93
|
+
render_layout :global => global, :page => page
|
91
94
|
end
|
92
95
|
|
93
96
|
def render_layout(params)
|
94
|
-
layout = params[:
|
97
|
+
layout = params[:page][:layout] || params[:global][:layout] || 'layout'
|
95
98
|
|
96
99
|
puts "rendering layout '#{layout}'"
|
97
100
|
haml = Haml::Engine.new File.open("#{layout}.haml").read, :format => :html5
|