Skip to content

Instantly share code, notes, and snippets.

@vic
Last active December 14, 2015 16:59
Show Gist options
  • Select an option

  • Save vic/5119557 to your computer and use it in GitHub Desktop.

Select an option

Save vic/5119557 to your computer and use it in GitHub Desktop.
%title {{title}}
# A renderer that uses Rails asset pipeline and view caching
class PageRenderer
attr_reader :page
def initialize(page)
@page = page
end
def site
page.site
end
def render(options = {})
options[:template] = page.layout if options.blank?
content = view_renderer.render(self, options)
Mustache.render content, self
end
def has_key?(name)
name
end
def [](name)
name
end
def theme
@@theme ||= {}
return @@theme[site.design] if @@theme[site.design]
file = Rails.root.join("themes/#{site.design}/theme.yml")
@@theme[site.design] = Class.new(Settingslogic) { source file }
end
def lookup_context
site = page.site
view_paths = ["themes/#{site.design}/views"]
lookup_context = ActionView::LookupContext.new(view_paths)
lookup_context.skip_default_locale!
lookup_context.locale = site.locale
lookup_context
end
def view_renderer
ActionView::Renderer.new(lookup_context)
end
end
!!! 5
%html
!= render partial: 'head'
%body
.hero-unit
%h1 {{title}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment