Class: Dokkit::Environment::Basic

Inherits:
Container
  • Object
show all
Includes:
Helper
Defined in:
lib/dokkit/environment/basic.rb

Instance Method Summary collapse

Methods included from Helper

#configure, #extend_document, #select_data, #select_document

Methods inherited from Container

#[], #method_missing, #register

Constructor Details

#initialize {|_self| ... } ⇒ Basic

Returns a new instance of Basic.

Yields:

  • (_self)

Yield Parameters:



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dokkit/environment/basic.rb', line 29

def initialize(&blk)
  super
  add_lib_to_load_path
  
  init_extmap
  init_services
  
  yield self if block_given?        

  define_tasks
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Dokkit::Environment::Container

Instance Method Details

#add_lib_to_load_pathObject

Add lib folder to the load path.



139
140
141
# File 'lib/dokkit/environment/basic.rb', line 139

def add_lib_to_load_path
  $: << 'lib'
end

#data_factory_blockObject



196
197
198
199
200
# File 'lib/dokkit/environment/basic.rb', line 196

def data_factory_block
  lambda do |source_fn|
    Resource::Data.new(source_fn, configuration.marshal_dump)
  end
end

#default_configurationObject



159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/dokkit/environment/basic.rb', line 159

def default_configuration
  {
    :document_dir => 'doc/pages',
    :config_dir => 'doc/configs',
    :layout_dir => 'doc/layouts',
    :data_dir => 'doc/data',
    :output_dir => 'output',
    :cache_dir => '.cache',
    :default_filter_chain => default_filter_chain,
    :default_postfilter_chain => default_postfilter_chain 
  }                    
end

#default_filter_chainObject



147
148
149
150
151
152
153
# File 'lib/dokkit/environment/basic.rb', line 147

def default_filter_chain
  { 
    'deplate' => { 'html' => ['erb', 'deplate-html'], 'latex' => ['erb', 'deplate-latex'], 'text' => ['erb', 'deplate-text']},
    'maruku' => { 'html' => ['erb', 'maruku-html'], 'latex' => ['erb', 'maruku-latex'] },
    'haml' => { 'html' => ['haml'] },
  }  
end

#default_postfilter_chainObject



155
156
157
# File 'lib/dokkit/environment/basic.rb', line 155

def default_postfilter_chain
  { 'html' => ['erb'], 'latex' => ['erb'], 'text' => ['erb'] }  
end

#define_tasksObject



41
42
43
44
# File 'lib/dokkit/environment/basic.rb', line 41

def define_tasks
  render
  clean
end

#documentObject



172
173
174
175
176
177
178
179
180
181
# File 'lib/dokkit/environment/basic.rb', line 172

def document
  register :document do
    Resource::Document.new(source_fn, configuration.marshal_dump) do |document|
      document.logger = logger
      document.cache = cache
      document.resource_factory = resource_factory
      document.filter_factory = filter_factory
    end          
  end
end

#document_factory_blockObject

Return a block that is able to construct a Document instance.



184
185
186
187
188
189
190
191
192
193
194
# File 'lib/dokkit/environment/basic.rb', line 184

def document_factory_block
  lambda do |source_fn|
    Resource::Document.new(source_fn, configuration.marshal_dump) do |document|
      document.logger = logger
      document.cache = cache
      document.resource_factory = resource_factory
      document.filter_factory = filter_factory
      document.extend @extmap[source_fn] if @extmap[source_fn]
    end
  end
end

#init_extmapObject



143
144
145
# File 'lib/dokkit/environment/basic.rb', line 143

def init_extmap
  @extmap = { }
end

#init_servicesObject



46
47
48
# File 'lib/dokkit/environment/basic.rb', line 46

def init_services
  methods.select { |meth| meth =~ /register_/ }.each { |meth| send(meth) }
end

#register_cacheObject



99
100
101
102
103
# File 'lib/dokkit/environment/basic.rb', line 99

def register_cache
  register :cache do
    Cache.new
  end
end

#register_cleanObject



116
117
118
119
120
121
122
123
124
# File 'lib/dokkit/environment/basic.rb', line 116

def register_clean
  register :clean do
    TaskLib::Clean.new do |task|
      task.logger = logger
      task.output_dir = configuration.output_dir
      task.cache_dir = configuration.cache_dir
    end
  end
end

#register_configurationObject



132
133
134
135
136
# File 'lib/dokkit/environment/basic.rb', line 132

def register_configuration
  register :configuration do
    OpenStruct.new(default_configuration)
  end
end

#register_data_fsObject



59
60
61
62
63
64
65
# File 'lib/dokkit/environment/basic.rb', line 59

def register_data_fs
  register :data_fs do
    Environment::Helper::FileSelection.new(configuration.data_dir) do |fs|
      fs.include('**/*')
    end
  end
end

#register_document_fsObject



50
51
52
53
54
55
56
57
# File 'lib/dokkit/environment/basic.rb', line 50

def register_document_fs
  register :document_fs do
    Environment::Helper::FileSelection.new(configuration.document_dir) do |fs|
      fs.include('**/*')
      fs.exclude('**/*.yaml')
    end
  end
end

#register_extmapObject



67
68
69
70
71
# File 'lib/dokkit/environment/basic.rb', line 67

def register_extmap
  register :extmap do
    Helper::ExtMap.new(configuration.document_dir)
  end
end

#register_filter_factoryObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/dokkit/environment/basic.rb', line 73

def register_filter_factory
  register :filter_factory do
    Dokkit::Factory.new do |factory|
      factory.add('nil') { Dokkit::Filter::Nil.new } 
      factory.add('erb') { |document| Dokkit::Filter::ERB.new(document) }
      factory.add('yaml') { |document| Dokkit::Filter::YAML.new(document) }
      factory.add('tidy') { Dokkit::Filter::Tidy.new }
      factory.add('maruku-html') { Dokkit::Filter::MarukuHTML.new }
      factory.add('deplate-latex') { Dokkit::Filter::DeplateLatex.new }
      factory.add('deplate-html') { Dokkit::Filter::DeplateHTML.new }
      factory.add('deplate-text') { Dokkit::Filter::DeplateText.new }
      factory.add('haml') { |document| Dokkit::Filter::Haml.new(document) }
    end
    
  end
end

#register_loggerObject



126
127
128
129
130
# File 'lib/dokkit/environment/basic.rb', line 126

def register_logger
  register :logger do
    Logging::Observer::Console.logger          
  end
end

#register_renderObject



105
106
107
108
109
110
111
112
113
114
# File 'lib/dokkit/environment/basic.rb', line 105

def register_render
  register :render do
    TaskLib::Render.new do |task|
      task.logger = logger
      task.resource_factory = resource_factory
      task.document_fns = document_fs.files
      task.data_fns = data_fs.files
    end
  end
end

#register_resource_factoryObject



90
91
92
93
94
95
96
97
# File 'lib/dokkit/environment/basic.rb', line 90

def register_resource_factory
  register :resource_factory do
    Factory.new do |factory|
      factory.add(:document, &document_factory_block)
      factory.add(:data, &data_factory_block)
    end        
  end
end