Class: Alephant::Preview::Server
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Alephant::Preview::Server
- Defined in:
- lib/alephant/preview/server.rb
Constant Summary collapse
- BASE_LOCATION =
"#{(ENV['BASE_LOCATION'] || Dir.pwd)}/components".freeze
Instance Method Summary collapse
- #find_id_from_template(template) ⇒ Object
- #render_batch_component ⇒ Object
- #render_component ⇒ Object
- #render_preview ⇒ Object
Instance Method Details
#find_id_from_template(template) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/alephant/preview/server.rb', line 92 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_component ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/alephant/preview/server.rb', line 115 def render_batch_component content = render_component { :component => template, :options => {}, :status => 200, :body => content, :content_type => get_content_type(content), :sequence_id => sequence_id } end |
#render_component ⇒ Object
109 110 111 112 113 |
# File 'lib/alephant/preview/server.rb', line 109 def render_component view_mapper.generate(fixture_data)[template].render.tap do |content| response["Content-Type"] = get_content_type(content) end end |