class Dugway::Liquifier

Public Class Methods

new(request) click to toggle source
# File lib/dugway/liquifier.rb, line 16
def initialize(request)
  @request = request
end
render_styles(css) click to toggle source
# File lib/dugway/liquifier.rb, line 40
def self.render_styles(css)
  Liquid::Template.parse(css).render!(
    { 'theme' => Drops::ThemeDrop.new(Dugway.theme.customization) },
    :registers => { :settings => Dugway.theme.settings }
  )
end

Public Instance Methods

render(content, variables={}) click to toggle source
# File lib/dugway/liquifier.rb, line 20
def render(content, variables={})
  variables.symbolize_keys!

  assigns = shared_assigns
  assigns['page_content'] = variables[:page_content]
  assigns['page'] = Drops::PageDrop.new(variables[:page])
  assigns['product'] = Drops::ProductDrop.new(variables[:product])

  registers = shared_registers
  registers[:category] = variables[:category]
  registers[:artist] = variables[:artist]

  if errors = variables.delete(:errors)
    shared_context['errors'] << errors
  end

  context = Liquid::Context.new([ assigns, shared_context ], {}, registers)
  Liquid::Template.parse(content).render!(context)
end

Private Instance Methods

bigcartel_credit() click to toggle source
# File lib/dugway/liquifier.rb, line 100
def bigcartel_credit
  '<a href="http://bigcartel.com/" title="Start your own store at Big Cartel now">Online Store by Big Cartel</a>'
end
cart() click to toggle source
# File lib/dugway/liquifier.rb, line 57
def cart
  Dugway.cart
end
head_content() click to toggle source
# File lib/dugway/liquifier.rb, line 90
def head_content
  content = %{<meta name="generator" content="Big Cartel">}

  if google_font_url = ThemeFont.google_font_url_for_theme(Dugway.theme.fonts, Dugway.theme.customization)
    content << %{\n<link rel="stylesheet" type="text/css" href="#{ google_font_url }">}
  end

  content
end
shared_assigns() click to toggle source
# File lib/dugway/liquifier.rb, line 65
def shared_assigns
  {
    'store' => Drops::AccountDrop.new(store.account),
    'cart' => Drops::CartDrop.new(cart),
    'theme' => Drops::ThemeDrop.new(theme.customization),
    'pages' => Drops::PagesDrop.new(store.pages.map { |p| Drops::PageDrop.new(p) }),
    'categories' => Drops::CategoriesDrop.new(store.categories.map { |c| Drops::CategoryDrop.new(c) }),
    'artists' => Drops::ArtistsDrop.new(store.artists.map { |a| Drops::ArtistDrop.new(a) }),
    'products' => Drops::ProductsDrop.new(store.products.map { |p| Drops::ProductDrop.new(p) }),
    'contact' => Drops::ContactDrop.new,
    'head_content' => head_content,
    'bigcartel_credit' => bigcartel_credit
  }
end
shared_context() click to toggle source
# File lib/dugway/liquifier.rb, line 61
def shared_context
  @shared_context ||= { 'errors' => [] }
end
shared_registers() click to toggle source
# File lib/dugway/liquifier.rb, line 80
def shared_registers
  {
    :request => @request,
    :path => @request.path,
    :params => @request.params.with_indifferent_access,
    :currency => store.currency,
    :settings => theme.settings
  }
end
store() click to toggle source
# File lib/dugway/liquifier.rb, line 49
def store
  Dugway.store
end
theme() click to toggle source
# File lib/dugway/liquifier.rb, line 53
def theme
  Dugway.theme
end