tdreyno-staticmatic 2.9.0 → 2.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/bin/sm-build +19 -2
  2. data/bin/sm-init +2 -2
  3. data/bin/sm-server +12 -2
  4. data/lib/builder.rb +46 -0
  5. data/lib/generator.rb +27 -0
  6. data/lib/merb/init.rb +31 -0
  7. data/lib/merb/router.rb +3 -0
  8. data/lib/merb/site.rb +41 -0
  9. data/lib/{templates → template}/helpers/site_helper.rb +3 -1
  10. data/lib/{templates/layouts → template/layout}/site.html.haml +1 -1
  11. data/lib/{templates → template}/pages/index.html.haml +0 -0
  12. data/lib/{templates/stylesheets/site.css.sass → template/stylesheets/sass/site.sass} +0 -0
  13. data/spec/builder_spec.rb +31 -16
  14. data/spec/fixtures/sample/helpers/speech_helper.rb +5 -3
  15. data/spec/fixtures/sample/{layouts → pages/layout}/site.html.erb +0 -0
  16. data/spec/fixtures/sample/{layouts → pages/layout}/specified_layout.html.erb +0 -0
  17. data/spec/fixtures/sample/pages/partial_test.html.erb +1 -1
  18. data/spec/fixtures/sample/stylesheets/{site.css.sass → sass/site.sass} +0 -0
  19. metadata +27 -76
  20. data/lib/staticmatic/actionpack_support/mime.rb +0 -5
  21. data/lib/staticmatic/actionpack_support/remove_controller_caching.rb +0 -7
  22. data/lib/staticmatic/actionpack_support/remove_partial_benchmark.rb +0 -6
  23. data/lib/staticmatic/autoload.rb +0 -18
  24. data/lib/staticmatic/base.rb +0 -77
  25. data/lib/staticmatic/builder/dotnet.rb +0 -44
  26. data/lib/staticmatic/builder/html.rb +0 -23
  27. data/lib/staticmatic/builder.rb +0 -86
  28. data/lib/staticmatic/config.rb +0 -41
  29. data/lib/staticmatic/deprecation.rb +0 -26
  30. data/lib/staticmatic/generator.rb +0 -28
  31. data/lib/staticmatic/helpers/asset_tag_helper.rb +0 -11
  32. data/lib/staticmatic/helpers/page_helper.rb +0 -9
  33. data/lib/staticmatic/helpers/url_helper.rb +0 -19
  34. data/lib/staticmatic/previewer.rb +0 -54
  35. data/lib/staticmatic/template.rb +0 -97
  36. data/lib/staticmatic/template_handlers/haml.rb +0 -15
  37. data/lib/staticmatic/template_handlers/liquid.rb +0 -9
  38. data/lib/staticmatic/template_handlers/markdown.rb +0 -9
  39. data/lib/staticmatic/template_handlers/sass.rb +0 -9
  40. data/lib/staticmatic/template_handlers/textile.rb +0 -9
  41. data/lib/staticmatic/templates/rescues/default_error.html.erb +0 -2
  42. data/lib/staticmatic/templates/rescues/template_error.html.erb +0 -19
  43. data/lib/staticmatic.rb +0 -32
  44. data/spec/action_view_helpers_spec.rb +0 -12
  45. data/spec/asset_helpers_spec.rb +0 -24
  46. data/spec/base_spec.rb +0 -54
  47. data/spec/config_spec.rb +0 -31
  48. data/spec/deprecation_spec.rb +0 -18
  49. data/spec/fixtures/sample/build/haml_test.html +0 -11
  50. data/spec/fixtures/sample/build/hello_world.html +0 -9
  51. data/spec/fixtures/sample/build/index.html +0 -9
  52. data/spec/fixtures/sample/build/page_with_error.html +0 -61
  53. data/spec/fixtures/sample/build/services/index.html +0 -9
  54. data/spec/fixtures/sample/build/services/web_development.html +0 -9
  55. data/spec/fixtures/sample/build/stylesheets/site.css +0 -3
  56. data/spec/fixtures/sample/pages/liquid_test.html.liquid +0 -3
  57. data/spec/fixtures/sample/pages/markdown_test.html.markdown +0 -3
  58. data/spec/fixtures/sample/pages/page_with_error.html.haml +0 -3
  59. data/spec/fixtures/sample/pages/textile_test.html.textile +0 -3
  60. data/spec/layouts_spec.rb +0 -28
  61. data/spec/rendering_spec.rb +0 -62
@@ -1,44 +0,0 @@
1
- module StaticMatic
2
- module Builder
3
- class DotNetGenerator < BaseGenerator
4
- glob! "images", [] # No templates
5
- glob! "javascripts", [] # No templates
6
- glob! "stylesheets", site.extentions # Registered templates
7
-
8
- # Run the dynamic pages through actionpack
9
- site.dynamic_pages.each do |relative_path|
10
- output_name = site.rendered_ext(relative_path).gsub("pages/", "")
11
- template output_name.gsub('.', '_').to_sym, relative_path, output_name
12
- end
13
-
14
- # Build master pages
15
- site.layouts.each do |layout_name|
16
- file_name = (site.layouts.length <= 1) ? "MasterPage" : layout_name.split('.')[0].capitalize
17
- template :layout, File.join("layouts", layout_name), "#{file_name}.master"
18
- end
19
-
20
- # Copy static pages
21
- site.static_pages.each do |relative_path|
22
- output_name = relative_path.gsub("pages/", "")
23
- file output_name.gsub('.', '_').to_sym, relative_path, output_name
24
- end
25
-
26
- def render(action)
27
- if action.name == :layout
28
- output = site.render_layout(action.source, '<asp:ContentPlaceHolder id="content" runat="server" />')
29
- file_name = File.basename(action.destination).gsub(".master", '')
30
- prefix = %Q(<%@ Master Language="C#" AutoEventWireup="true" CodeFile="#{file_name}.master.cs" Inherits="#{file_name}" %>)
31
- output = prefix + "\n" + output
32
- output.gsub!("<head", '<head runat="server"')
33
- else
34
- # replace content_for with <asp:whatevers
35
- site.render(action.source)
36
- #prefix = %Q(<%@ Master Language="C#" AutoEventWireup="true" CodeFile="#{file_name}.master.cs" Inherits="#{file_name}" %>)
37
- #output = prefix + "\n" + output
38
- end
39
- end
40
- end
41
-
42
- add :build_dotnet, DotNetGenerator
43
- end
44
- end
@@ -1,23 +0,0 @@
1
- module StaticMatic
2
- module Builder
3
- class HTMLGenerator < BaseGenerator
4
- glob! "images", [] # No templates
5
- glob! "javascripts", [] # No templates
6
- glob! "stylesheets", site.extentions # Registered templates
7
-
8
- # Run the dynamic pages through actionpack
9
- site.dynamic_pages.each do |relative_path|
10
- output_name = site.rendered_ext(relative_path).gsub("pages/", "")
11
- template output_name.gsub('.', '_').to_sym, relative_path, output_name
12
- end
13
-
14
- # Copy static pages
15
- site.static_pages.each do |relative_path|
16
- output_name = relative_path.gsub("pages/", "")
17
- file output_name.gsub('.', '_').to_sym, relative_path, output_name
18
- end
19
- end
20
-
21
- add :build_html, HTMLGenerator
22
- end
23
- end
@@ -1,86 +0,0 @@
1
- require 'templater'
2
- require 'zip/zip'
3
- require 'find'
4
- require 'fileutils'
5
-
6
- module StaticMatic
7
- module Builder
8
- extend Templater::Manifold
9
- desc "Multiple ways to build a staticmatic site"
10
-
11
- class BaseGenerator < Templater::Generator
12
- # Setup StaticMatic site
13
- def self.site; @@site ||= ::StaticMatic::Base.new(Dir.pwd); end
14
- def site; self.class.site; end
15
-
16
- # Define source and desintation
17
- def self.source_root; site.root_dir; end
18
- def destination_root; site.build_dir; end
19
-
20
- # Override template to ask staticmatic for the correct extension to output
21
- # NOTE: could probably be better
22
- def self.template(name, *args, &block)
23
- ext = File.extname(args.first)
24
- ext = ext[1..ext.length]
25
-
26
- if (args[0] === args[1]) && (site.extentions.include? ext)
27
- args[1] = site.rendered_ext(args[0])
28
- end
29
-
30
- super(name, *args, &block)
31
- end
32
-
33
- def render(action)
34
- site.render(action.source)
35
- end
36
- end
37
-
38
- require File.join(File.dirname(__FILE__), 'builder', 'html')
39
- require File.join(File.dirname(__FILE__), 'builder', 'dotnet')
40
-
41
- class BuilderGenerator < Templater::Generator
42
- # Setup StaticMatic site
43
- def self.site; @@site ||= ::StaticMatic::Base.new(Dir.pwd); end
44
- def site; self.class.site; end
45
-
46
- option :format, :default => :html, :desc => "Which format to export as (html, dotnet)"
47
- option :package, :as => :boolean, :desc => "Build a Zip file"
48
-
49
- invoke :build_html, :format => :html
50
- invoke :build_dotnet, :format => :dotnet
51
-
52
- def after_generation
53
- return unless package
54
-
55
- output_file = File.join(site.build_dir, "package.zip")
56
- FileUtils.rm(output_file) if File.exists?(output_file)
57
-
58
- Zip::ZipFile.open(output_file, Zip::ZipFile::CREATE) do |zipfile|
59
- Find.find(site.build_dir) do |path|
60
- Find.prune if File.basename(path)[0] == ?.
61
- dest = /build\/(\w.*)/.match(path)
62
- zipfile.add(dest[1], path) if dest
63
- end
64
- end
65
-
66
- status_flag = "[PACKAGE]".rjust(12)
67
- say "<%= color('#{status_flag}', :green) %> " + File.basename(output_file)
68
- end
69
- end
70
-
71
- add :build, BuilderGenerator
72
- end
73
- end
74
-
75
- # Monkey-patch to use a dynamic renderer, not just ERb
76
- class Templater::Actions::Template
77
- # Re-route back to the generator
78
- def render
79
- if generator.respond_to? :render
80
- generator.render(self)
81
- else
82
- context = generator.instance_eval 'binding'
83
- ERB.new(::File.read(source), nil, '-').result(context)
84
- end
85
- end
86
- end
@@ -1,41 +0,0 @@
1
- class StaticMatic::Config
2
- class << self
3
- def defaults
4
- @defaults ||= {
5
- :host => "0.0.0.0",
6
- :port => "3000",
7
- :sass_options => {},
8
- :haml_options => {},
9
- :use_build_tracking => true
10
- }
11
- end
12
-
13
- def setup(settings = {})
14
- @configuration = defaults.merge(settings)
15
- end
16
-
17
- def key?(key)
18
- @configuration.key?(key)
19
- end
20
-
21
- def [](key)
22
- (@configuration||={})[key]
23
- end
24
-
25
- def []=(key,val)
26
- @configuration[key] = val
27
- end
28
-
29
- def delete(key)
30
- @configuration.delete(key)
31
- end
32
-
33
- def fetch(key, default)
34
- @configuration.fetch(key, default)
35
- end
36
-
37
- def to_hash
38
- @configuration
39
- end
40
- end
41
- end
@@ -1,26 +0,0 @@
1
- module StaticMatic
2
- module Deprecation
3
- def deprecate(options = {})
4
- message = "#{caller_method_name} has been deprecated and will be removed."
5
- message << %Q{ Please use "#{options[:alt]}" instead } if options[:alt]
6
-
7
- logger.warn(message)
8
- end
9
-
10
- private
11
-
12
- # Thanks to http://snippets.dzone.com/posts/show/2787 for this nugget
13
- def caller_method_name
14
- parse_caller(caller(2).first).last
15
- end
16
-
17
- def parse_caller(at)
18
- if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
19
- file = Regexp.last_match[1]
20
- line = Regexp.last_match[2].to_i
21
- method = Regexp.last_match[3]
22
- [file, line, method]
23
- end
24
- end
25
- end
26
- end
@@ -1,28 +0,0 @@
1
- require 'templater'
2
-
3
- module StaticMatic
4
- module Generator
5
- extend Templater::Manifold
6
- desc "Generator for streamlining staticmatic"
7
-
8
- class StaticmaticGenerator < Templater::Generator
9
- desc "Creates a new staticmatic scaffold."
10
- first_argument :location, :required => true, :desc => "Project location"
11
-
12
- def destination_root
13
- File.expand_path(location)
14
- end
15
-
16
- def self.source_root
17
- File.join(File.dirname(__FILE__), '../templates')
18
- end
19
-
20
- glob!
21
- empty_directory :build, "build"
22
- empty_directory :javascripts, "javascripts"
23
- empty_directory :images, "images"
24
- end
25
-
26
- add :setup, StaticmaticGenerator
27
- end
28
- end
@@ -1,11 +0,0 @@
1
- module StaticMatic
2
- module Helpers
3
- module AssetTagHelper
4
- def compute_public_path(source, dir, ext = nil, include_host = true)
5
- path = "#{@relative_path_to_root}#{dir}/#{source}"
6
- path << ".#{ext}" if ext
7
- path
8
- end
9
- end
10
- end
11
- end
@@ -1,9 +0,0 @@
1
- module StaticMatic
2
- module Helpers
3
- module PageHelper
4
- def current_page
5
- @current_page
6
- end
7
- end
8
- end
9
- end
@@ -1,19 +0,0 @@
1
- module StaticMatic
2
- module Helpers
3
- module UrlHelper
4
- def link_to(name, options = {}, html_options = nil)
5
- options = urlify(name) if options == {}
6
- super(name, options, html_options)
7
- end
8
-
9
- def urlify(string)
10
- string.tr(" ", "_").
11
- sub("&", "and").
12
- sub("@", "at").
13
- tr("^A-Za-z0-9_", "").
14
- sub(/_{2,}/, "_").
15
- downcase
16
- end
17
- end
18
- end
19
- end
@@ -1,54 +0,0 @@
1
- require 'mongrel'
2
-
3
- module StaticMatic
4
- class Previewer < Mongrel::HttpHandler
5
- def initialize(staticmatic)
6
- @files = Mongrel::DirHandler.new(staticmatic.root_dir, false)
7
- @guard = Mutex.new
8
- @staticmatic = staticmatic
9
- end
10
-
11
- def process(request, response)
12
- return if response.socket.closed?
13
-
14
- path_info = request.params[Mongrel::Const::PATH_INFO].chomp("/")
15
- get_or_head = %w(GET HEAD).include? request.params[Mongrel::Const::REQUEST_METHOD]
16
-
17
- # Reload(and therefore can_render?) is not thread-safe... so lame
18
- @guard.synchronize {
19
- if @staticmatic.can_render? path_info
20
- file_ext = File.extname(path_info).gsub(/^\./, '')
21
- file_ext = "html" if file_ext.blank?
22
- file_name = CGI::unescape(path_info).gsub!(/^\//, '') || ''
23
- begin
24
- response.start(200) do |head, out|
25
- output = @staticmatic.render(file_name)
26
- head[Mongrel::Const::CONTENT_TYPE] = Mongrel::DirHandler::MIME_TYPES[".#{file_ext}"] || "application/octet-stream"
27
- out.write(output || "")
28
- end
29
- rescue Errno::EPIPE
30
- response.socket.close
31
- end
32
- elsif get_or_head and @files.can_serve(path_info)
33
- @files.process(request, response) # try to serve static file from site dir
34
- end
35
- }
36
- end
37
-
38
- class << self
39
- # Starts the StaticMatic preview server
40
- def start(staticmatic)
41
- staticmatic = StaticMatic::Base.new(staticmatic) if staticmatic.is_a? String
42
- Mongrel::Configurator.new :host => StaticMatic::Config[:host] do
43
- puts "Running Preview of #{staticmatic.root_dir} on port #{StaticMatic::Config[:port]}"
44
- listener :port => StaticMatic::Config[:port] do
45
- uri "/", :handler => Previewer.new(staticmatic)
46
- uri "/favicon", :handler => Mongrel::Error404Handler.new("")
47
- end
48
- trap("INT") { stop }
49
- run
50
- end.join
51
- end
52
- end
53
- end
54
- end
@@ -1,97 +0,0 @@
1
- module StaticMatic
2
- class Template
3
- attr_accessor :view, :path
4
-
5
- def initialize(filename, site)
6
- @path = filename
7
- @site = site
8
-
9
- @view = ActionView::Base.new([], {}, self)
10
- @view.template_format = determine_format_for(@path)
11
- @view.finder.view_paths = [ @site.root_dir ]
12
- @view.instance_variable_set("@staticmatic", @site)
13
- end
14
-
15
- def can_render?
16
- @view.finder.class.reload!
17
- @view.finder.file_exists?(strip_extension(@path))
18
- end
19
-
20
- def render
21
- load_helpers
22
-
23
- @view.instance_variable_set("@current_page", File.basename(@path))
24
- output = @view.render_file(strip_extension(@path), true)
25
- return output if layout === false
26
-
27
- render_with_layout(layout, output)
28
- rescue Exception => e
29
- rescue_from_error(e)
30
- end
31
-
32
- def rendered_ext
33
- @path.gsub(Regexp.new('\.(' + @site.extentions.join('|') + ')'), '')
34
- end
35
-
36
- protected
37
- def render_with_layout(layout, content)
38
- #layout = full_template_path(layout).gsub("pages/", "layouts/")
39
- @view.instance_variable_set("@content_for_layout", content)
40
- output = @view.render_file("layouts/#{layout}", true)
41
-
42
- # little bit of cleaning for content_for blocks which concat by default (wtf?)
43
- @view.instance_variables.grep(/content_for_|layout/).select do |name|
44
- name != "content_for_layout"
45
- end.each do |name|
46
- @view.instance_variable_set(name, nil)
47
- end
48
-
49
- output
50
- end
51
-
52
- def layout
53
- return false unless @path.include? "pages"
54
-
55
- layout = @view.instance_variable_get("@layout")
56
- layout = "site" if layout.nil? # @layout = false is valid
57
- layout
58
- end
59
-
60
- def rescue_from_error(exception)
61
- rescue_template = (exception == ActionView::TemplateError) ? "template_error" : "default_error"
62
- error_template_path = File.expand_path(File.dirname(__FILE__) + "/templates/rescues/#{rescue_template}.html.erb")
63
-
64
- @view.instance_variable_set("@exception", exception)
65
- @view.render_file(error_template_path, false)
66
- end
67
-
68
- # Return the format for a given template path
69
- #
70
- # For example: application.css.sass -> :css
71
- def determine_format_for(filename)
72
- if File.extname(filename).empty? || filename =~ /(\.html|\.haml)/
73
- extension = ".html"
74
- elsif filename =~ /(\.css|\.sass)/
75
- extension = ".css"
76
- else
77
- extension = File.extname(filename)
78
- end
79
-
80
- extension[1,extension.length-1].to_sym
81
- end
82
-
83
- # Load all helpers from src/helpers/
84
- def load_helpers
85
- @site.helpers.each do |helper|
86
- load(helper)
87
- module_name = File.basename(helper, '.rb').gsub(/(^|\_)./) { |c| c.upcase }.gsub(/\_/, '')
88
- ActionView::Base.class_eval("include #{module_name}")
89
- end
90
- end
91
-
92
- # Remove the extension from a given template path
93
- def strip_extension(template)
94
- template.split('.').first
95
- end
96
- end
97
- end
@@ -1,15 +0,0 @@
1
- require 'haml'
2
- require 'haml/engine'
3
-
4
- class StaticMatic::TemplateHandlers::Haml < ActionView::TemplateHandler
5
- include ActionView::TemplateHandlers::Compilable
6
-
7
- def compile(template, local_assigns = {})
8
- options = StaticMatic::Config[:haml_options].dup
9
- options[:filename] = template.filename
10
-
11
- ::Haml::Engine.new(template.source, options).send(:precompiled_with_ambles, [])
12
- end
13
- end
14
-
15
- ActionView::Template.register_template_handler(:haml, StaticMatic::TemplateHandlers::Haml)
@@ -1,9 +0,0 @@
1
- require 'liquid'
2
-
3
- class StaticMatic::TemplateHandlers::Liquid < ActionView::TemplateHandler
4
- def render(template, local_assigns = {})
5
- ::Liquid::Template.parse(template.source).render(local_assigns)
6
- end
7
- end
8
-
9
- ActionView::Template.register_template_handler(:liquid, StaticMatic::TemplateHandlers::Liquid)
@@ -1,9 +0,0 @@
1
- require 'bluecloth'
2
-
3
- class StaticMatic::TemplateHandlers::Markdown < ActionView::TemplateHandler
4
- def render(template, local_assigns = {})
5
- ::BlueCloth::new(template.source).to_html
6
- end
7
- end
8
-
9
- ActionView::Template.register_template_handler(:markdown, StaticMatic::TemplateHandlers::Markdown)
@@ -1,9 +0,0 @@
1
- require 'sass'
2
-
3
- class StaticMatic::TemplateHandlers::Sass < ActionView::TemplateHandler
4
- def render(template)
5
- ::Sass::Engine.new(template.source, StaticMatic::Config[:sass_options]).render
6
- end
7
- end
8
-
9
- ActionView::Template.register_template_handler(:sass, StaticMatic::TemplateHandlers::Sass)
@@ -1,9 +0,0 @@
1
- require 'redcloth'
2
-
3
- class StaticMatic::TemplateHandlers::Textile < ActionView::TemplateHandler
4
- def render(template, local_assigns = {})
5
- ::RedCloth::new(template.source).to_html
6
- end
7
- end
8
-
9
- ActionView::Template.register_template_handler(:textile, StaticMatic::TemplateHandlers::Textile)
@@ -1,2 +0,0 @@
1
- <%= @exception.message %>
2
- <%= debug(@exception.backtrace)%>
@@ -1,19 +0,0 @@
1
- <h1>
2
- <%=h @exception.class.to_s %> in
3
- <% #= #h request.parameters["controller"].capitalize if request.parameters["controller"]%>#<%=h request.parameters["action"] %>
4
- </h1>
5
-
6
- <p>
7
- Showing <i><%=h @exception.file_name %></i> where line <b>#<%=h @exception.line_number %></b> raised:
8
- <pre><code><%=h @exception.message %></code></pre>
9
- </p>
10
-
11
- <p>Extracted source (around line <b>#<%=h @exception.line_number %></b>):
12
- <pre><code><%=h @exception.source_extract %></code></pre></p>
13
-
14
- <p><%=h @exception.sub_template_message %></p>
15
-
16
- <% @real_exception = @exception
17
- @exception = @exception.original_exception || @exception %>
18
-
19
- <% @exception = @real_exception %>
data/lib/staticmatic.rb DELETED
@@ -1,32 +0,0 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) unless
2
- $LOAD_PATH.include?(File.dirname(__FILE__)) ||
3
- $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
4
-
5
- require 'rubygems'
6
- require 'staticmatic/autoload'
7
-
8
- gem 'actionpack', '2.1.2'
9
- require 'active_support'
10
- $LOAD_PATH.unshift Gem.required_location('actionpack', 'action_controller/vendor/html-scanner')
11
- require 'action_view'
12
- require 'staticmatic/actionpack_support/mime'
13
- require 'staticmatic/actionpack_support/remove_partial_benchmark'
14
- require 'staticmatic/actionpack_support/remove_controller_caching'
15
-
16
- # Load generic helpers
17
- ActionView::Base.class_eval do
18
- include StaticMatic::Helpers::AssetTagHelper
19
- include StaticMatic::Helpers::PageHelper
20
- include StaticMatic::Helpers::UrlHelper
21
- include StaticMatic::Deprecation
22
- include Mime
23
- end
24
-
25
- # Load template handlers
26
- Dir[File.dirname(__FILE__) + '/staticmatic/template_handlers/*.rb'].each do |handler|
27
- begin
28
- require "staticmatic/template_handlers/#{File.basename(handler)}"
29
- rescue LoadError
30
- # Could not load gem or handler
31
- end
32
- end
@@ -1,12 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "lib", "staticmatic")
2
-
3
- describe "ActionView Helper Integration" do
4
- before :all do
5
- @sample_site_path = File.dirname(__FILE__) + "/fixtures/sample"
6
- @staticmatic = StaticMatic::Base.new(@sample_site_path)
7
- end
8
-
9
- it "should render partial" do
10
- @staticmatic.render("partial_test").should include("This is a form")
11
- end
12
- end
@@ -1,24 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "lib", "staticmatic")
2
-
3
- describe "Asset Helpers" do
4
- ActionView::Base.included_modules.each do |mod|
5
- include mod if mod.parents.include?(ActionView::Helpers)
6
- end
7
-
8
- include StaticMatic::Helpers::AssetTagHelper
9
- before :all do
10
- @staticmatic = StaticMatic::Base.new(File.dirname(__FILE__) + "/fixtures/sample")
11
- end
12
-
13
- it "should generate stylesheet link" do
14
- @relative_path_to_root = calculate_relative_path_to_root('pages/services/web_development/costs')
15
- stylesheet_link_tag("site").should include("../../stylesheets/site.css")
16
- end
17
-
18
- def calculate_relative_path_to_root(template)
19
- return '' if template.match(/^((\.\.?)?\/|\#|.+?\:)/)
20
-
21
- current_page_depth = template.split('/').length - 2;
22
- (current_page_depth > 0) ? ([ '..' ] * current_page_depth).join('/') + '/' : ''
23
- end
24
- end
data/spec/base_spec.rb DELETED
@@ -1,54 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "lib", "staticmatic")
2
-
3
- describe StaticMatic::Base do
4
- before :all do
5
- @sample_site_path = File.dirname(__FILE__) + "/fixtures/sample"
6
- @staticmatic = StaticMatic::Base.new(@sample_site_path)
7
- end
8
-
9
- it "should list static pages" do
10
- @staticmatic.static_pages.should include("pages/static.html")
11
- end
12
-
13
- # Depending on system gems, markdown/textile files would be listed here too
14
- it "should list dynamic pages" do
15
- ["pages/haml_test.html.haml", "pages/hello_world.html.erb", "pages/index.html.erb",
16
- "pages/no_layout.html.erb", "pages/page_with_error.html.haml", "pages/services/index.html.erb",
17
- "pages/services/web_development.html.erb", "pages/specify_layout.html.erb"].each do |path|
18
- @staticmatic.dynamic_pages.should include(path)
19
- end
20
- end
21
-
22
- it "should list layouts" do
23
- @staticmatic.layouts.should == %w(site.html.erb specified_layout.html.erb)
24
- end
25
-
26
- it "should catch any haml template errors" do
27
- output = @staticmatic.render("page_with_error")
28
- output.should include("Illegal nesting")
29
- end
30
-
31
- it "should still render correctly after a haml error occured" do
32
- output = @staticmatic.render("page_with_error")
33
- @staticmatic.render("hello_world").should include("Hello world!")
34
- end
35
-
36
- it "should load custom helpers" do
37
- @staticmatic.template("haml_test").view.respond_to?(:say).should be_true
38
- end
39
-
40
- it "should determine template directory for file" do
41
- @staticmatic.template("stylesheets/site.css").path.should_not include("pages/")
42
- @staticmatic.template("hello_world.html").path.should include("pages/")
43
- @staticmatic.template("haml_test").path.should include("pages/")
44
- end
45
-
46
- it "should know if we can render a template or not" do
47
- @staticmatic.can_render?("hello_world.html").should_not be_false
48
- @staticmatic.can_render?("stylesheets/site.css").should_not be_false
49
- end
50
-
51
- it "should add index if needed" do
52
- @staticmatic.template("services").path.should == "pages/services/index"
53
- end
54
- end