fairytale 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/fairytale.rb +23 -46
  2. metadata +2 -2
data/lib/fairytale.rb CHANGED
@@ -1,67 +1,44 @@
1
1
  require 'rubygems'
2
- require 'stringio'
3
2
  require 'fileutils'
4
- require 'erb'
5
- require 'tilt'
6
- require 'digest/sha1'
3
+ require 'fairytale/helpers'
7
4
 
8
5
  module Fairytale
6
+ include Fairytale::Helpers
7
+
9
8
  def get url, layout = :"views/layout.erb", &block
9
+ @url = url
10
+
10
11
  print "Building #{url} ... "
11
12
  view_content = block.call
12
- view_content = tilt(layout, url: url) { view_content } unless layout.nil?
13
+
14
+ unless layout.nil?
15
+ view_content = tilt(layout) { view_content }
16
+ end
13
17
 
14
18
  save url, view_content
15
19
  print "saved"
16
20
 
17
- reset!
21
+ reset
18
22
  puts
19
23
  end
20
24
 
21
- def save url, content
22
- path = "webroot#{url}"
23
- path += "index.html" if url[-1] == '/'
24
- FileUtils.mkdir_p File.dirname path
25
- File.open(path, "w+") { |f| f.write content }
26
- end
27
-
28
- def reset!
29
- instance_variables.each { |var_symbol| instance_variable_set var_symbol, nil }
30
- end
31
-
25
+ # Present merely to mirror Sinatra
32
26
  def before &block
33
27
  block.call
34
28
  end
35
29
 
36
- def md file, params = {}, &block
37
- file = "content/#{file.to_s}" if file.class == Symbol
38
- tilt(file, params, &block)
39
- end
40
-
41
- def erb file, params = {}, &block
42
- file = "views/#{file.to_s}.erb" if file.class == Symbol
43
- tilt(file, params, &block)
44
- end
45
-
46
- def sass file, params = {}, &block
47
- file = "webroot/assets/css/#{file.to_s}.sass" if file.class == Symbol
48
- tilt(file, params, &block)
49
- end
50
-
51
- def scss file, params = {}, &block
52
- file = "webroot/assets/css/#{file.to_s}.scss" if file.class == Symbol
53
- tilt(file, params, &block)
54
- end
55
-
56
- def tilt file, params = {}, &block
57
- engine_options = params[:engine_options] || {}
58
- template = Tilt.new file.to_s, nil, engine_options
59
- template.render(self, params) { block.call }
60
- end
61
-
62
- def digest file
63
- Digest::SHA1.hexdigest File.read(file)
64
- end
30
+ protected
31
+ def save url, content
32
+ path = "public#{url}"
33
+ path += "index.html" if url[-1] == '/'
34
+ FileUtils.mkdir_p File.dirname path
35
+ File.open(path, "w+") { |f| f.write content }
36
+ end
37
+
38
+ # Resets this object, ready for the next 'request'
39
+ def reset
40
+ instance_variables.each { |var_symbol| instance_variable_set var_symbol, nil }
41
+ end
65
42
  end
66
43
 
67
44
  include Fairytale
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fairytale
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-30 00:00:00.000000000 Z
12
+ date: 2012-04-27 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Sinatra is awesome for building sites. Fairytale brings its power and
15
15
  freedom to static site compilation.