Module: Mail2FrontMatter
- Defined in:
- lib/mail2frontmatter/parser.rb,
lib/mail2frontmatter/writer.rb,
lib/mail2frontmatter/version.rb,
lib/mail2frontmatter/watcher.rb,
lib/mail2frontmatter/preprocessor.rb,
lib/mail2frontmatter/configuration.rb
Overview
Holds configuration and nothing more
Defined Under Namespace
Classes: Parser, PreProcessor, Watcher, Writer
Constant Summary
collapse
- VERSION =
"0.1.0"
Class Method Summary
collapse
Class Method Details
.config ⇒ Object
10
11
12
|
# File 'lib/mail2frontmatter/configuration.rb', line 10
def config
@config
end
|
.logger ⇒ Object
6
7
8
|
# File 'lib/mail2frontmatter/configuration.rb', line 6
def logger
@logger
end
|
.set_config(passed_config = nil, &block) ⇒ Object
14
15
16
17
18
19
20
21
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/mail2frontmatter/configuration.rb', line 14
def set_config(passed_config = nil, &block)
if passed_config.is_a?(String)
@config = YAML.load_file(passed_config).deep_symbolize_keys!
elsif passed_config.is_a?(NilClass)
default_config = File.join(Dir.pwd, 'data', 'mail2frontmatter.yml')
if File.exist?(default_config)
@config = YAML.load_file(default_config).deep_symbolize_keys!
else
raise LoadError, 'no configuration given or found at ./data/mail2frontmatter.yml'
end
elsif passed_config.is_a?(Hash)
@config = passed_config
else
raise ArgumentError, 'not a valid configuration type'
end
if @config[:log_file]
@logger = Logger.new(@config[:log_file])
elsif Dir.exist?(File.join(Dir.pwd, 'log'))
@logger = Logger.new(File.join(Dir.pwd, 'log', 'mail2frontmatter.log'))
else
@logger = Logger.new(STDOUT)
end
unless @config[:data_directory]
@config[:data_directory] = File.join(Dir.pwd, 'source', 'blog')
end
unless @config[:media_directory]
@config[:media_directory] = File.join(Dir.pwd, 'source')
end
yield(@config) if block_given?
preprocessors = @config[:preprocessors] || []
preprocessors.each do |processor|
begin
require "mail2frontmatter/#{processor[:key]}"
rescue LoadError => e
puts "could not require specified preprocessor '#{processor[:key]}.rb', no such file in load path. Check your configuration and try again \n\n"
raise e
end
klass = "Mail2FrontMatter::#{processor[:key].underscore.camelize}".constantize.register(processor[:options] || {})
end
end
|