Sha256: af941aba1c65b8b60a43315465399783ad8763d18a7eff8394cce569a3f94783
Contents?: true
Size: 1.69 KB
Versions: 2
Compression:
Stored size: 1.69 KB
Contents
require 'puppet-herald' require 'puppet-herald/javascript' require 'sinatra/base' require 'sinatra/namespace' # A module for Herald module PuppetHerald # A module that holds module of app module App # Frontend logic impl internal class class LogicImpl def initialize @js = PuppetHerald::Javascript.new end # Gets an app.html # @dodgy executed also to raise an exception for testing (application_spec) def app_html if PuppetHerald.in_prod? minified = '.min' files = ['/app.min.js'] else minified = '' files = @js.files end [minified, files] end # Uglify an application JS's into one minified JS file # @param mapname [String] name of source map to be put into uglified JS # @return [Hash] a hash with uglified JS and source map def uglify(mapname) @js.uglify mapname end end # Class that holds implementation of frontent interface class Frontend < Sinatra::Base use PuppetHerald::App::Configuration set :logic, PuppetHerald::App::LogicImpl.new get '/' do cache_control :public, :must_revalidate, max_age: 60 if PuppetHerald.in_prod? @minified, @files = settings.logic.app_html erb :app end get '/index.html' do redirect '/', 301 end get '/app.html' do redirect '/', 301 end get %r{^/app\.min\.(js\.map|js)$} do |ext| content_type 'application/javascript' contents = settings.logic.uglify('/app.min.js.map')[ext] cache_control :public, :must_revalidate, max_age: 60 if PuppetHerald.in_prod? contents end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
puppet-herald-0.8.1 | lib/puppet-herald/app/frontend.rb |
puppet-herald-0.8.0 | lib/puppet-herald/app/frontend.rb |