Class: Dokkit::Resource::Document
- Inherits:
-
Object
- Object
- Dokkit::Resource::Document
- Includes:
- Extension::Builtin, FilenameHelper
- Defined in:
- lib/dokkit/resource/document.rb
Overview
Document is the core resource class of dokkit. Document instances are usually created on demand by Dokkit::Resource::Factory.
Instance Attribute Summary collapse
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#configs ⇒ Object
readonly
Returns the value of attribute configs.
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#deps ⇒ Object
readonly
Returns the value of attribute deps.
-
#env_configuration ⇒ Object
readonly
Returns the value of attribute env_configuration.
-
#filter_factory ⇒ Object
Returns the value of attribute filter_factory.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#layouts ⇒ Object
readonly
Returns the value of attribute layouts.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#resource_factory ⇒ Object
Returns the value of attribute resource_factory.
-
#source_fn ⇒ Object
readonly
Returns the value of attribute source_fn.
-
#targets ⇒ Object
readonly
Returns the value of attribute targets.
Instance Method Summary collapse
- #config(config_fn) ⇒ Object
- #deps_for(format) ⇒ Object
-
#filters_for(format, formatter = @formatter) ⇒ Object
Return the filters chain associated with the given formatter and output format.
- #get_binding ⇒ Object
- #has_format?(format) ⇒ Boolean
-
#initialize(source_fn, env_configuration, &blk) ⇒ Document
constructor
Initialize a Document instance.
- #layout(layout_fn) ⇒ Object
-
#post_filters_for(format) ⇒ Object
Return the post filters chain associated with the given format.
- #reconfigure(configuration = { }) {|_self| ... } ⇒ Object
-
#render(args = { }) ⇒ Object
Render the document in the specified format.
- #render? ⇒ Boolean
-
#source ⇒ Object
Return the content of the source document file.
- #target_for(format) ⇒ Object
Methods included from FilenameHelper
Methods included from Extension::HTML
Methods included from Extension::Url
Constructor Details
#initialize(source_fn, env_configuration, &blk) ⇒ Document
Initialize a Document instance.
source_fn
-
is the file name of the document source file.
configuration
-
is the configuration hash to be associated with the document.
logger
-
is the logger instance.
cache
-
is the cache manager instance.
36 37 38 39 40 41 |
# File 'lib/dokkit/resource/document.rb', line 36 def initialize(source_fn, env_configuration, &blk) @source_fn = source_fn @env_configuration = env_configuration reconfigure(&blk) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth) ⇒ Object (private)
116 117 118 119 120 121 122 123 |
# File 'lib/dokkit/resource/document.rb', line 116 def method_missing(meth) if @configuration.has_key?(meth.to_s) @configuration[meth.to_s] else @logger.warn("Configuration key '#{meth.to_s}' is not defined for #{source_fn}.") @default_configuration_value end end |
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
25 26 27 |
# File 'lib/dokkit/resource/document.rb', line 25 def cache @cache end |
#configs ⇒ Object (readonly)
Returns the value of attribute configs.
28 29 30 |
# File 'lib/dokkit/resource/document.rb', line 28 def configs @configs end |
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
27 28 29 |
# File 'lib/dokkit/resource/document.rb', line 27 def configuration @configuration end |
#deps ⇒ Object (readonly)
Returns the value of attribute deps.
28 29 30 |
# File 'lib/dokkit/resource/document.rb', line 28 def deps @deps end |
#env_configuration ⇒ Object (readonly)
Returns the value of attribute env_configuration.
27 28 29 |
# File 'lib/dokkit/resource/document.rb', line 27 def env_configuration @env_configuration end |
#filter_factory ⇒ Object
Returns the value of attribute filter_factory.
25 26 27 |
# File 'lib/dokkit/resource/document.rb', line 25 def filter_factory @filter_factory end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
29 30 31 |
# File 'lib/dokkit/resource/document.rb', line 29 def format @format end |
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
29 30 31 |
# File 'lib/dokkit/resource/document.rb', line 29 def formatter @formatter end |
#layouts ⇒ Object (readonly)
Returns the value of attribute layouts.
28 29 30 |
# File 'lib/dokkit/resource/document.rb', line 28 def layouts @layouts end |
#logger ⇒ Object
Returns the value of attribute logger.
25 26 27 |
# File 'lib/dokkit/resource/document.rb', line 25 def logger @logger end |
#resource_factory ⇒ Object
Returns the value of attribute resource_factory.
25 26 27 |
# File 'lib/dokkit/resource/document.rb', line 25 def resource_factory @resource_factory end |
#source_fn ⇒ Object (readonly)
Returns the value of attribute source_fn.
27 28 29 |
# File 'lib/dokkit/resource/document.rb', line 27 def source_fn @source_fn end |
#targets ⇒ Object (readonly)
Returns the value of attribute targets.
28 29 30 |
# File 'lib/dokkit/resource/document.rb', line 28 def targets @targets end |
Instance Method Details
#config(config_fn) ⇒ Object
43 44 45 |
# File 'lib/dokkit/resource/document.rb', line 43 def config(config_fn) reconfigure('config' => config_fn) end |
#deps_for(format) ⇒ Object
81 82 83 |
# File 'lib/dokkit/resource/document.rb', line 81 def deps_for(format) @deps[format] end |
#filters_for(format, formatter = @formatter) ⇒ Object
Return the filters chain associated with the given formatter and output format.
68 69 70 |
# File 'lib/dokkit/resource/document.rb', line 68 def filters_for(format, formatter = @formatter) process_filter_key('filter', format) || default_filter_chain_for(formatter, format) end |
#get_binding ⇒ Object
59 60 61 |
# File 'lib/dokkit/resource/document.rb', line 59 def get_binding binding end |
#has_format?(format) ⇒ Boolean
63 64 65 |
# File 'lib/dokkit/resource/document.rb', line 63 def has_format?(format) @targets.has_key?(format) end |
#layout(layout_fn) ⇒ Object
47 48 49 |
# File 'lib/dokkit/resource/document.rb', line 47 def layout(layout_fn) reconfigure('layout' => layout_fn) end |
#post_filters_for(format) ⇒ Object
Return the post filters chain associated with the given format.
73 74 75 |
# File 'lib/dokkit/resource/document.rb', line 73 def post_filters_for(format) process_filter_key('postfilter', format) || default_postfilter_chain_for(format) end |
#reconfigure(configuration = { }) {|_self| ... } ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/dokkit/resource/document.rb', line 51 def reconfigure(configuration = { }, &blk) init_default(configuration) yield self if block_given? configure end |
#render(args = { }) ⇒ Object
Render the document in the specified format.
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/dokkit/resource/document.rb', line 97 def render(args = { }) if args[:format].nil? unless @current_format args = { :format => @default_format }.merge args @current_format = args[:format] end else @current_format = args[:format] end args.has_key?(:partial) ? render_partial(args[:partial], @current_format) : do_render!(@formatter, @current_format) end |
#render? ⇒ Boolean
89 90 91 92 93 94 |
# File 'lib/dokkit/resource/document.rb', line 89 def render? if @configuration.has_key?('render') return false unless @configuration['render'] end true end |
#source ⇒ Object
Return the content of the source document file.
110 111 112 |
# File 'lib/dokkit/resource/document.rb', line 110 def source @source ||= read_source end |
#target_for(format) ⇒ Object
77 78 79 |
# File 'lib/dokkit/resource/document.rb', line 77 def target_for(format) @targets[format][:target_fn] end |