sitefuel 0.0.0b → 0.1.0a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. data/README.rdoc +81 -0
  2. data/{RELEASE_NOTES → RELEASE_NOTES.rdoc} +0 -0
  3. data/bin/sitefuel +64 -111
  4. data/lib/sitefuel/CommandLine.rb +142 -0
  5. data/lib/sitefuel/Configuration.rb +49 -13
  6. data/lib/sitefuel/License.rb +292 -0
  7. data/lib/sitefuel/SiteFuelLogger.rb +34 -5
  8. data/lib/sitefuel/SiteFuelRuntime.rb +217 -44
  9. data/lib/sitefuel/extensions/ArrayComparisons.rb +2 -2
  10. data/lib/sitefuel/extensions/ColumnPrinter.rb +276 -0
  11. data/lib/sitefuel/extensions/DynamicClassMethods.rb +2 -2
  12. data/lib/sitefuel/extensions/FileComparison.rb +2 -2
  13. data/lib/sitefuel/extensions/FileTree.rb +94 -0
  14. data/lib/sitefuel/extensions/Silently.rb +2 -2
  15. data/lib/sitefuel/extensions/StringFormatting.rb +52 -8
  16. data/lib/sitefuel/extensions/SymbolComparison.rb +4 -2
  17. data/lib/sitefuel/extensions/TerminalInfo.rb +53 -0
  18. data/lib/sitefuel/external/AbstractExternalProgram.rb +65 -11
  19. data/lib/sitefuel/external/ExternalProgramTestCase.rb +2 -2
  20. data/lib/sitefuel/external/GIT.rb +50 -3
  21. data/lib/sitefuel/external/JPEGTran.rb +2 -2
  22. data/lib/sitefuel/external/PNGCrush.rb +2 -2
  23. data/lib/sitefuel/external/SVN.rb +57 -0
  24. data/lib/sitefuel/processors/AbstractExternalProgramProcessor.rb +17 -4
  25. data/lib/sitefuel/processors/AbstractProcessor.rb +64 -47
  26. data/lib/sitefuel/processors/AbstractStringBasedProcessor.rb +20 -3
  27. data/lib/sitefuel/processors/CSSProcessor.rb +2 -2
  28. data/lib/sitefuel/processors/Configurable.rb +94 -0
  29. data/lib/sitefuel/processors/HAMLProcessor.rb +4 -4
  30. data/lib/sitefuel/processors/HTMLProcessor.rb +2 -2
  31. data/lib/sitefuel/processors/JavaScriptProcessor.rb +2 -2
  32. data/lib/sitefuel/processors/PHPProcessor.rb +2 -2
  33. data/lib/sitefuel/processors/PNGProcessor.rb +2 -2
  34. data/lib/sitefuel/processors/RHTMLProcessor.rb +2 -2
  35. data/lib/sitefuel/processors/SASSProcessor.rb +4 -4
  36. data/test/{test_images → images}/sample_jpg01.jpg +0 -0
  37. data/test/{test_images → images}/sample_png01.png +0 -0
  38. data/test/processor_listing.rb +2 -2
  39. data/test/{test_programs → programs}/versioning.rb +2 -2
  40. data/test/repositories/git/few_files/deployment.yml +0 -0
  41. data/test/repositories/git/few_files/index.html +10 -0
  42. data/test/repositories/git/few_files/style.css +2 -0
  43. data/test/repositories/svn/testrepo1/README.txt +5 -0
  44. data/test/repositories/svn/testrepo1/conf/authz +32 -0
  45. data/test/repositories/svn/testrepo1/conf/passwd +8 -0
  46. data/test/repositories/svn/testrepo1/conf/svnserve.conf +47 -0
  47. data/test/repositories/svn/testrepo1/db/current +1 -0
  48. data/test/repositories/svn/testrepo1/db/format +2 -0
  49. data/test/repositories/svn/testrepo1/db/fs-type +1 -0
  50. data/test/repositories/svn/testrepo1/db/fsfs.conf +37 -0
  51. data/test/repositories/svn/testrepo1/db/min-unpacked-rev +1 -0
  52. data/test/repositories/svn/testrepo1/db/rep-cache.db +0 -0
  53. data/test/repositories/svn/testrepo1/db/revprops/0/0 +5 -0
  54. data/test/repositories/svn/testrepo1/db/revprops/0/1 +13 -0
  55. data/test/repositories/svn/testrepo1/db/revs/0/0 +11 -0
  56. data/test/repositories/svn/testrepo1/db/revs/0/1 +0 -0
  57. data/test/repositories/svn/testrepo1/db/txn-current +1 -0
  58. data/test/repositories/svn/testrepo1/db/txn-current-lock +0 -0
  59. data/test/repositories/svn/testrepo1/db/uuid +1 -0
  60. data/test/repositories/svn/testrepo1/db/write-lock +0 -0
  61. data/test/repositories/svn/testrepo1/format +1 -0
  62. data/test/repositories/svn/testrepo1/hooks/post-commit.tmpl +50 -0
  63. data/test/repositories/svn/testrepo1/hooks/post-lock.tmpl +45 -0
  64. data/test/repositories/svn/testrepo1/hooks/post-revprop-change.tmpl +57 -0
  65. data/test/repositories/svn/testrepo1/hooks/post-unlock.tmpl +43 -0
  66. data/test/repositories/svn/testrepo1/hooks/pre-commit.tmpl +85 -0
  67. data/test/repositories/svn/testrepo1/hooks/pre-lock.tmpl +71 -0
  68. data/test/repositories/svn/testrepo1/hooks/pre-revprop-change.tmpl +66 -0
  69. data/test/repositories/svn/testrepo1/hooks/pre-unlock.tmpl +63 -0
  70. data/test/repositories/svn/testrepo1/hooks/start-commit.tmpl +68 -0
  71. data/test/repositories/svn/testrepo1/locks/db-logs.lock +3 -0
  72. data/test/repositories/svn/testrepo1/locks/db.lock +3 -0
  73. data/test/sites/simplehtml/deployment.yml +19 -0
  74. data/test/{test_sites → sites}/simplehtml/index.html +0 -0
  75. data/test/{test_sites → sites}/simplehtml/style.css +0 -0
  76. data/test/sites/sitefuelteaser/deployment.yml +13 -0
  77. data/test/sites/sitefuelteaser/img/hd.png +0 -0
  78. data/test/sites/sitefuelteaser/img/logo.png +0 -0
  79. data/test/sites/sitefuelteaser/img/uses-sitefuel.png +0 -0
  80. data/test/sites/sitefuelteaser/index.html +1 -1
  81. data/test/sites/sitefuelteaser/master.css +18 -0
  82. data/test/test_AbstractExternalProgram.rb +5 -5
  83. data/test/test_AbstractProcessor.rb +4 -4
  84. data/test/test_AbstractStringBasedProcessor.rb +2 -2
  85. data/test/test_AllProcessors.rb +4 -4
  86. data/test/test_ArrayComparisons.rb +4 -4
  87. data/test/test_CSSProcessor.rb +4 -4
  88. data/test/test_ColumnPrinter.rb +40 -0
  89. data/test/test_Configurable.rb +106 -0
  90. data/test/test_FileComparisons.rb +4 -4
  91. data/test/test_GIT.rb +41 -0
  92. data/test/{test_HAMLProcessor.rb.rb → test_HAMLProcessor.rb} +4 -4
  93. data/test/test_HTMLProcessor.rb +4 -4
  94. data/test/test_JPEGTran.rb +4 -4
  95. data/test/test_JavaScriptProcessor.rb +3 -2
  96. data/test/test_PHPProcessor.rb +4 -4
  97. data/test/test_PNGCrush.rb +8 -8
  98. data/test/test_PNGProcessor.rb +5 -5
  99. data/test/test_RHTMLProcessor.rb +4 -4
  100. data/test/test_SASSProcessor.rb +4 -4
  101. data/test/test_SVN.rb +44 -0
  102. data/test/test_SiteFuelLogging.rb +4 -4
  103. data/test/test_SiteFuelRuntime.rb +42 -4
  104. data/test/test_StringFormatting.rb +27 -4
  105. data/test/test_SymbolComparison.rb +4 -4
  106. data/test/ts_all.rb +2 -2
  107. metadata +94 -20
  108. data/README +0 -86
  109. data/test/test_sites/simplehtml/deployment.yml +0 -22
data/README.rdoc ADDED
@@ -0,0 +1,81 @@
1
+
2
+ = SiteFuel
3
+ ==== http://sitefuel.org
4
+ ==== v0.1.0 (alpha release)
5
+
6
+
7
+ --------------------------------------------------------------------------------
8
+
9
+ A program and API for minifying websites and web applications and
10
+ deploying them from version control.
11
+
12
+ - Get started: http://sitefuel.org/getstarted
13
+ - Lists: http://sitefuel.org/mailinglists
14
+ - Report a bug: http://sitefuel.org/bug
15
+
16
+ - Contribute! http://sitefuel.org/contribute
17
+
18
+
19
+ == Table of Contents
20
+
21
+ - Introduction
22
+ - System Requirements
23
+ - Supported Formats
24
+ - Installation
25
+ - Getting Started
26
+ - Reporting a Bug
27
+ - A Note about the API
28
+ - Further Reading
29
+
30
+
31
+ == Introduction
32
+ SiteFuel is a Ruby program
33
+
34
+ Use SiteFuel to:
35
+ - deploy your website out of SVN or GIT
36
+ - minify your
37
+
38
+
39
+ == System Requirements
40
+
41
+ - Ruby 1.8.6 or greater.
42
+ - =pngcrush= for PNG compression
43
+ - =jpegtran= for JPEG compression
44
+ - =git= for deploying sites from Git repositories
45
+ - =svn= for deploying sites from SVN repositories
46
+
47
+ SiteFuel hasn't been tested on Windows machines.
48
+
49
+
50
+ == Installation
51
+
52
+ SiteFuel is deployed as a RubyGem through http://gemcutter.org. You
53
+ should be able to install it directly using RubyGems:
54
+
55
+ $ gem install -t sitefuel
56
+
57
+ Note that for PNG and JPEG compression to be enabled you must install
58
+ the =pngcrush= and =jpegtran= programs.
59
+
60
+
61
+
62
+ == Getting Started
63
+
64
+ SiteFuel
65
+
66
+
67
+
68
+
69
+ == Reporting a Bug
70
+
71
+
72
+ == A Note About the API
73
+
74
+ The general API in SiteFuel should be considered unstable while SiteFuel
75
+ is <1.0. For practical reasons we can't increment the major version
76
+ number each time there is a non-backwards compatible API change....
77
+
78
+
79
+ == Further Reading
80
+ - http://sitefuel.org: main sitefuel website
81
+ - http://sitefuel.org/help: pointers to various resources
File without changes
data/bin/sitefuel CHANGED
@@ -2,46 +2,74 @@
2
2
 
3
3
  # == Synopsis
4
4
  #
5
- # A lightweight ruby framework for processing and deploying websites, either
6
- # from
5
+ # SiteFuel is a program and lightweight Ruby API for processing the
6
+ # source code behind your static and dynamic websites. SiteFuel can
7
+ # remove comments and unneeded whitespace from your CSS, HTML, and
8
+ # JavaScript files (as well as fragments in RHTML and PHP) files. It can
9
+ # also loss-lessly compress your PNG and JPEG images. SiteFuel can also
10
+ # deploy your website from SVN or GIT.
11
+ #
12
+ # Support for more file formats and repositories is planned for future
13
+ # versions.
14
+ #
7
15
  #
8
16
  # == Usage
9
17
  #
10
- # sitefuel deploy|process SOURCE [OPTIONS]
18
+ # sitefuel <command> [--driver=file|svn|git] <source> [<output>]
19
+ # [--debug] [--verbose] [--help] [--license]
11
20
  #
12
- # == Introduction
13
- # sitefuel is a lightweight ruby framework for deploying websites directly from
14
- # version control. sitefuel includes support for compressing HTML and CSS as
15
- # well as optimizing PNG graphics. Support is planned for SASS; compressing
16
- # JavaScript; automatically creating sprites; and supporting more image formats.
17
- # (and more!)
18
- #
19
- # TODO: add more details
21
+ # === <command>
22
+ # Possible commands are:
23
+ # stage:: Simulate a deployment of a site.
24
+ # deploy:: Deploy a site using SiteFuel.
25
+ # help:: Show this message.
20
26
  #
21
- # * More information: http://sitefuel.org
22
- # * Getting started: http://sitefuel.org/getstarted
23
- # * Documentation: http://sitefuel.org/documentation
27
+ # === <driver>
28
+ # SiteFuel can typically guess what driver to use, but you can explicitly
29
+ # specify:
30
+ #
31
+ # filesystem:: deploy a directory
32
+ # svn:: use with Subversion repositories
33
+ # git:: use with Git repositories
34
+ #
35
+ # === <source>
36
+ # Specify the source SiteFuel is deploying from. This should accept all
37
+ # protocols supported by enabled drivers. Eg.
38
+ #
39
+ # For svn:
40
+ # svn+ssh://user@sitefuel.org/svn/web/sitefuel-main
41
+ #
42
+ # For git:
43
+ # ssh://user@sitefuel.org/...
44
+ #
45
+ # === <output>
46
+ # Specify the directory into which SiteFuel is to deploy. Currently SiteFuel can
47
+ # only deploy into the file system.
24
48
  #
25
- # == Commands
49
+ # === --debug
50
+ # Enables all messages including debugging. This will give you a blow by blow
51
+ # account of what SiteFuel is doing.
52
+ #
53
+ # === --verbose
54
+ # Enables most messages. This will give you a relatively detailed account of
55
+ # how SiteFuel is deploying your site.
26
56
  #
27
- # deploy:: Deploy a site using sitefuel.
28
- # process:: Modify an existing website inplace.
29
- # stage:: Simulates a deployment without actually changing anything.
30
- # help:: Show this message.
31
57
  #
32
58
  # == Examples
33
59
  # Process an already deployed site:
34
- # sitefuel process /var/www/
60
+ # sitefuel deploy /var/www/sitefuel /var/www/sitefuel-compacted
35
61
  #
36
62
  # Deploy a site from SVN:
37
63
  # sitefuel deploy svn+ssh://sitefuel.org/svn/tags/21 /var/www/
38
64
  #
39
- # Specify a non-default deployment file:
40
- # sitefuel process /var/www/ -c customdeployment.yml
65
+ # == Links
41
66
  #
67
+ # * More information: http://sitefuel.org
68
+ # * Getting started: http://sitefuel.org/getstarted
69
+ # * Documentation: http://sitefuel.org/documentation
42
70
  #
43
71
  # == Author
44
- # Zanoccio, LLC.
72
+ # wkm, Zanoccio LLC.
45
73
  #
46
74
  # == Copyright
47
75
  # Copyright (c) 2009 Zanoccio.
@@ -51,7 +79,7 @@
51
79
  # modify it under the terms of the GNU General Public License
52
80
  # as published by the Free Software Foundation; either version 2
53
81
  # of the License, or (at your option) any later version.
54
- #
82
+ # # stage::
55
83
  # This program is distributed in the hope that it will be useful,
56
84
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
57
85
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -66,97 +94,22 @@
66
94
  $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
67
95
 
68
96
  begin
69
- require 'rubygems'
70
- rescue LoadError
71
- # attempt to continue running the program
72
- end
73
-
74
-
75
- require 'rdoc/usage'
76
- require 'term/ansicolor'
77
-
78
- require 'sitefuel/SiteFuelRuntime'
79
-
80
- include Term::ANSIColor
81
-
82
- def puts_and_exit(*args)
83
- puts(*args)
84
- exit
85
- end
86
-
87
- $HELP_HINT_LINE = "type \'#{$0} help\' for usage"
88
-
89
- # parse command line arguments and configure a SiteFuelRuntime
90
- def parse_command_line(runtime)
91
-
92
- #### BUILD THE OPTIONS PARSER
93
- opts = OptionParser.new
94
-
95
- # the banner text comes from the header comment for this file
96
-
97
- opts.on('-oARG', '-o=ARG', '-o PLACE', '--output=ARG', '--output PLACE', String,
98
- 'Where to put a deployed site') do |out|
99
- runtime.deploy_to = out
100
- end
101
- opts.on('-v', '--version', 'Gives the version of sitefuel') do
102
- puts 'SiteFuel ' + VERSION_TEXT
103
- end
104
-
105
- opts.on('--[no-]verbose', 'List actions as they are preformed') do
106
- puts 'cause SiteFuel to be verbose listing actions as they are preformed'
107
- end
108
-
109
- opts.on('--only-list-recognized-files', 'Only list summaries for files which were changed') do
110
- runtime.only_list_recognized_files = true
111
- end
112
-
113
- opts.on('-h', '--help', '-?', '--about', 'Gives help for a specific command.') do
114
- RDoc::usage_no_exit('Synopsis', 'Usage', 'Introduction')
115
- puts opts
116
- RDoc::usage_no_exit('Examples', 'Author', 'Copyright', 'License')
117
- exit
118
- end
119
-
120
- opts.separator ''
121
- opts.separator 'Specific options for a command can be seen with: '
122
- opts.separator ' COMMAND --help'
123
-
124
-
125
- #### ATTEMPT TO PARSE THE COMMAND LINE
126
97
  begin
127
- commands = opts.parse(*ARGV)
128
- rescue OptionParser::InvalidOption => iopt
129
- puts iopt
130
- puts_and_exit $HELP_HINT_LINE
131
- rescue => exception
132
- # TODO: add better handling for the various exceptions (unnecessary
133
- # argument, missing argument, etc.)
134
- puts_and_exit "couldn't parse command line: #{exception}", $HELP_HINT_LINE
98
+ require 'rubygems'
99
+ rescue LoadError
100
+ # attempt to continue running the program
135
101
  end
136
102
 
103
+ require 'sitefuel/SiteFuelRuntime'
104
+ require 'sitefuel/CommandLine'
137
105
 
138
- # note that --help will have already been intercepted but 'help' still needs
139
- # special treatment
140
- puts_and_exit 'no command given', $HELP_HINT_LINE if commands.length < 1
141
- puts_and_exit opts if commands[0].downcase == 'help'
142
-
143
- case commands[0].downcase
144
- when 'deploy'
145
- runtime.deploy_from = commands[1]
146
- runtime.deploy
147
-
148
- when 'stage'
149
- runtime.deploy_from = commands[1]
150
- runtime.stage
151
-
152
- else
153
- puts_and_exit "unknown command: '#{commands[0]}'", $HELP_HINT_LINE
106
+ def main
107
+ runtime = SiteFuel::SiteFuelRuntime.new
108
+ SiteFuel::CommandLine::parse_command_line(runtime)
154
109
  end
155
- end
156
110
 
157
- def main
158
- runtime = SiteFuel::SiteFuelRuntime.new
159
- parse_command_line(runtime)
160
- end
111
+ main()
161
112
 
162
- main()
113
+ rescue Interrupt
114
+ puts 'Fatal: interrupted. Exiting.'
115
+ end
@@ -0,0 +1,142 @@
1
+ #
2
+ # File:: CommandLine.rb
3
+ # Author:: wkm
4
+ # Copyright:: 2009, Zanoccio LLC.
5
+ # License:: GPL version 2.0 (see LICENSE.rb)
6
+ #
7
+ # Contains the command line parser for the sitefuel program
8
+ #
9
+
10
+
11
+ module SiteFuel
12
+ module CommandLine
13
+
14
+ require 'rdoc/usage'
15
+ require 'term/ansicolor'
16
+
17
+ require 'sitefuel/License'
18
+
19
+ include Term::ANSIColor
20
+
21
+ def self.puts_and_exit(*args)
22
+ puts(*args)
23
+ exit
24
+ end
25
+
26
+ $HELP_HINT_LINE = "type '#{$0} help' for usage"
27
+
28
+ @option_parser = nil
29
+
30
+ # parse command line arguments and configure a SiteFuelRuntime
31
+ def self.parse_command_line(runtime)
32
+
33
+ #### BUILD THE OPTIONS PARSER
34
+ @option_parser = OptionParser.new
35
+
36
+ # the banner text comes from the header comment for this file
37
+
38
+ @option_parser.on('-o PLACE', '--output=ARG', '--output PLACE', String,
39
+ 'Where to put a deployed site') do |out|
40
+ runtime.deploy_to = out
41
+ end
42
+ @option_parser.on('-v', '--version', 'Gives the version of sitefuel') do
43
+ puts_and_exit 'SiteFuel ' + VERSION_TEXT
44
+ end
45
+
46
+ @option_parser.on('--scm=ARG', '--scm PLACE', String,
47
+ 'What SCM to use (git, svn, or filesystem)') do |out|
48
+ runtime.scm_system = out
49
+ end
50
+
51
+ #
52
+ # Verbosity options
53
+ #
54
+
55
+ @option_parser.on('--[no-]verbose', 'List actions as they are preformed') do |be_verbose|
56
+ if be_verbose
57
+ # fatal, error, warnings, and info
58
+ runtime.verbosity(3)
59
+ else
60
+ # fatal, error, and warnings
61
+ runtime.verbosity(2)
62
+ end
63
+ end
64
+
65
+ @option_parser.on('--debug', 'Gives verbose debugging information') do
66
+ runtime.verbosity(4)
67
+ end
68
+
69
+ @option_parser.on('--abort-errors', '[default] Abort deployment if there are errors') do
70
+ runtime.abort_on_errors = true
71
+ end
72
+
73
+ @option_parser.on('--ignore-errors', 'Deploy even if there are errors') do
74
+ runtime.abort_on_errors = false
75
+ runtime.abort_on_warnings = false
76
+ end
77
+
78
+ @option_parser.on('--abort-warnings', 'Abort deployment if there are warnings') do
79
+ runtime.abort_on_warnings = true
80
+ runtime.abort_on_errors = true
81
+ end
82
+
83
+ @option_parser.on('--ignore-warnings', '[default] Deploy even if there are warnings') do
84
+ runtime.abort_on_warnings = true
85
+ end
86
+
87
+ @option_parser.on('--only-list-recognized-files', 'Only list summaries for files which were changed') do
88
+ runtime.only_list_recognized_files = true
89
+ end
90
+
91
+ @option_parser.on('-h', '--help', '-?', '--about', 'Gives help for a specific command.') do
92
+ RDoc::usage_no_exit('Synopsis', 'Usage', 'Introduction')
93
+ puts @option_parser
94
+ RDoc::usage_no_exit('Examples', 'Author', 'Copyright')
95
+ exit
96
+ end
97
+
98
+ @option_parser.on('--license', 'Gives the license for SiteFuel.') do
99
+ puts_and_exit SiteFuel::LICENSE
100
+ end
101
+
102
+ @option_parser.separator ''
103
+ @option_parser.separator 'Specific options for a command can be seen with: '
104
+ @option_parser.separator ' COMMAND --help'
105
+
106
+
107
+ #### ATTEMPT TO PARSE THE COMMAND LINE
108
+ begin
109
+ commands = @option_parser.parse(*ARGV)
110
+ rescue OptionParser::InvalidOption => invalid_option
111
+ puts invalid_option
112
+ puts_and_exit $HELP_HINT_LINE
113
+ rescue => exception
114
+ # TODO: add better handling for the various exceptions (unnecessary
115
+ # argument, missing argument, etc.)
116
+
117
+ puts_and_exit "couldn't parse command line: #{exception}", $HELP_HINT_LINE
118
+ # puts exception.backtrace.join("\n")
119
+ end
120
+
121
+
122
+ # note that --help will have already been intercepted but 'help' still needs
123
+ # special treatment
124
+ puts_and_exit 'no command given', $HELP_HINT_LINE if commands.length < 1
125
+ puts_and_exit @option_parser if commands[0].downcase == 'help'
126
+
127
+ case commands[0].downcase
128
+ when 'deploy'
129
+ runtime.deploy_from = commands[1]
130
+ runtime.deploy_to = commands[2]
131
+ runtime.deploy
132
+
133
+ when 'stage'
134
+ runtime.deploy_from = commands[1]
135
+ runtime.stage
136
+
137
+ else
138
+ puts_and_exit "unknown command: '#{commands[0]}'", $HELP_HINT_LINE
139
+ end
140
+ end
141
+ end
142
+ end
@@ -1,35 +1,71 @@
1
1
  #
2
2
  # File:: configuration.rb
3
3
  # Author:: wkm
4
- # Copyright:: 2009
5
- # License:: GPL
4
+ # Copyright:: 2009, Zanoccio LLC.
5
+ # License:: GPL version 2.0 (see LICENSE.rb)
6
6
  #
7
7
  # Load and process SiteFuel YAML configuration files
8
8
  #
9
9
 
10
10
  module SiteFuel
11
+ require 'sitefuel/SiteFuelLogger'
11
12
  require 'yaml'
12
13
 
14
+ # exception which represents that a configuration could not be found
13
15
  class Configuration
14
16
 
15
- # exception which represents that a configuration could not be found
16
- class NotFound < StandardError
17
- end
17
+ include SiteFuel::Logging
18
+
19
+ DEFAULT_CONFIGURATION_FILE = 'deployment.yml'
18
20
 
19
21
  # given a directory path will attempt to location a configuration file
20
- # and load it, returning a SiteFuel::Configuration class
21
- def self.load(path)
22
- unless File.exist?(path)
23
- throw NotFound, path
22
+ def self.find_configuration(path, filename = DEFAULT_CONFIGURATION_FILE)
23
+ files = Dir["**/"+filename]
24
+
25
+ if files.length < 0
26
+ return nil
27
+ elsif files.length > 1
28
+ warn("Multiple possible configuration files found: #{files.join(', ')}; using #{files.first}")
29
+ return files.first
30
+ else
31
+ return files.first
24
32
  end
33
+ end
25
34
 
26
- yamlconfig = YAML::load_file(configfile)
27
-
28
- Configuration.new(yamlconfig)
35
+
36
+ # given a directory path will attempt to find and load a
37
+ # configuration file
38
+ def self.load_configuration(runtime, path, filename = DEFAULT_CONFIGURATION_FILE)
39
+ configuration_file = find_configuration(path, filename)
40
+
41
+ if configuration_file == nil
42
+ warn('No deployment configuration file found. Using defaults.')
43
+ return Configuration.new(runtime, nil)
44
+ else
45
+ yaml = YAML::load_file(configuration_file)
46
+ return Configuration.new(runtime, yaml)
47
+ end
29
48
  end
30
49
 
50
+
31
51
  # builds a sitefuel configuration from a parsed YAML file
32
- def initialize(yamlconfig)
52
+ def initialize(runtime, yaml_config)
53
+ @processor_configurations = Hash.new([])
54
+ @runtime = runtime
55
+
56
+ load_yaml_config(yaml_config)
57
+ end
58
+
59
+
60
+ # loads a yaml configuration
61
+ def load_yaml_config(yaml_config)
62
+
63
+ end
64
+
65
+
66
+ # gives an array of configuration options for the processor
67
+ def processor_configuration(processor)
68
+ @processor_configurations[processor]
33
69
  end
34
70
  end
35
71
  end