fairytale 0.7.9.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/fairytale.rb +57 -0
  2. metadata +46 -0
data/lib/fairytale.rb ADDED
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'stringio'
3
+ require 'fileutils'
4
+ require 'erb'
5
+ require 'tilt'
6
+
7
+ module Fairytale
8
+ def get url, layout = :"views/layout.erb", &block
9
+ print "Building #{url} ... "
10
+ view_content = block.call
11
+ view_content = tilt(layout, url: url) { view_content } unless layout.nil?
12
+
13
+ save url, view_content
14
+ print "saved"
15
+
16
+ reset!
17
+ puts
18
+ end
19
+
20
+ def save url, content
21
+ path = "webroot#{url}"
22
+ path += "index.html" if url[-1] == '/'
23
+ FileUtils.mkdir_p File.dirname path
24
+ File.open(path, "w+") { |f| f.write content }
25
+ end
26
+
27
+ def reset!
28
+ instance_variables.each { |var_symbol| instance_variable_set var_symbol, nil }
29
+ end
30
+
31
+ def md file, params = {}, &block
32
+ file = "content/#{file.to_s}" if file.class == Symbol
33
+ tilt(file, params, &block)
34
+ end
35
+
36
+ def erb file, params = {}, &block
37
+ file = "views/#{file.to_s}.erb" if file.class == Symbol
38
+ tilt(file, params, &block)
39
+ end
40
+
41
+ def sass file, params = {}, &block
42
+ file = "webroot/assets/css/#{file.to_s}.sass" if file.class == Symbol
43
+ tilt(file, params, &block)
44
+ end
45
+
46
+ def scss file, params = {}, &block
47
+ file = "webroot/assets/css/#{file.to_s}.scss" if file.class == Symbol
48
+ tilt(file, params, &block)
49
+ end
50
+
51
+ def tilt file, params = {}, &block
52
+ template = Tilt.new file.to_s
53
+ template.render(self, params) { block.call }
54
+ end
55
+ end
56
+
57
+ include Fairytale
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fairytale
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.9.pre
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Michael Mokrysz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-30 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Sinatra is awesome for building sites. Fairytale brings it's power and
15
+ freedom to static site compilation.
16
+ email: hi@46bit.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/fairytale.rb
22
+ homepage: http://rubygems.org/gems/fairytale
23
+ licenses: []
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>'
38
+ - !ruby/object:Gem::Version
39
+ version: 1.3.1
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 1.8.21
43
+ signing_key:
44
+ specification_version: 3
45
+ summary: Sinatra-like static site compiler.
46
+ test_files: []