Class: Black::Preview
- Inherits:
-
Object
- Object
- Black::Preview
- Defined in:
- lib/black/preview.rb
Overview
rack compatable preview generator Usage: Create a new rack application in config.ru:
require 'rack'
require 'black'
diff = Black::Diff.new('older string', 'newer string', 'file-name.html')
content = Black::HTMLView.render(diff: diff)
run Black::Preview.new(content)
Then run the rack app: $ rackup config.ru
Defined Under Namespace
Classes: Context
Constant Summary collapse
- Template =
<<-TEXT <!doctype html> <html> <head> <style> html, body { margin: 0; padding: 0; } <%= css %> </style> </head> <body> <%= content %> </body> </html> TEXT
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(content, css = nil) ⇒ Preview
constructor
A new instance of Preview.
Constructor Details
#initialize(content, css = nil) ⇒ Preview
Returns a new instance of Preview.
32 33 34 35 |
# File 'lib/black/preview.rb', line 32 def initialize(content, css=nil) @css = css @content = content end |
Instance Method Details
#call(env) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/black/preview.rb', line 37 def call(env) @css ||= Black::Stylesheets.css({ style: :compressed }) context = Context.new(@content, @css) output = ::ERB.new(Template).result(context.get_binding) [200, {'Content-Type' => 'text/html'}, [output]] end |