Module: Brief::Document::Rendering
- Extended by:
- ActiveSupport::Concern
- Included in:
- Brief::Document
- Defined in:
- lib/brief/document/rendering.rb
Defined Under Namespace
Modules: ClassMethods
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
43 44 45 46 47 48 49 |
# File 'lib/brief/document/rendering.rb', line 43 def script_contents(={}) " <script type=\"text/javascript\">\n Brief.documents['\#{ self.relative_path }'] = \#{ to_model.as_json(options).to_json };\n </script>\n EOF\nend\n" |
#script_preamble ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/brief/document/rendering.rb', line 31 def script_preamble " <script type=\"text/javascript\">\n if(typeof(global)===\"undefined\"){\n global = window\n }\n global.Brief = global.Brief || {}\n Brief.documents = Brief.documents || {}\n </script>\n EOF\nend\n" |
#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.
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/brief/document/rendering.rb', line 57 def to_html( = {}) html = if [:wrap] == false unwrapped_html else wrapper = .fetch(:wrapper, 'div') "#{script_preamble if options[:script] && !options[:skip_preamble]}<#{ wrapper } data-brief-model='#{ model_class.type_alias }' data-brief-path='#{ relative_path }'>#{ unwrapped_html }</#{wrapper}>#{ script_contents(options) if options[:script]}" end html.respond_to?(:html_safe) ? html.html_safe : html.to_s end |
#unwrapped_html ⇒ Object
68 69 70 71 72 73 |
# File 'lib/brief/document/rendering.rb', line 68 def unwrapped_html # remove annoying linebreaks from paragraphs parser.css("p br").remove() unless Brief.configuration.preserve_gfm_line_breaks parser.to_html end |