Sha256: bfa98b53f7b47edc1935e439cd6eb4111b8d52ce2433636f16bc5ee7ce8dee44
Contents?: true
Size: 1.36 KB
Versions: 4
Compression:
Stored size: 1.36 KB
Contents
require 'erb' require 'rubrowser/data' require 'rubrowser/formatter/json' module Rubrowser class Renderer # Accepted options are: # files: list of file paths to parse # toolbox: bool, show/hide toolbox def self.call(options = {}) new(options).call end def call if @json output.write(data) else output.write(erb(:index)) end end private include ERB::Util attr_reader :files, :output, :server def initialize(options) @output = output_file(options[:output]) @layout = options[:layout] @server = options[:server] @files = options[:files] @toolbox = options[:toolbox] @json = !!options[:json] end def output_file(path) path.is_a?(String) ? File.open(path, 'w') : path end def layout return 'null' unless @layout File.read(@layout) end def toolbox? @toolbox end def data data = Data.new(files) formatter = Formatter::JSON.new(data) formatter.call end def file(path) File.read(resolve_file_path("/public/#{path}")) end def erb(template) path = resolve_file_path("/views/#{template}.erb") file = File.open(path).read ERB.new(file).result binding end def resolve_file_path(path) File.expand_path("../../..#{path}", __FILE__) end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
rubrowser-2.10 | lib/rubrowser/renderer.rb |
rubrowser-2.9.1 | lib/rubrowser/renderer.rb |
rubrowser-2.9.0 | lib/rubrowser/renderer.rb |
rubrowser-2.8.0 | lib/rubrowser/renderer.rb |