Class: SC::Builder::Html

Inherits:
Base show all
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.

Direct Known Subclasses

Test

Constant Summary

Constants included from Helpers::TextHelper

Helpers::TextHelper::AUTO_LINK_RE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::DomIdHelper

#dom_id!

Methods included from Helpers::StaticHelper

#bootstrap, #image_urls_for_client, #inline_javascript, #inline_stylesheet, #javascript_urls_for_client, #javascripts_for_client, #loc, #partial, #sc_resource, #sc_static, #sc_target, #stylesheet_urls_for_client, #stylesheets_for_client, #theme_name, #title

Methods included from Helpers::CaptureHelper

#capture, #content_for

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, #read, #readlines, #replace_static_url, #sc_static_match, #static_url, #writeline, #writelinebinary, #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.expand_required_targets.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

#bundleObject (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

#entriesObject (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

#entryObject (readonly)

the entry we are building



24
25
26
# File 'lib/sproutcore/builders/html.rb', line 24

def entry
  @entry
end

#filenameObject (readonly)

the final filename



33
34
35
# File 'lib/sproutcore/builders/html.rb', line 33

def filename
  @filename
end

#languageObject (readonly)

the current builder language



36
37
38
# File 'lib/sproutcore/builders/html.rb', line 36

def language
  @language
end

#libraryObject (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

#manifestObject (readonly)

manifest owning the current entry



45
46
47
# File 'lib/sproutcore/builders/html.rb', line 45

def manifest
  @manifest
end

#projectObject (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

#rendererObject (readonly)

the current render



42
43
44
# File 'lib/sproutcore/builders/html.rb', line 42

def renderer
  @renderer
end

#targetObject (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



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/sproutcore/builders/html.rb', line 114

def build(dst_path)
  # WE ARE DISABLING HTML5 MANIFEST FOR NOW. Because it doesn't work.
  if false and CONFIG[:html5_manifest]
    $to_html5_manifest << dst_path
    $to_html5_manifest_networks = CONFIG[:html5_manifest_networks]
    @content_for_html5_manifest = true
  end

  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


141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/sproutcore/builders/html.rb', line 141

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), input_path )
  end

  @render = old_renderer
  return self
end

#configObject



50
# File 'lib/sproutcore/builders/html.rb', line 50

def config; target.config; end

#default_content_for_keyObject



126
# File 'lib/sproutcore/builders/html.rb', line 126

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 expand_required_targets(target, opts = {})
  opts[:debug] = target.config[:load_debug]
  opts[:theme] = true
  return target.expand_required_targets(opts)
end

#layout_entryObject

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_pathObject

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

#renderObject

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
112
# 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_nameObject Also known as: bundle_name



47
# File 'lib/sproutcore/builders/html.rb', line 47

def target_name; target[:target_name].to_s.sub(/^\//,''); end