Module: Brief::Document::Rendering
- Extended by:
- ActiveSupport::Concern
- Included in:
- Brief::Document
- Defined in:
- lib/brief/document/rendering.rb
Instance Method Summary collapse
- #script_contents(options = {}) ⇒ Object
- #script_preamble ⇒ Object
-
#to_html(options = {}) ⇒ Object
Documents can be rendered into HTML.
- #unwrapped_html ⇒ Object
Instance Method Details
#script_contents(options = {}) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/brief/document/rendering.rb', line 30 def script_contents(={}) <<-EOF <script type="text/javascript"> Brief.documents['#{ self.relative_path }'] = #{ to_model.as_json().to_json }; </script> EOF end |
#script_preamble ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/brief/document/rendering.rb', line 18 def script_preamble <<-EOF <script type="text/javascript"> if(typeof(global)==="undefined"){ global = window } global.Brief = global.Brief || {} Brief.documents = Brief.documents || {} </script> EOF end |
#to_html(options = {}) ⇒ Object
Documents can be rendered into HTML.
They will first be put through a Nokogiri processor pipeline which allows us to wrap things in section containers, apply data attributes, and other things to the HTML so that the output HTML retains its relationship to the underlying data and document structure.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/brief/document/rendering.rb', line 44 def to_html( = {}) html = if [:wrap] == false unwrapped_html else wrapper = .fetch(:wrapper, 'div') "#{script_preamble if [:script] && ![:skip_preamble]}<#{ wrapper } data-brief-model='#{ model_class.type_alias }' data-brief-path='#{ relative_path }'>#{ unwrapped_html }</#{wrapper}>#{ script_contents() if [:script]}" end html.respond_to?(:html_safe) ? html.html_safe : html.to_s end |
#unwrapped_html ⇒ Object
55 56 57 |
# File 'lib/brief/document/rendering.rb', line 55 def unwrapped_html parser.to_html end |