Class: Alephant::Preview::Server

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/alephant/preview/server.rb

Constant Summary collapse

BASE_LOCATION =
"#{(ENV['BASE_LOCATION'] || Dir.pwd)}/components".freeze

Instance Method Summary collapse

Instance Method Details

#find_id_from_template(template) ⇒ Object



85
86
87
88
89
90
91
92
93
# File 'lib/alephant/preview/server.rb', line 85

def find_id_from_template(template)
  files = Dir.glob(BASE_LOCATION + "/**/models/*")
  file = files.select! { |file| file.include? "/#{template}.rb" }.pop

  halt(404) if file.nil?

  result = /#{BASE_LOCATION}\/(\w+)/.match(file)
  result[1]
end

#render_batch_componentObject



106
107
108
109
110
111
112
113
# File 'lib/alephant/preview/server.rb', line 106

def render_batch_component
  {
    :component => template,
    :options   => {},
    :status    => 200,
    :body      => render_component
  }
end

#render_componentObject



102
103
104
# File 'lib/alephant/preview/server.rb', line 102

def render_component
  view_mapper.generate(fixture_data)[template].render
end

#render_previewObject



95
96
97
98
99
100
# File 'lib/alephant/preview/server.rb', line 95

def render_preview
  Template::Base.new(
    { region => render_component },
    preview_template_location
  ).render
end