Class: Magneto::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/magneto/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

Returns a new instance of Application.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/magneto/application.rb', line 7

def initialize
  super
  @options = {}
  @config_path = 'config.yaml'
  @config = {
    :source_path        => '.',
    :output_path        => 'output',
    :hidden_files       => false,
    :remove_obsolete    => false,
    :auto_regeneration  => false
  }
  @filters = {}
  @site = nil
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/magneto/application.rb', line 5

def config
  @config
end

#filtersObject (readonly)

Returns the value of attribute filters.



5
6
7
# File 'lib/magneto/application.rb', line 5

def filters
  @filters
end

#siteObject (readonly)

Returns the value of attribute site.



5
6
7
# File 'lib/magneto/application.rb', line 5

def site
  @site
end

Instance Method Details

#runObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/magneto/application.rb', line 22

def run
  parse_options
  load_configuration

  @config.deep_merge! @options

  [:source_path, :output_path].each do |path|
    @config[path] = File.expand_path(@config[path])
    @config[path].freeze
  end

  load_plugins
  find_filters

  @site = Site.new(@config, @filters)

  if @config[:auto_regeneration]
    puts 'Automatic regeneration enabled.'

    require 'directory_watcher'

    dw = DirectoryWatcher.new(@config[:source_path])
    dw.glob = [@config[:hidden_files] ? 'items/**/{.[^.],}*' : 'items/**/*', 'templates/*.*', 'script.rb']
    dw.interval = 1
    dw.add_observer { |*args| @site.generate }
    dw.start
    gets
    dw.stop
  else
    @site.generate
  end

  exit
end