Class: Dokkit::Resource::Document

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from FilenameHelper

#filename_helper

Methods included from Extension::HTML

#link_to

Methods included from Extension::Url

#relative

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

#cacheObject

Returns the value of attribute cache.



25
26
27
# File 'lib/dokkit/resource/document.rb', line 25

def cache
  @cache
end

#configsObject (readonly)

Returns the value of attribute configs.



28
29
30
# File 'lib/dokkit/resource/document.rb', line 28

def configs
  @configs
end

#configurationObject (readonly)

Returns the value of attribute configuration.



27
28
29
# File 'lib/dokkit/resource/document.rb', line 27

def configuration
  @configuration
end

#depsObject (readonly)

Returns the value of attribute deps.



28
29
30
# File 'lib/dokkit/resource/document.rb', line 28

def deps
  @deps
end

#env_configurationObject (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_factoryObject

Returns the value of attribute filter_factory.



25
26
27
# File 'lib/dokkit/resource/document.rb', line 25

def filter_factory
  @filter_factory
end

#formatObject (readonly)

Returns the value of attribute format.



29
30
31
# File 'lib/dokkit/resource/document.rb', line 29

def format
  @format
end

#formatterObject (readonly)

Returns the value of attribute formatter.



29
30
31
# File 'lib/dokkit/resource/document.rb', line 29

def formatter
  @formatter
end

#layoutsObject (readonly)

Returns the value of attribute layouts.



28
29
30
# File 'lib/dokkit/resource/document.rb', line 28

def layouts
  @layouts
end

#loggerObject

Returns the value of attribute logger.



25
26
27
# File 'lib/dokkit/resource/document.rb', line 25

def logger
  @logger
end

#resource_factoryObject

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_fnObject (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

#targetsObject (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_bindingObject



59
60
61
# File 'lib/dokkit/resource/document.rb', line 59

def get_binding
  binding
end

#has_format?(format) ⇒ Boolean

Returns:

  • (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

Yields:

  • (_self)

Yield Parameters:



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

Returns:

  • (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

#sourceObject

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