awestruct 0.2.18 → 0.4.2.x1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/bin/awestruct +2 -274
  2. data/lib/awestruct/astruct.rb +22 -0
  3. data/lib/awestruct/astruct_mixin.rb +81 -0
  4. data/lib/awestruct/cli/auto.rb +34 -0
  5. data/lib/awestruct/cli/deploy.rb +38 -0
  6. data/lib/awestruct/{commands → cli}/generate.rb +3 -3
  7. data/lib/awestruct/cli/invoker.rb +120 -0
  8. data/lib/awestruct/cli/options.rb +116 -0
  9. data/lib/awestruct/{commands → cli}/server.rb +1 -1
  10. data/lib/awestruct/config.rb +20 -8
  11. data/lib/awestruct/context.rb +22 -0
  12. data/lib/awestruct/dependencies.rb +102 -0
  13. data/lib/awestruct/deploy/github_pages_deploy.rb +61 -0
  14. data/lib/awestruct/{commands/deploy.rb → deploy/rsync_deploy.rb} +10 -6
  15. data/lib/awestruct/deployers.rb +15 -0
  16. data/lib/awestruct/engine.rb +172 -411
  17. data/lib/awestruct/extensions/atomizer.rb +7 -4
  18. data/lib/awestruct/extensions/coffeescripttransform.rb +42 -0
  19. data/lib/awestruct/extensions/minify.rb +21 -23
  20. data/lib/awestruct/extensions/paginator.rb +6 -4
  21. data/lib/awestruct/extensions/partial.rb +0 -1
  22. data/lib/awestruct/extensions/pipeline.rb +5 -0
  23. data/lib/awestruct/extensions/posts.rb +11 -9
  24. data/lib/awestruct/extensions/sitemap.rb +2 -1
  25. data/lib/awestruct/extensions/tagger.rb +0 -2
  26. data/lib/awestruct/extensions/template.atom.haml +4 -3
  27. data/lib/awestruct/handler_chain.rb +28 -0
  28. data/lib/awestruct/handler_chains.rb +48 -0
  29. data/lib/awestruct/handlers/asciidoc_handler.rb +57 -0
  30. data/lib/awestruct/handlers/base_handler.rb +111 -0
  31. data/lib/awestruct/handlers/base_sass_handler.rb +42 -0
  32. data/lib/awestruct/handlers/coffeescript_handler.rb +48 -0
  33. data/lib/awestruct/handlers/erb_handler.rb +44 -0
  34. data/lib/awestruct/handlers/file_handler.rb +64 -0
  35. data/lib/awestruct/handlers/front_matter_handler.rb +85 -0
  36. data/lib/awestruct/handlers/haml_handler.rb +54 -0
  37. data/lib/awestruct/handlers/interpolation_handler.rb +28 -0
  38. data/lib/awestruct/handlers/layout_handler.rb +63 -0
  39. data/lib/awestruct/handlers/markdown_handler.rb +50 -0
  40. data/lib/awestruct/handlers/no_op_handler.rb +34 -0
  41. data/lib/awestruct/handlers/orgmode_handler.rb +48 -0
  42. data/lib/awestruct/handlers/page_delegating_handler.rb +54 -0
  43. data/lib/awestruct/handlers/restructuredtext_handler.rb +67 -0
  44. data/lib/awestruct/handlers/sass_handler.rb +21 -0
  45. data/lib/awestruct/handlers/scss_handler.rb +21 -0
  46. data/lib/awestruct/handlers/string_handler.rb +29 -0
  47. data/lib/awestruct/handlers/textile_handler.rb +58 -0
  48. data/lib/awestruct/handlers/yaml_handler.rb +25 -0
  49. data/lib/awestruct/layouts.rb +16 -0
  50. data/lib/awestruct/page.rb +141 -0
  51. data/lib/awestruct/page_loader.rb +82 -0
  52. data/lib/awestruct/pipeline.rb +56 -0
  53. data/lib/awestruct/site.rb +29 -35
  54. data/lib/awestruct/version.rb +1 -1
  55. data/lib/guard/awestruct.rb +38 -0
  56. metadata +115 -88
  57. data/lib/awestruct.rb +0 -2
  58. data/lib/awestruct/asciidoc_file.rb +0 -24
  59. data/lib/awestruct/asciidocable.rb +0 -35
  60. data/lib/awestruct/commands/frameworks/960/base_layout.html.haml +0 -10
  61. data/lib/awestruct/commands/frameworks/base_index.html.haml +0 -5
  62. data/lib/awestruct/commands/frameworks/base_pipeline.rb +0 -6
  63. data/lib/awestruct/commands/frameworks/blueprint/base_layout.html.haml +0 -12
  64. data/lib/awestruct/commands/frameworks/bootstrap/base_index.html.haml +0 -27
  65. data/lib/awestruct/commands/frameworks/bootstrap/base_layout.html.haml +0 -29
  66. data/lib/awestruct/commands/git_hub_pages.rb +0 -55
  67. data/lib/awestruct/commands/init.rb +0 -40
  68. data/lib/awestruct/commands/manifest.rb +0 -205
  69. data/lib/awestruct/erb_file.rb +0 -24
  70. data/lib/awestruct/erbable.rb +0 -19
  71. data/lib/awestruct/front_matter_file.rb +0 -54
  72. data/lib/awestruct/haml/filters/asciidoc.rb +0 -8
  73. data/lib/awestruct/haml_file.rb +0 -27
  74. data/lib/awestruct/hamlable.rb +0 -19
  75. data/lib/awestruct/markdown_file.rb +0 -23
  76. data/lib/awestruct/markdownable.rb +0 -18
  77. data/lib/awestruct/orgmode_file.rb +0 -23
  78. data/lib/awestruct/orgmodeable.rb +0 -15
  79. data/lib/awestruct/renderable.rb +0 -18
  80. data/lib/awestruct/renderable_file.rb +0 -39
  81. data/lib/awestruct/restructuredtext_file.rb +0 -23
  82. data/lib/awestruct/restructuredtextable.rb +0 -38
  83. data/lib/awestruct/sass_file.rb +0 -24
  84. data/lib/awestruct/sassable.rb +0 -33
  85. data/lib/awestruct/scss_file.rb +0 -24
  86. data/lib/awestruct/textilable.rb +0 -22
  87. data/lib/awestruct/textile_file.rb +0 -23
  88. data/lib/awestruct/verbatim_file.rb +0 -12
data/bin/awestruct CHANGED
@@ -3,278 +3,6 @@
3
3
  $: << File.dirname(__FILE__) + '/../lib'
4
4
 
5
5
  require 'rubygems'
6
- require 'optparse'
7
- require 'awestruct/version'
8
- require 'awestruct/commands/init'
9
- require 'awestruct/commands/generate'
10
- require 'awestruct/commands/server'
11
- require 'awestruct/commands/deploy'
12
- require 'awestruct/commands/git_hub_pages'
13
- require 'yaml'
14
- require 'fssm'
15
- require 'fileutils'
6
+ require 'awestruct/cli/invoker'
16
7
 
17
- def parse(args)
18
- options = OpenStruct.new( {
19
- :generate=>true,
20
- :server=>false,
21
- :port=>4242,
22
- :bind_addr=>'0.0.0.0',
23
- :auto=>false,
24
- :force=>false,
25
- :init=>false,
26
- :framework=>'compass',
27
- :scaffold=>true,
28
- :base_url=>nil,
29
- :profile=>nil,
30
- :deploy=>false,
31
- :script=>nil,
32
- } )
33
-
34
- opts = OptionParser.new do |opts|
35
- opts.on( '-i', '--init', 'Initialize a new project in the current directory' ) do |init|
36
- options.init = init
37
- options.generate = false
38
- end
39
- opts.on( '-f', '--framework FRAMEWORK', 'Specify a compass framework during initialization (bootstrap, blueprint, 960)' ) do |framework|
40
- options.framework = framework
41
- end
42
- opts.on( '--[no-]scaffold', 'Create scaffolding during initialization (default: true)' ) do |s|
43
- options.scaffold = s
44
- end
45
- opts.on( '--force', 'Force a regeneration' ) do |force|
46
- options.force = force
47
- end
48
- opts.on( '-s', '--server', 'Serve generated site' ) do |s|
49
- options.server = s
50
- end
51
- opts.on( '-u', '--url URL', 'Set site.base_url' ) do |url|
52
- options.base_url = url
53
- end
54
- opts.on( '-d', '--dev', 'Run in development mode (--auto, --server and -profile development)' ) do |url|
55
- options.server = true
56
- options.auto = true
57
- options.port = 4242
58
- options.profile = 'development'
59
- end
60
-
61
- opts.on( '-P', '--profile PROFILE', 'Specify a profile' ) do |profile|
62
- options.profile = profile
63
- end
64
-
65
- opts.on( '--deploy', 'Deploy site' ) do |deploy|
66
- options.deploy = deploy
67
- end
68
-
69
- opts.on( '-a', '--auto', 'Auto-generate when changes are noticed' ) do |a|
70
- options.auto = a
71
- end
72
- opts.on( '-p', '--port PORT', Integer, 'Server port (default: 4242)' ) do |port|
73
- options.port = port
74
- end
75
- opts.on( '-b', '--bind ADDR', 'Server address (default: 0.0.0.0)' ) do |bind_addr|
76
- options.bind_addr = bind_addr
77
- end
78
- opts.on( '-g', '--[no-]generate', 'Generated site' ) do |g|
79
- options.generate = g
80
- end
81
- opts.on( '--run SCRIPT', 'Force a regeneration' ) do |script|
82
- options.script = script
83
- end
84
-
85
- opts.separator ''
86
- opts.separator "Common options:"
87
-
88
- opts.on_tail("-h", "--help", "Show this message") do
89
- puts opts
90
- exit
91
- end
92
-
93
- opts.on_tail("-v", "--version", "Display the version") do
94
- puts "Awestruct: #{Awestruct::VERSION}"
95
- puts "http://awestruct.org/"
96
- exit
97
- end
98
-
99
- end
100
-
101
- opts.parse!(args)
102
- options
103
- end
104
-
105
- def site_path
106
- dir = (@profiles_data.nil? || @profile_data.nil? || @profile_data['output_dir'].nil?) ? '_site' : @profile_data['output_dir']
107
- path = File.join( Dir.pwd, dir )
108
- end
109
-
110
- options = parse(ARGV)
111
-
112
- unless options.init
113
- site_yaml_file = File.join( Dir.pwd, '_config', 'site.yml' )
114
- site_yaml = YAML.load( File.read( site_yaml_file ) )
115
- if site_yaml
116
- @profiles_data = site_yaml['profiles'] || {}
117
- @profile_data = if @profiles_data.nil?
118
- nil
119
- else
120
- if options.profile
121
- @profiles_data[options.profile]
122
- else
123
- # if no profile given, pick the first with deploy config
124
- options.profile, profile_data = @profiles_data.select { |k,v| v && v['deploy'] }.first
125
- profile_data
126
- end
127
- end
128
- end
129
- end
130
-
131
- config = Awestruct::Config.new(Dir.pwd)
132
-
133
- if ( options.init )
134
- if ( options.generate || options.auto || options.server )
135
- $stderr.puts "--init may not be used with --generate, --auto or --server"
136
- exit
137
- end
138
- cmd = Awestruct::Commands::Init.new( Dir.pwd, options.framework, options.scaffold )
139
- cmd.run
140
- exit
141
- end
142
-
143
- default_base_url = 'http://localhost:4242'
144
-
145
- def camelize(str)
146
- str.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
147
- end
148
-
149
- if ( options.script )
150
- puts "Running #{options.script} and exiting"
151
- require "awestruct/scripts/#{options.script}"
152
- script_class = eval "Awestruct::Scripts::#{camelize(options.script)}"
153
- script = script_class.new(*ARGV)
154
- script.run
155
- exit
156
- end
157
-
158
- if ( options.server )
159
- hostname = ( options.bind_addr == '0.0.0.0' ? 'localhost' : options.bind_addr )
160
- default_base_url = "http://#{hostname}:#{options.port}"
161
- end
162
-
163
- if ( options.force )
164
- if File.exist?( site_path )
165
- FileUtils.rmdir( site_path )
166
- end
167
- end
168
-
169
- if ( options.generate )
170
- cmd = Awestruct::Commands::Generate.new( config, options.profile, options.base_url, default_base_url, options.force )
171
- cmd.run
172
- end
173
-
174
- if ( options.deploy )
175
- if ( options.auto || options.server )
176
- $stderr.puts "--deploy may not be used with --auto or --server"
177
- exit
178
- end
179
-
180
- if ( ! options.profile )
181
- $stderr.puts "You must specify a --profile when using --deploy"
182
- exit
183
- end
184
-
185
- if ( @profiles_data.nil? )
186
- $stderr.puts "_config/site.yml must define a 'profiles' section"
187
- exit
188
- end
189
-
190
- if ( @profile_data.nil? )
191
- $stderr.puts "Unknown profile '#{options.profile}'"
192
- exit
193
- end
194
-
195
- if ( ! File.exist?( site_path ) )
196
- $stderr.puts "No #{site_path}/ generated yet."
197
- exit
198
- end
199
-
200
- deploy_data = @profile_data['deploy']
201
- if ( deploy_data.nil? )
202
- $stderr.puts "No configuration for 'deploy'"
203
- exit
204
- end
205
-
206
- puts "deploying to '#{options.profile}'"
207
- if (deploy_data['host'] == 'github_pages')
208
- puts "publishing to github pages"
209
- cmd = Awestruct::Commands::GitHubPages.new( site_path )
210
- else
211
- cmd = Awestruct::Commands::Deploy.new( site_path, deploy_data )
212
- end
213
- cmd.run
214
- puts "deploy finished"
215
- exit
216
- end
217
-
218
- threads = []
219
-
220
- if ( options.auto )
221
- threads << Thread.new {
222
- generate_cmd = Awestruct::Commands::Generate.new( config, options.profile, options.base_url, default_base_url )
223
-
224
- monitor = FSSM::Monitor.new
225
-
226
- call_generate = lambda do |base, relative|
227
- # Convert to absolute path and append file separator if necessary.
228
- base = File::expand_path(base)
229
- if base[base.length - 1] != File::SEPARATOR
230
- base += File::SEPARATOR
231
- end
232
-
233
- # Filter out bad input just in case.
234
- if base.length < config.input_dir.length or config.input_dir != base[0..config.input_dir.length]
235
- return
236
- end
237
-
238
- path = base + relative
239
- path = path[config.input_dir.length..path.length]
240
-
241
- if path =~ /^(_site|_tmp|\.git|\.gitignore|\.sass-cache|\.|\.\.).*/
242
- return
243
- end
244
- if path =~ /.*(~|\.(swp|bak|tmp))$/
245
- return
246
- end
247
-
248
- puts "Triggered regeneration: #{path}"
249
- generate_cmd.run
250
- puts "Done"
251
- if relative == '.'
252
- # It's necessary to restart the monitor on individual files
253
- # after a change is handled
254
- monitor.file(base) do
255
- update &call_generate
256
- create &call_generate
257
- end
258
- end
259
- end
260
-
261
- monitor.path(config.input_dir) do
262
- update &call_generate
263
- create &call_generate
264
- end
265
-
266
- monitor.run
267
- }
268
- end
269
-
270
- if ( options.server )
271
- threads << Thread.new {
272
- puts "Serving site at #{site_path}"
273
- server_cmd = Awestruct::Commands::Server.new( site_path, options.bind_addr, options.port )
274
- server_cmd.run
275
- }
276
- end
277
-
278
- threads.each do |thr|
279
- thr.join
280
- end
8
+ Awestruct::CLI::Invoker.new( ARGV ).invoke!
@@ -0,0 +1,22 @@
1
+ require 'awestruct/astruct_mixin'
2
+
3
+ module Awestruct
4
+
5
+ class AStruct < Hash
6
+
7
+ include AStructMixin
8
+
9
+ def initialize(hash=nil)
10
+ hash.each{|k,v| self[k]=v } if hash
11
+ end
12
+
13
+ alias_method :original_entries, :entries
14
+ undef entries
15
+
16
+ def inspect
17
+ "AStruct{...}"
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,81 @@
1
+
2
+ require 'awestruct/dependencies'
3
+
4
+ module Awestruct
5
+
6
+ module AStructMixin
7
+
8
+ def self.extended(o)
9
+ class << o
10
+ alias_method :original_entries, :entries
11
+ undef entries
12
+ end
13
+ end
14
+
15
+ def cascade_for_nils!
16
+ @cascade_for_nils = true
17
+ self
18
+ end
19
+
20
+ def key?(key)
21
+ super( key ) || super( key.to_sym ) || super( key.to_s )
22
+ end
23
+
24
+ def [](key)
25
+ r = super( key ) || super( key.to_sym ) || super( key.to_s )
26
+ transform_entry( key, r )
27
+ end
28
+
29
+ def method_missing(sym, *args, &blk)
30
+ type = sym.to_s[-1,1]
31
+ name = sym.to_s.gsub(/[=!?]$/, '').to_sym
32
+ case type
33
+ when '='
34
+ self[name] = args.first
35
+ when '!'
36
+ __send__(name, *args, &blk)
37
+ when '?'
38
+ self[name]
39
+ else
40
+ if key?(name)
41
+ self[name]
42
+ elsif @cascade_for_nils
43
+ self[name] = AStruct.new.cascade_for_nils!
44
+ self[name]
45
+ else
46
+ nil
47
+ end
48
+ end
49
+ end
50
+
51
+ UNTRACKED_KEYS = [
52
+ :url,
53
+ ]
54
+
55
+ def transform_entry(for_key, entry)
56
+ r = case(entry)
57
+ when AStructMixin
58
+ entry
59
+ when Hash
60
+ #AStruct.new( entry )
61
+ entry.extend( AStructMixin )
62
+ when Array
63
+ entry.map!{|i| transform_entry( for_key, i)}
64
+ else
65
+ entry
66
+ end
67
+ if ( self.is_a? Awestruct::Page )
68
+ unless UNTRACKED_KEYS.include? for_key.to_sym
69
+ Awestruct::Dependencies.track_dependency( self )
70
+ end
71
+ end
72
+ r
73
+ end
74
+
75
+ def inspect
76
+ "AStruct{...}"
77
+ end
78
+
79
+ end
80
+
81
+ end
@@ -0,0 +1,34 @@
1
+ require 'guard/awestruct'
2
+
3
+ module Awestruct
4
+ module CLI
5
+ class Auto
6
+
7
+ def initialize(config)
8
+ @config = config
9
+ end
10
+
11
+ def run()
12
+ Guard.setup
13
+ Guard.start( :guardfile_contents=>guardfile_contents,
14
+ :watchdir=>@config.dir,
15
+ :watch_all_modifications=>true )
16
+ end
17
+
18
+ def guardfile_contents
19
+ ignored = [
20
+ "'.awestruct'",
21
+ "'#{File.basename( @config.tmp_dir )}'",
22
+ "'#{File.basename( @config.output_dir )}'",
23
+ ]
24
+ c = ''
25
+ c += "guard :awestruct do\n"
26
+ c += " watch %r(.*)\n"
27
+ c += " ignore_paths #{ignored.join(', ')}"
28
+ c += "end\n"
29
+ c
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,38 @@
1
+ require 'awestruct/deploy/rsync_deploy'
2
+ require 'awestruct/deploy/github_pages_deploy'
3
+
4
+ module Awestruct
5
+ module CLI
6
+
7
+ class Deploy
8
+
9
+ attr_accessor :site_config
10
+ attr_accessor :deploy_config
11
+
12
+ def initialize(site_config, deploy_config)
13
+ @site_config = site_config
14
+ @deploy_config = deploy_config
15
+ end
16
+
17
+ def run()
18
+ deploy_type = :rsync
19
+
20
+ if ( deploy_config['host'] == 'github_pages' )
21
+ deploy_type = :github_pages
22
+ end
23
+
24
+ deployer_class = Awestruct::Deployers.instance[ deploy_type ]
25
+
26
+ if ( deployer_class.nil? )
27
+ $stderr.puts "Unable to locate correct deployer for #{deploy_type}"
28
+ return
29
+ end
30
+
31
+ deployer = deployer_class.new( site_config, deploy_config )
32
+ deployer.run
33
+
34
+ end
35
+ end
36
+
37
+ end
38
+ end