Sha256: 2217d7bf9fec9e704abfad64db6a8794ee973264326707240bd3e28c188f2415
Contents?: true
Size: 1.15 KB
Versions: 3
Compression:
Stored size: 1.15 KB
Contents
require 'sinatra/base' require 'sinatra/reloader' require 'sinatra/flash' require 'sinatra/flash/style_patch' require 'tilt/haml' module GhPreview class Server < Sinatra::Base enable :sessions register Sinatra::Flash configure :development do register Sinatra::Reloader end set :views, GhPreview::Config.views_folder set :public_folder, GhPreview::Config.public_folder set :haml, attr_wrapper: '"' helpers do def render(*args) if args.first.is_a?(Hash) && args.first.keys.include?(:partial) return haml "_#{args.first[:partial]}".to_sym, layout: false else super end end end def initialize(file) super @file = file end get '/' do if file_content(@file) @text = render_file(file_content(@file)) else flash.now[:warning] = "#{@file} doesn't exist !" end haml :index end private def render_file(file) GhPreview::Converter.to_html(file) end def file_content(file) return nil unless File.exist?(file) File.read(file) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
gh-preview-1.0.2 | lib/gh_preview/server.rb |
gh-preview-1.0.1 | lib/gh_preview/server.rb |
gh-preview-1.0.0 | lib/gh_preview/server.rb |