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.
@@ -1,3 +1,3 @@
1
1
  class TinySite
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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
- vars, *parts = tp.split(/^\+\+\+\+|\+\+\+\+$/)
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
- return vars, parts
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}.textile"
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
- global_vars, global_parts = TextileParts.parse @global_file, @image_path
87
- page_vars, page_parts = TextileParts.parse page_file, @image_path
90
+ global = TextileParts.parse @global_file, @image_path
91
+ page = TextileParts.parse page_file, @image_path
88
92
 
89
- render_layout :global_vars => global_vars, :global_parts => global_parts,
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[:page_vars][:layout] || params[:global_vars][:layout] || 'layout'
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
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: tiny_site
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.1.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Niko Dittmann