tiny_site 0.1.6 → 0.1.7
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 +12 -12
- metadata +1 -1
data/lib/tiny_site/version.rb
CHANGED
data/lib/tiny_site.rb
CHANGED
@@ -4,20 +4,19 @@ require 'yaml'
|
|
4
4
|
require 'haml'
|
5
5
|
|
6
6
|
class TextileParts
|
7
|
-
def self.parse(tp, image_path='')
|
7
|
+
def self.parse(tp, image_path='', file_path_postfix='')
|
8
8
|
return {:title => '404 not found'} unless tp
|
9
9
|
|
10
10
|
vars, *parts = tp.split(/^\+{4}([\w\d\-_]+)\+{4}$/)
|
11
|
-
|
12
11
|
vars = YAML.load(vars) || {}
|
13
12
|
|
14
13
|
parts = Hash[*parts]
|
15
|
-
parts.each{|k,v| parts[k] = textilize(v,image_path)}
|
14
|
+
parts.each{|k,v| parts[k] = textilize(v,image_path,file_path_postfix)}
|
16
15
|
|
17
16
|
vars.update(parts)
|
18
17
|
end
|
19
|
-
def self.textilize(string, image_path)
|
20
|
-
string.gsub!(%r{!([\w\d\-\._]+)!}){ |a| "!#{image_path}/#{$1}!" }
|
18
|
+
def self.textilize(string, image_path, file_path_postfix='')
|
19
|
+
string.gsub!(%r{!([\w\d\-\._]+)!}){ |a| "!#{image_path}/#{$1}#{file_path_postfix}!" }
|
21
20
|
|
22
21
|
RedCloth.new(string).to_html
|
23
22
|
end
|
@@ -70,14 +69,15 @@ end
|
|
70
69
|
|
71
70
|
class TinySite
|
72
71
|
def initialize(opts)
|
73
|
-
@file_path
|
74
|
-
@
|
75
|
-
@
|
76
|
-
@
|
72
|
+
@file_path = opts[:file_path]
|
73
|
+
@file_path_postfix = opts[:file_path_postfix] || ''
|
74
|
+
@file_extension = opts[:file_extension] || 'textile'
|
75
|
+
@image_path = opts[:image_path] || File.join(@file_path, 'images')
|
76
|
+
@cache_buster = opts[:cache_buster] || 'bust'
|
77
77
|
end
|
78
78
|
|
79
79
|
def remote_file_url_for(filename)
|
80
|
-
File.join @file_path, "#{filename}.#{@file_extension}"
|
80
|
+
File.join @file_path, "#{filename}.#{@file_extension}#{@file_path_postfix}"
|
81
81
|
end
|
82
82
|
|
83
83
|
def render
|
@@ -87,8 +87,8 @@ class TinySite
|
|
87
87
|
_, page_file = CachedHttpFile.get remote_file_url_for(@status) if @status != 200
|
88
88
|
global_file_fetch_tread.join
|
89
89
|
|
90
|
-
global = TextileParts.parse @global_file, @image_path
|
91
|
-
page = TextileParts.parse page_file, @image_path
|
90
|
+
global = TextileParts.parse @global_file, @image_path, @file_path_postfix
|
91
|
+
page = TextileParts.parse page_file, @image_path, @file_path_postfix
|
92
92
|
|
93
93
|
render_layout :global => global, :page => page, :env => {:path => @path, :query_string => @query_string}
|
94
94
|
end
|