Class: SC::Builder::Html
- Includes:
- Helpers::CaptureHelper, Helpers::DomIdHelper, Helpers::StaticHelper, Helpers::TagHelper, Helpers::TextHelper, ViewHelpers
- Defined in:
- lib/sproutcore/builders/html.rb
Overview
Builds an HTML files. This will setup an HtmlContext and then invokes the render engines for each source before finally rendering the layout.
Constant Summary
Constants included from Helpers::TextHelper
Helpers::TextHelper::AUTO_LINK_RE
Instance Attribute Summary collapse
-
#bundle ⇒ Object
readonly
bundle is an alias for target included for backwards compatibility.
-
#entries ⇒ Object
readonly
the full set of entries we plan to build.
-
#entry ⇒ Object
readonly
the entry we are building.
-
#filename ⇒ Object
readonly
the final filename.
-
#language ⇒ Object
readonly
the current builder language.
-
#library ⇒ Object
readonly
library is an alias for project for backwards compatibility.
-
#manifest ⇒ Object
readonly
manifest owning the current entry.
-
#project ⇒ Object
readonly
library is an alias for project for backwards compatibility.
-
#renderer ⇒ Object
readonly
the current render.
-
#target ⇒ Object
readonly
bundle is an alias for target included for backwards compatibility.
Instance Method Summary collapse
- #build(dst_path) ⇒ Object
-
#compile(render_engine, input_path, content_for_key = nil) ⇒ Object
Loads the passed input file and then hands it to the render_engine instance to compile th file.
- #config ⇒ Object
- #default_content_for_key ⇒ Object
-
#expand_required_targets(target, opts = {}) ⇒ Object
Returns the expanded list of required targets for the passed target.
-
#initialize(entry) ⇒ Html
constructor
A new instance of Html.
-
#layout_entry ⇒ Object
The entry for the layout we want to build.
-
#layout_path ⇒ Object
the path to the current layout for the resource.
-
#render ⇒ Object
Renders the html file, returning the resulting string which can be written to a file.
- #target_name ⇒ Object (also: #bundle_name)
Methods included from Helpers::DomIdHelper
Methods included from Helpers::StaticHelper
#javascripts_for_client, #loc, #partial, #sc_resource, #sc_static, #sc_target, #stylesheets_for_client, #theme_name, #title
Methods included from Helpers::CaptureHelper
Methods included from Helpers::TextHelper
#auto_link, #concat, #cycle, #highlight, #pluralize, #reset_cycle, #simple_format, #strip_links
Methods included from Helpers::TagHelper
#cdata_section, #content_tag, #escape_once, #link_to, #tag
Methods inherited from Base
build, #joinlines, #readlines, #replace_static_url, #static_url, #writelines
Constructor Details
#initialize(entry) ⇒ Html
Returns a new instance of Html.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/sproutcore/builders/html.rb', line 65 def initialize(entry) super(entry) @target = @bundle = entry.manifest.target @filename = entry.filename @language = @entry.manifest.language @project = @library = @target.project @manifest = entry.manifest @renderer = nil # set the current layout from the target's config.layout @layout = @target.config.layout || 'lib/index.rhtml' # find all entries -- use source_Entries + required if needed @entries = entry.source_entries.dup if entry.include_required_targets? @target..each do |target| cur_manifest = target.manifest_for(@manifest.variation).build! cur_entry = cur_manifest.entry_for(entry.filename, :combined => true) || cur_manifest.entry_for(entry.filename, :hidden => true, :combined => true) next if cur_entry.nil? @entries += cur_entry.source_entries end end end |
Instance Attribute Details
#bundle ⇒ Object (readonly)
bundle is an alias for target included for backwards compatibility
27 28 29 |
# File 'lib/sproutcore/builders/html.rb', line 27 def bundle @bundle end |
#entries ⇒ Object (readonly)
the full set of entries we plan to build
30 31 32 |
# File 'lib/sproutcore/builders/html.rb', line 30 def entries @entries end |
#entry ⇒ Object (readonly)
the entry we are building
24 25 26 |
# File 'lib/sproutcore/builders/html.rb', line 24 def entry @entry end |
#filename ⇒ Object (readonly)
the final filename
33 34 35 |
# File 'lib/sproutcore/builders/html.rb', line 33 def filename @filename end |
#language ⇒ Object (readonly)
the current builder language
36 37 38 |
# File 'lib/sproutcore/builders/html.rb', line 36 def language @language end |
#library ⇒ Object (readonly)
library is an alias for project for backwards compatibility
39 40 41 |
# File 'lib/sproutcore/builders/html.rb', line 39 def library @library end |
#manifest ⇒ Object (readonly)
manifest owning the current entry
45 46 47 |
# File 'lib/sproutcore/builders/html.rb', line 45 def manifest @manifest end |
#project ⇒ Object (readonly)
library is an alias for project for backwards compatibility
39 40 41 |
# File 'lib/sproutcore/builders/html.rb', line 39 def project @project end |
#renderer ⇒ Object (readonly)
the current render
42 43 44 |
# File 'lib/sproutcore/builders/html.rb', line 42 def renderer @renderer end |
#target ⇒ Object (readonly)
bundle is an alias for target included for backwards compatibility
27 28 29 |
# File 'lib/sproutcore/builders/html.rb', line 27 def target @target end |
Instance Method Details
#build(dst_path) ⇒ Object
113 114 115 |
# File 'lib/sproutcore/builders/html.rb', line 113 def build(dst_path) writelines dst_path, [self.render] end |
#compile(render_engine, input_path, content_for_key = nil) ⇒ Object
Loads the passed input file and then hands it to the render_engine instance to compile th file. the results will be targeted at the content_for_key or otherwise override in your template.
Params
render_engine:: A render engine instance
input_path:: The file to load
content_for_key:: optional target for content
Returns
self
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/sproutcore/builders/html.rb', line 132 def compile(render_engine, input_path, content_for_key = nil) if content_for_key.nil? if @in_partial content_for_key = :_partial_ else content_for_key = self.default_content_for_key end end if !File.exist?(input_path) raise "html_builder could compile file at #{input_path} because the file could not be found" end old_renderer = @renderer @renderer = render_engine # save for capture... input = File.read(input_path) content_for content_for_key do _render_compiled_template( render_engine.compile(input) ) end @render = old_renderer return self end |
#config ⇒ Object
50 |
# File 'lib/sproutcore/builders/html.rb', line 50 def config; target.config; end |
#default_content_for_key ⇒ Object
117 |
# File 'lib/sproutcore/builders/html.rb', line 117 def default_content_for_key; :resources; end |
#expand_required_targets(target, opts = {}) ⇒ Object
Returns the expanded list of required targets for the passed target. This method can be overridden by subclasses to provide specific config settings.
92 93 94 95 96 |
# File 'lib/sproutcore/builders/html.rb', line 92 def (target, opts = {}) opts[:debug] = target.config.load_debug opts[:theme] = true return target.(opts) end |
#layout_entry ⇒ Object
The entry for the layout we want to build. this will be used to stage the layout if needed..
54 55 56 |
# File 'lib/sproutcore/builders/html.rb', line 54 def layout_entry @manifest.entry_for(@layout) || @manifest.entry_for(@layout, :hidden => true) end |
#layout_path ⇒ Object
the path to the current layout for the resource. this is computed from the layout property, which is a relative pathname.
60 61 62 63 |
# File 'lib/sproutcore/builders/html.rb', line 60 def layout_path entry = layout_entry entry.nil? ? nil : entry.staging_path end |
#render ⇒ Object
Renders the html file, returning the resulting string which can be written to a file.
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/sproutcore/builders/html.rb', line 100 def render # render each entry... @entries.each { |entry| render_entry(entry) } # then finally compile the layout. if self.layout_path.nil? raise "html_builder could not find a layout file for #{@layout}" end compile(SC::RenderEngine::Erubis.new(self), self.layout_path, :_final_) return @content_for__final_ end |
#target_name ⇒ Object Also known as: bundle_name
47 |
# File 'lib/sproutcore/builders/html.rb', line 47 def target_name; target.target_name.to_s.sub(/^\//,''); end |