Class: Weaver::Weave

Inherits:
Object
  • Object
show all
Defined in:
lib/weaver/weave.rb

Overview

Handles .weave file

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}) ⇒ Weave

Returns a new instance of Weave.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/weaver/weave.rb', line 7

def initialize(file, options = {})
  @pages = {}
  @file = file
  @global_settings = options

  @global_settings[:root] = @global_settings[:root] || '/'
  unless @global_settings[:root].end_with? '/'
    @global_settings[:root] = "#{@global_settings[:root]}/"
  end
  instance_eval(File.read(file), file)
end

Instance Attribute Details

#pagesObject

Returns the value of attribute pages.



6
7
8
# File 'lib/weaver/weave.rb', line 6

def pages
  @pages
end

Class Method Details

.register_page_type(symbol, class_constant) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/weaver/weave.rb', line 31

def register_page_type(symbol, class_constant)
  define_method symbol,
                (proc do |path = '', title = nil, options = {}, &block|
                  if title.nil?
                    title = path
                    path = ''
                  end

                  p = class_constant.new(title, @global_settings, options,
                                         &block)
                  @pages[path] = p
                end)
end

Instance Method Details

#include(file) ⇒ Object



23
24
25
26
27
28
# File 'lib/weaver/weave.rb', line 23

def include(file)
  dir = File.dirname(@file)
  filename = File.join([dir, file])
  File.read(filename)
  load filename
end

#set_global(key, value) ⇒ Object



19
20
21
# File 'lib/weaver/weave.rb', line 19

def set_global(key, value)
  @global_settings[key] = value
end