staticmatic3 2.1.9
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.
- checksums.yaml +7 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +43 -0
- data/LICENSE +20 -0
- data/README.md +154 -0
- data/Rakefile +45 -0
- data/VERSION.yml +5 -0
- data/bin/staticmatic +142 -0
- data/lib/staticmatic.rb +22 -0
- data/lib/staticmatic/ambiguous_template_error.rb +19 -0
- data/lib/staticmatic/base.rb +149 -0
- data/lib/staticmatic/compass.rb +5 -0
- data/lib/staticmatic/compass/app_integration.rb +21 -0
- data/lib/staticmatic/compass/configuration_defaults.rb +44 -0
- data/lib/staticmatic/compass/installer.rb +15 -0
- data/lib/staticmatic/configuration.rb +56 -0
- data/lib/staticmatic/deployers/aws-s3.rb +108 -0
- data/lib/staticmatic/deployers/config/amazon.yml +7 -0
- data/lib/staticmatic/error.rb +17 -0
- data/lib/staticmatic/helpers.rb +12 -0
- data/lib/staticmatic/helpers/assets_helper.rb +116 -0
- data/lib/staticmatic/helpers/current_path_helper.rb +22 -0
- data/lib/staticmatic/helpers/form_helper.rb +23 -0
- data/lib/staticmatic/helpers/render_helper.rb +14 -0
- data/lib/staticmatic/helpers/tag_helper.rb +35 -0
- data/lib/staticmatic/helpers/url_helper.rb +59 -0
- data/lib/staticmatic/mixins/build.rb +41 -0
- data/lib/staticmatic/mixins/helpers.rb +15 -0
- data/lib/staticmatic/mixins/render.rb +110 -0
- data/lib/staticmatic/mixins/rescue.rb +12 -0
- data/lib/staticmatic/mixins/server.rb +7 -0
- data/lib/staticmatic/mixins/setup.rb +16 -0
- data/lib/staticmatic/server.rb +87 -0
- data/lib/staticmatic/template_error.rb +44 -0
- data/lib/staticmatic/templates/rescues/default.haml +7 -0
- data/lib/staticmatic/templates/rescues/template.haml +18 -0
- data/spec/base_spec.rb +13 -0
- data/spec/compass_integration_spec.rb +28 -0
- data/spec/helpers/asset_helper_spec.rb +41 -0
- data/spec/helpers/custom_helper_spec.rb +17 -0
- data/spec/render_spec.rb +44 -0
- data/spec/rescue_spec.rb +36 -0
- data/spec/sandbox/test_site/config/compass.rb +1 -0
- data/spec/sandbox/test_site/config/site.rb +0 -0
- data/spec/sandbox/test_site/site/sub_folder/another_sub_folder/index.html +1 -0
- data/spec/sandbox/test_site/site/sub_folder/another_sub_folder/index.html.html +1 -0
- data/spec/sandbox/test_site/site/sub_folder/index.html +1 -0
- data/spec/sandbox/test_site/src/_helpers/application_helper.rb +5 -0
- data/spec/sandbox/test_site/src/_layouts/alternate_layout.haml +3 -0
- data/spec/sandbox/test_site/src/_layouts/default.haml +7 -0
- data/spec/sandbox/test_site/src/_layouts/projects.haml +1 -0
- data/spec/sandbox/test_site/src/_partials/menu.haml +1 -0
- data/spec/sandbox/test_site/src/_partials/partial_with_error.haml +1 -0
- data/spec/sandbox/test_site/src/hello_world.erb +1 -0
- data/spec/sandbox/test_site/src/index.haml +5 -0
- data/spec/sandbox/test_site/src/layout_test.haml +2 -0
- data/spec/sandbox/test_site/src/page_one.haml +3 -0
- data/spec/sandbox/test_site/src/page_two.haml +2 -0
- data/spec/sandbox/test_site/src/page_with_error.haml +5 -0
- data/spec/sandbox/test_site/src/page_with_partial_error.haml +3 -0
- data/spec/sandbox/test_site/src/stylesheets/application.sass +5 -0
- data/spec/sandbox/test_site/src/stylesheets/css_with_error.sass +5 -0
- data/spec/sandbox/test_site/src/stylesheets/nested/a_nested_stylesheet.sass +0 -0
- data/spec/sandbox/test_site/src/stylesheets/partials/_forms.sass +2 -0
- data/spec/sandbox/test_site/src/stylesheets/sassy.scss +12 -0
- data/spec/server_spec.rb +11 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/template_error_spec.rb +23 -0
- data/staticmatic.gemspec +158 -0
- data/staticmatic3.gemspec +164 -0
- data/website/Gemfile +1 -0
- data/website/config/site.rb +17 -0
- data/website/site/docs/compass_integration.html +70 -0
- data/website/site/docs/getting_started.html +49 -0
- data/website/site/docs/helpers.html +22 -0
- data/website/site/images/bycurve21.gif +0 -0
- data/website/site/images/curve21.jpg +0 -0
- data/website/site/images/homepage-build.jpg +0 -0
- data/website/site/images/homepage-previewing.jpg +0 -0
- data/website/site/images/homepage-templating.jpg +0 -0
- data/website/site/stylesheets/ie.css +5 -0
- data/website/site/stylesheets/print.css +372 -0
- data/website/site/stylesheets/screen.css +488 -0
- data/website/src/helpers/content_helper.rb +10 -0
- data/website/src/layouts/default.haml +15 -0
- data/website/src/pages/development.haml +9 -0
- data/website/src/pages/docs/_menu.haml +4 -0
- data/website/src/pages/docs/_requires_prerelease.haml +4 -0
- data/website/src/pages/docs/compass_integration.haml +54 -0
- data/website/src/pages/docs/getting_started.haml +31 -0
- data/website/src/pages/docs/helpers.haml +1 -0
- data/website/src/pages/index.haml +27 -0
- data/website/src/stylesheets/_base.scss +43 -0
- data/website/src/stylesheets/_defaults.scss +260 -0
- data/website/src/stylesheets/ie.scss +10 -0
- data/website/src/stylesheets/print.scss +33 -0
- data/website/src/stylesheets/screen.scss +73 -0
- metadata +285 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
["assets", "form", "current_path", "render", "tag", "url"].each do |helper|
|
2
|
+
require File.join(File.dirname(__FILE__), "helpers", "#{helper}_helper")
|
3
|
+
end
|
4
|
+
|
5
|
+
module StaticMatic::Helpers
|
6
|
+
include TagHelper
|
7
|
+
include UrlHelper
|
8
|
+
include AssetsHelper
|
9
|
+
include FormHelper
|
10
|
+
include RenderHelper
|
11
|
+
include CurrentPathHelper
|
12
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module StaticMatic
|
2
|
+
module Helpers
|
3
|
+
module AssetsHelper
|
4
|
+
self.extend self
|
5
|
+
|
6
|
+
# Generates links to all stylesheets in the source directory
|
7
|
+
# = stylesheets
|
8
|
+
# or specific stylesheets in a specific order
|
9
|
+
# = stylesheets :reset, :application
|
10
|
+
# Can also pass options hash in at the end so you can specify :media => :print
|
11
|
+
def stylesheets(*params)
|
12
|
+
options = (params.last.is_a? Hash) ? params.pop : {}
|
13
|
+
|
14
|
+
options[:media] = 'all' unless options.has_key?(:media)
|
15
|
+
options[:rel] = 'stylesheet'; options[:type] = 'text/css'
|
16
|
+
|
17
|
+
src_files = @staticmatic.src_file_paths('sass','scss','css')
|
18
|
+
output = ""
|
19
|
+
|
20
|
+
if params.length == 0
|
21
|
+
# no specified files; include them all!
|
22
|
+
src_files.each {|path| output << format_output(:link,path,options) }
|
23
|
+
else
|
24
|
+
# specific files requested and in a specific order
|
25
|
+
params.each do |file|
|
26
|
+
|
27
|
+
if file.to_s.match %r{^https?://}
|
28
|
+
output << format_output(:link,file,options)
|
29
|
+
else
|
30
|
+
idx = src_files.index do |src|
|
31
|
+
%w{sass scss css}.map {|t| src.match /#{file}\.#{t}$/ }.any?
|
32
|
+
end
|
33
|
+
output << format_output(:link,src_files[idx],options) unless idx.nil?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
output
|
38
|
+
end
|
39
|
+
|
40
|
+
# Generate javascript source tags for the specified files
|
41
|
+
#
|
42
|
+
# javascripts('test') -> <script language="javascript" src="path/to/test.js"></script>
|
43
|
+
#
|
44
|
+
def javascripts(*files)
|
45
|
+
options = (files.last.is_a? Hash) ? files.pop : {}
|
46
|
+
|
47
|
+
options[:language] = 'javascript'
|
48
|
+
options[:type] = 'text/javascript'
|
49
|
+
|
50
|
+
src_files = @staticmatic.src_file_paths('js','coffee')
|
51
|
+
output = ""
|
52
|
+
|
53
|
+
files.each do |path|
|
54
|
+
if path.to_s.match %r{^https?://}
|
55
|
+
output << format_output(:script,path,options)
|
56
|
+
else
|
57
|
+
idx = src_files.index do |src|
|
58
|
+
%w{coffee js}.map {|t| src.match /#{path.to_s}\.#{t}$/ }.any?
|
59
|
+
end
|
60
|
+
output << format_output(:script,src_files[idx],options) unless idx.nil?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
output
|
64
|
+
end
|
65
|
+
|
66
|
+
# Generates an image tag always relative to the current page unless absolute path or http url specified.
|
67
|
+
#
|
68
|
+
# img('test_image.gif') -> <img src="/images/test_image.gif" alt="Test image"/>
|
69
|
+
# img('contact/test_image.gif') -> <img src="/images/contact/test_image.gif" alt="Test image"/>
|
70
|
+
# img('http://localhost/test_image.gif') -> <img src="http://localhost/test_image.gif" alt="Test image"/>
|
71
|
+
def img(name, options = {})
|
72
|
+
options[:src] = name.match(%r{^((\.\.?)?/|https?://)}) ? name : "#{current_page_relative_path}images/#{name}"
|
73
|
+
options[:alt] ||= name.split('/').last.split('.').first.capitalize.gsub(/_|-/, ' ')
|
74
|
+
tag :img, options
|
75
|
+
end
|
76
|
+
|
77
|
+
def format_output(tag_type,path,options)
|
78
|
+
external_url = !!path.match(%r{^https?://})
|
79
|
+
|
80
|
+
if external_url
|
81
|
+
src = path
|
82
|
+
else
|
83
|
+
filename_without_extension = File.basename(path).chomp(File.extname(path))
|
84
|
+
|
85
|
+
path = path.gsub(/^#{@staticmatic.src_dir}/, "").
|
86
|
+
gsub(/^#{@staticmatic.site_dir}/, "").
|
87
|
+
gsub(/#{filename_without_extension}\.(sass|scss|css|js|coffee)/, "").
|
88
|
+
gsub(/^\//, "")
|
89
|
+
paths = [current_page_relative_path, path, "#{filename_without_extension}"].compact
|
90
|
+
src = File.join(*paths)
|
91
|
+
end
|
92
|
+
|
93
|
+
if tag_type == :link
|
94
|
+
src += '.css' if !external_url
|
95
|
+
options[:href] = qstring(src, options[:qstring]); options.delete :qstring
|
96
|
+
tag(tag_type,options)
|
97
|
+
elsif tag_type == :script
|
98
|
+
src += '.js' if !external_url
|
99
|
+
options[:src] = qstring(src, options[:qstring]); options.delete :qstring
|
100
|
+
tag(tag_type,options) { '' }
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
# Prepares a query string based on the given qstr.
|
106
|
+
# If qstr is true, it generates a query string based on the current time.
|
107
|
+
# If qstr is a string, it uses it as the query string itself.
|
108
|
+
#
|
109
|
+
def qstring(src,qstr)
|
110
|
+
src += '?_=' + Time.now.to_i.to_s if qstr == true
|
111
|
+
src += '?_=' + qstr if qstr.is_a? String
|
112
|
+
src
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module StaticMatic
|
2
|
+
module Helpers
|
3
|
+
module CurrentPathHelper
|
4
|
+
self.extend self
|
5
|
+
|
6
|
+
def current_page
|
7
|
+
@staticmatic.current_file
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def current_page_relative_path(current_path = nil)
|
13
|
+
if current_path.nil? || current_path.match(/^((\.\.?)?\/|\#|.+?\:)/) == nil
|
14
|
+
current_page_depth = current_page.split('/').length - 3;
|
15
|
+
(current_page_depth > 0) ? ([ '..' ] * current_page_depth).join('/') + '/' : nil
|
16
|
+
else
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
module StaticMatic
|
3
|
+
module Helpers
|
4
|
+
module FormHelper
|
5
|
+
self.extend self
|
6
|
+
|
7
|
+
# Generates a form text field
|
8
|
+
#
|
9
|
+
def text_field(name, value, options = {})
|
10
|
+
options.merge!(:type => "text", :name => name, :value => value)
|
11
|
+
tag(:input, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
# Generate a form textarea
|
16
|
+
#
|
17
|
+
def text_area(name, value, options = {})
|
18
|
+
options.merge!(:name => name)
|
19
|
+
tag(:textarea, options) { value }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
module StaticMatic
|
3
|
+
module Helpers
|
4
|
+
module RenderHelper
|
5
|
+
self.extend self
|
6
|
+
|
7
|
+
# Include a partial template
|
8
|
+
def partial(name, options = {})
|
9
|
+
name = @staticmatic.ensure_extension(name)
|
10
|
+
@staticmatic.generate_partial(name, options)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module StaticMatic
|
2
|
+
module Helpers
|
3
|
+
module TagHelper
|
4
|
+
self.extend self
|
5
|
+
|
6
|
+
# Generates HTML tags:
|
7
|
+
#
|
8
|
+
# tag(:br) -> <br/>
|
9
|
+
# tag(:a, :href => 'test.html') { "Test" } -> <a href="test.html">Test</a>
|
10
|
+
#
|
11
|
+
def tag(name, options = {}, &block)
|
12
|
+
options[:id] ||= options[:name] if options[:name]
|
13
|
+
output = "<#{name}"
|
14
|
+
options.keys.sort { |a, b| a.to_s <=> b.to_s }.each do |key|
|
15
|
+
output << " #{key}=\"#{options[key]}\"" if options[key]
|
16
|
+
end
|
17
|
+
|
18
|
+
if block_given?
|
19
|
+
output << ">"
|
20
|
+
output << yield
|
21
|
+
output << "</#{name}>"
|
22
|
+
else
|
23
|
+
format = @staticmatic.configuration.engine_options['haml'][:format]
|
24
|
+
|
25
|
+
if format.nil? || format == :xhtml
|
26
|
+
output << "/>"
|
27
|
+
else
|
28
|
+
output << ">"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
output
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module StaticMatic
|
2
|
+
module Helpers
|
3
|
+
module UrlHelper
|
4
|
+
self.extend self
|
5
|
+
|
6
|
+
# Generate an HTML link
|
7
|
+
#
|
8
|
+
# If only the title is passed, it will automatically
|
9
|
+
# create a link from this value:
|
10
|
+
#
|
11
|
+
# link('Test') -> <a href="test.html">Test</a>
|
12
|
+
#
|
13
|
+
def link(title, href = "", options = {})
|
14
|
+
if href.is_a?(Hash)
|
15
|
+
options = href
|
16
|
+
href = ""
|
17
|
+
end
|
18
|
+
|
19
|
+
if href.nil? || href.strip.length < 1
|
20
|
+
path_prefix = ''
|
21
|
+
if title.match(/^(\.\.?)?\//)
|
22
|
+
# starts with relative path so strip it off and prepend it to the urlified title
|
23
|
+
path_prefix_match = title.match(/^[^\s]*\//)
|
24
|
+
path_prefix = path_prefix_match[0] if path_prefix_match
|
25
|
+
title = title[path_prefix.length, title.length]
|
26
|
+
end
|
27
|
+
href = path_prefix + urlify(title) + ".html"
|
28
|
+
end
|
29
|
+
|
30
|
+
options[:href] = "#{current_page_relative_path(href)}#{href}"
|
31
|
+
|
32
|
+
local_page = (options[:href].match(/^(\#|.+?\:)/) == nil)
|
33
|
+
unless @staticmatic.configuration.use_extensions_for_page_links || !local_page
|
34
|
+
options[:href].chomp!(".html")
|
35
|
+
options[:href].chomp!("index") if options[:href][-5, 5] == 'index'
|
36
|
+
end
|
37
|
+
|
38
|
+
tag(:a, options) { title }
|
39
|
+
end
|
40
|
+
alias link_to link
|
41
|
+
|
42
|
+
# Generates a URL friendly string from the value passed:
|
43
|
+
#
|
44
|
+
# "We love Haml" -> "we_love_haml"
|
45
|
+
# "Elf & Ham" -> "elf_and_ham"
|
46
|
+
# "Stephen's gem" -> "stephens_gem"
|
47
|
+
#
|
48
|
+
def urlify(string)
|
49
|
+
string.tr(" ", "_").
|
50
|
+
sub("&", "and").
|
51
|
+
sub("@", "at").
|
52
|
+
tr("^A-Za-z0-9_", "").
|
53
|
+
sub(/_{2,}/, "_").
|
54
|
+
downcase
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module StaticMatic::BuildMixin
|
2
|
+
|
3
|
+
def build
|
4
|
+
src_file_paths('*').each do |src_path|
|
5
|
+
ext = File.extname(src_path).sub(/^\./, '')
|
6
|
+
|
7
|
+
if Tilt.mappings[ext].length > 0 and not File.directory? src_path
|
8
|
+
generate_site_file(src_path)
|
9
|
+
else
|
10
|
+
copy_file_from_src_to_site(src_path)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def copy_file_from_src_to_site(src_path)
|
18
|
+
site_path = src_path.gsub /^#{@src_dir}/, @site_dir
|
19
|
+
|
20
|
+
FileUtils.mkdir_p(File.dirname site_path)
|
21
|
+
FileUtils.cp_r src_path, site_path
|
22
|
+
end
|
23
|
+
|
24
|
+
def generate_site_file(src_path)
|
25
|
+
dir, name, ext = expand_path(src_path.gsub /^#{@src_dir}/, @site_dir)
|
26
|
+
target_ext = configuration.reverse_ext_mappings[ext]
|
27
|
+
site_path = File.join(dir, "#{name}.#{target_ext}")
|
28
|
+
|
29
|
+
puts " Rendered #{src_path} => #{site_path}"
|
30
|
+
|
31
|
+
FileUtils.mkdir_p(File.dirname site_path)
|
32
|
+
File.open(site_path, 'w+') do |f|
|
33
|
+
if target_ext == 'html'
|
34
|
+
f << render_template_with_layout(src_path)
|
35
|
+
else
|
36
|
+
f << render_template(src_path)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module StaticMatic::HelpersMixin
|
2
|
+
# Loads any helpers present in the helpers dir and mixes them into the template helpers
|
3
|
+
def load_helpers
|
4
|
+
|
5
|
+
Dir["#{@src_dir}/_helpers/**/*_helper.rb"].each do |helper|
|
6
|
+
load_helper(helper)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def load_helper(helper)
|
11
|
+
load helper
|
12
|
+
module_name = File.basename(helper, '.rb').gsub(/(^|\_)./) { |c| c.upcase }.gsub(/\_/, '')
|
13
|
+
Haml::Helpers.class_eval("include #{module_name}")
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module StaticMatic::RenderMixin
|
2
|
+
|
3
|
+
# clear all scope variables except @staticmatic
|
4
|
+
def clear_template_variables!
|
5
|
+
|
6
|
+
@scope.instance_variables.each do |var|
|
7
|
+
@scope.instance_variable_set(var, nil) unless var == '@staticmatic' || var == :@staticmatic
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Generate html from source file:
|
12
|
+
# render_template("index.haml")
|
13
|
+
def render_template(file_path)
|
14
|
+
@current_file_stack.push(file_path)
|
15
|
+
begin
|
16
|
+
tilt_template(file_path)
|
17
|
+
rescue StaticMatic::TemplateError => e
|
18
|
+
raise e # re-raise inline errors
|
19
|
+
rescue Exception => e
|
20
|
+
raise StaticMatic::TemplateError.new(file_path, e)
|
21
|
+
ensure
|
22
|
+
@current_file_stack.pop
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def render_template_with_layout(file_path)
|
27
|
+
@current_file_stack.push(file_path)
|
28
|
+
begin
|
29
|
+
rendered_file_content = render_template(file_path)
|
30
|
+
tilt_template_with_layout(fetch_layout_path) { rendered_file_content }
|
31
|
+
rescue Exception => e
|
32
|
+
render_rescue_from_error(e)
|
33
|
+
ensure
|
34
|
+
@current_file_stack.pop
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def generate_partial(name, options = {})
|
39
|
+
partial_dir, partial_name, partial_ext = expand_path name
|
40
|
+
partial_name = "_#{partial_name}"
|
41
|
+
|
42
|
+
context = File.join File.dirname(self.current_file), partial_dir
|
43
|
+
partial_path = determine_template_path(partial_name, partial_ext, context)
|
44
|
+
|
45
|
+
unless partial_path && File.exists?(partial_path)
|
46
|
+
# partial not found in the current file's directory, so try the _partials folder
|
47
|
+
context = File.join @src_dir, '_partials', partial_dir
|
48
|
+
partial_name.sub! /^_/, ''
|
49
|
+
partial_path = determine_template_path(partial_name, partial_ext, context)
|
50
|
+
end
|
51
|
+
|
52
|
+
if partial_path && File.exists?(partial_path)
|
53
|
+
return render_template partial_path
|
54
|
+
else
|
55
|
+
raise StaticMatic::Error.new("", name, "Partial not found")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def fetch_layout_path(dir = nil)
|
60
|
+
layout_path = File.join(@src_dir, "_layouts")
|
61
|
+
declared_layout_name = @scope.instance_variable_get("@layout")
|
62
|
+
|
63
|
+
if declared_layout_name
|
64
|
+
path = determine_template_path declared_layout_name, '', layout_path
|
65
|
+
unless path
|
66
|
+
error_path = File.join(layout_path, declared_layout_name)
|
67
|
+
raise StaticMatic::Error.new("", error_path, "Layout not found")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
if dir
|
72
|
+
dir_layout_name = dir.split("/")[1]
|
73
|
+
path ||= determine_template_path dir_layout_name, '', layout_path
|
74
|
+
end
|
75
|
+
path ||= determine_template_path @default_layout_name, '', layout_path
|
76
|
+
|
77
|
+
unless path
|
78
|
+
error_path = File.join(layout_path, @default_layout_name)
|
79
|
+
raise StaticMatic::Error.new("", error_path, "No default layout could be found")
|
80
|
+
end
|
81
|
+
|
82
|
+
return path
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
# TODO: more code reuse. needs some ruby &block and yield sorcery.
|
88
|
+
def tilt_template(file_path)
|
89
|
+
options = get_engine_options(file_path)
|
90
|
+
Tilt.new(file_path, options).render(@scope)
|
91
|
+
end
|
92
|
+
|
93
|
+
def tilt_template_with_layout(file_path)
|
94
|
+
options = get_engine_options(file_path)
|
95
|
+
Tilt.new(file_path, options).render(@scope) { yield }
|
96
|
+
end
|
97
|
+
|
98
|
+
def get_engine_options(file_path)
|
99
|
+
ext = File.extname(file_path).sub(/^\./, '')
|
100
|
+
options = configuration.engine_options[ext] || {}
|
101
|
+
preview_options = configuration.preview_engine_options[ext] || {}
|
102
|
+
|
103
|
+
if @mode == :preview
|
104
|
+
options.merge preview_options
|
105
|
+
else
|
106
|
+
options
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|