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
@@ -1,11 +1,10 @@
1
1
  require 'awestruct/engine'
2
2
 
3
3
  module Awestruct
4
- module Commands
4
+ module CLI
5
5
  class Generate
6
6
 
7
7
  def initialize(config, profile=nil, base_url=nil, default_base_url='http://localhost:4242', force=false)
8
- @dir = config.input_dir
9
8
  @profile = profile
10
9
  @base_url = base_url
11
10
  @default_base_url = default_base_url
@@ -15,7 +14,8 @@ module Awestruct
15
14
 
16
15
  def run()
17
16
  begin
18
- @engine.generate( @profile, @base_url, @default_base_url, @force )
17
+ puts "Generating site"
18
+ @engine.run( @profile, @base_url, @default_base_url, @force )
19
19
  rescue =>e
20
20
  puts e
21
21
  puts e.backtrace
@@ -0,0 +1,120 @@
1
+ require 'awestruct/cli/options'
2
+
3
+ require 'awestruct/cli/generate'
4
+ require 'awestruct/cli/auto'
5
+ require 'awestruct/cli/server'
6
+ require 'awestruct/cli/deploy'
7
+
8
+ require 'pathname'
9
+
10
+ module Awestruct
11
+ module CLI
12
+ class Invoker
13
+
14
+ attr_reader :options
15
+
16
+ attr_reader :config
17
+ attr_reader :profile
18
+
19
+ def initialize(*options)
20
+ options = options.flatten
21
+ if ( ( ! options.empty? ) && ( options.first === Awestruct::CLI::Options ) )
22
+ @options = options.first
23
+ else
24
+ @options = Awestruct::CLI::Options.parse! options
25
+ end
26
+ @threads = []
27
+ @profile = nil
28
+ end
29
+
30
+ def invoke!
31
+ load_profile() unless ( options.init )
32
+
33
+ setup_config()
34
+
35
+ invoke_init() if ( options.init )
36
+ invoke_script() if ( options.script )
37
+ invoke_force() if ( options.force )
38
+ invoke_generate() if ( options.generate )
39
+ invoke_deploy() if ( options.deploy )
40
+ invoke_server() if ( options.server )
41
+ invoke_auto() if ( options.auto )
42
+
43
+ wait_for_completion()
44
+ end
45
+
46
+ def load_profile()
47
+ site_yaml_file = File.join( Dir.pwd, '_config', 'site.yml' )
48
+ if ( File.exist?( site_yaml_file ) )
49
+ site_yaml = YAML.load( File.read( site_yaml_file ) )
50
+ if site_yaml
51
+ profiles_data = site_yaml['profiles'] || {}
52
+ @profile = if profiles_data.nil?
53
+ nil
54
+ else
55
+ if options.profile
56
+ profiles_data[options.profile]
57
+ else
58
+ # if no profile given, pick the first with deploy config
59
+ options.profile, profile_data = profiles_data.select { |k,v| v && v['deploy'] }.first
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ def setup_config()
67
+ @config = Awestruct::Config.new( Dir.pwd )
68
+ @config.track_dependencies = true if ( options.auto )
69
+ end
70
+
71
+ def invoke_init()
72
+ end
73
+
74
+ def invoke_script()
75
+ end
76
+
77
+ def invoke_force()
78
+ FileUtils.rm_rf( File.join( config.dir, '.awestruct', 'dependency-cache' ) )
79
+ FileUtils.rm_rf( config.output_dir )
80
+ end
81
+
82
+ def invoke_generate()
83
+ Awestruct::CLI::Generate.new( config, profile, options.base_url, 'http://localhost:4242', options.force ).run
84
+ end
85
+
86
+ def invoke_deploy()
87
+ deploy_config = profile[ 'deploy' ]
88
+
89
+ if ( deploy_config.nil? )
90
+ $stderr.puts "No configuration for 'deploy'"
91
+ return
92
+ end
93
+
94
+ Awestruct::CLI::Deploy.new( config, deploy_config ).run
95
+ end
96
+
97
+ def invoke_auto()
98
+ run_in_thread( Awestruct::CLI::Auto.new( config ) )
99
+ end
100
+
101
+ def invoke_server()
102
+ run_in_thread( Awestruct::CLI::Server.new( './_site', options.bind_addr, options.port ) )
103
+ end
104
+
105
+
106
+ private
107
+
108
+ def run_in_thread(command)
109
+ @threads << Thread.new(command){|c| c.run}
110
+ end
111
+
112
+ def wait_for_completion()
113
+ @threads.each do |thr|
114
+ thr.join
115
+ end
116
+ end
117
+
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,116 @@
1
+ require 'optparse'
2
+
3
+ require 'awestruct/version'
4
+
5
+ module Awestruct
6
+ module CLI
7
+ class Options
8
+
9
+ attr_accessor :generate
10
+ attr_accessor :server
11
+ attr_accessor :port
12
+ attr_accessor :bind_addr
13
+ attr_accessor :auto
14
+ attr_accessor :force
15
+ attr_accessor :init
16
+ attr_accessor :framework
17
+ attr_accessor :scaffold
18
+ attr_accessor :base_url
19
+ attr_accessor :profile
20
+ attr_accessor :deploy
21
+ attr_accessor :script
22
+
23
+ def initialize()
24
+ @generate = true
25
+ @server = false
26
+ @port = 4242
27
+ @bind_addr = '0.0.0.0'
28
+ @auto = false
29
+ @force = false
30
+ @init = false
31
+ @framework = 'compass'
32
+ @scaffold = true
33
+ @base_url = nil
34
+ @profile = nil
35
+ @deploy = false
36
+ @script = nil
37
+ end
38
+
39
+ def self.parse!(args)
40
+ Options.new.parse! args
41
+ end
42
+
43
+ def parse!(args)
44
+ opts = OptionParser.new do |opts|
45
+ opts.on( '-i', '--init', 'Initialize a new project in the current directory' ) do |init|
46
+ self.init = init
47
+ self.generate = false
48
+ end
49
+ opts.on( '-f', '--framework FRAMEWORK', 'Specify a compass framework during initialization (bootstrap, blueprint, 960)' ) do |framework|
50
+ self.framework = framework
51
+ end
52
+ opts.on( '--[no-]scaffold', 'Create scaffolding during initialization (default: true)' ) do |s|
53
+ self.scaffold = s
54
+ end
55
+ opts.on( '--force', 'Force a regeneration' ) do |force|
56
+ self.force = force
57
+ end
58
+ opts.on( '-s', '--server', 'Serve generated site' ) do |s|
59
+ self.server = s
60
+ end
61
+ opts.on( '-u', '--url URL', 'Set site.base_url' ) do |url|
62
+ self.base_url = url
63
+ end
64
+ opts.on( '-d', '--dev', 'Run in development mode (--auto, --server and -profile development)' ) do |url|
65
+ self.server = true
66
+ self.auto = true
67
+ self.port = 4242
68
+ self.profile = 'development'
69
+ end
70
+
71
+ opts.on( '-P', '--profile PROFILE', 'Specify a profile' ) do |profile|
72
+ self.profile = profile
73
+ end
74
+
75
+ opts.on( '--deploy', 'Deploy site' ) do |deploy|
76
+ self.deploy = deploy
77
+ end
78
+
79
+ opts.on( '-a', '--auto', 'Auto-generate when changes are noticed' ) do |a|
80
+ self.auto = a
81
+ end
82
+ opts.on( '-p', '--port PORT', Integer, 'Server port (default: 4242)' ) do |port|
83
+ self.port = port
84
+ end
85
+ opts.on( '-b', '--bind ADDR', 'Server address (default: 0.0.0.0)' ) do |bind_addr|
86
+ self.bind_addr = bind_addr
87
+ end
88
+ opts.on( '-g', '--[no-]generate', 'Generated site' ) do |g|
89
+ self.generate = g
90
+ end
91
+ opts.on( '--run SCRIPT', 'Force a regeneration' ) do |script|
92
+ self.script = script
93
+ end
94
+
95
+ opts.separator ''
96
+ opts.separator "Common options:"
97
+
98
+ opts.on_tail("-h", "--help", "Show this message") do
99
+ puts opts
100
+ exit
101
+ end
102
+
103
+ opts.on_tail("-v", "--version", "Display the version") do
104
+ puts "Awestruct: #{Awestruct::VERSION}"
105
+ puts "http://awestruct.org/"
106
+ exit
107
+ end
108
+ end
109
+
110
+ opts.parse!(args)
111
+ self
112
+ end # parse()
113
+
114
+ end
115
+ end
116
+ end
@@ -1,7 +1,7 @@
1
1
  require 'webrick'
2
2
 
3
3
  module Awestruct
4
- module Commands
4
+ module CLI
5
5
 
6
6
  WEBrick::HTTPUtils::DefaultMimeTypes.store('atom', 'application/atom+xml')
7
7
  WEBrick::HTTPUtils::DefaultMimeTypes.store('appcache', 'text/cache-manifest')
@@ -3,6 +3,7 @@ module Awestruct
3
3
 
4
4
  class Config
5
5
 
6
+ attr_accessor :dir
6
7
  attr_accessor :layouts_dir
7
8
  attr_accessor :config_dir
8
9
  attr_accessor :extension_dir
@@ -11,16 +12,27 @@ module Awestruct
11
12
  attr_accessor :skin_dir
12
13
  attr_accessor :tmp_dir
13
14
  attr_accessor :ignore
15
+ attr_accessor :track_dependencies
16
+
17
+ attr_accessor :images_dir
18
+ attr_accessor :stylesheets_dir
19
+
20
+ def initialize(dir = Dir.pwd)
21
+ @dir = Pathname.new( dir )
22
+ @layouts_dir = Pathname.new( File.join(dir, '_layouts') )
23
+ @config_dir = Pathname.new( File.join(dir, '_config') )
24
+ @input_dir = Pathname.new( File.join(dir, '') )
25
+ @output_dir = Pathname.new( File.join(dir, '_site') )
26
+ @extension_dir = Pathname.new( File.join(dir, '_ext') )
27
+ @skin_dir = Pathname.new( File.join(dir, '_skin') )
28
+ @tmp_dir = Pathname.new( File.join(dir, '_tmp') )
29
+
30
+ @images_dir = Pathname.new( File.join(dir, 'images') )
31
+ @stylesheets_dir = Pathname.new( File.join(dir, 'stylesheets') )
14
32
 
15
- def initialize(dir)
16
- @layouts_dir = File.join(dir, '_layouts')
17
- @config_dir = File.join(dir, '_config')
18
- @input_dir = File.join(dir, '')
19
- @output_dir = File.join(dir, '_site')
20
- @extension_dir = File.join(dir, '_ext')
21
- @skin_dir = File.join(dir, '_skin')
22
- @tmp_dir = File.join(dir, '_tmp')
23
33
  @ignore = File.exists?(ignore_file = File.join(dir, ".awestruct_ignore")) ? Dir[*IO.read(ignore_file).each_line.map(&:strip)] : []
34
+
35
+ @track_dependencies = false
24
36
  end
25
37
 
26
38
  end
@@ -0,0 +1,22 @@
1
+
2
+ require 'awestruct/astruct'
3
+
4
+ module Awestruct
5
+
6
+ class Context < Awestruct::AStruct
7
+ attr_accessor :site
8
+ attr_accessor :page
9
+
10
+ def initialize(hash)
11
+ super
12
+ @page = hash[:page]
13
+ @site = hash[:site]
14
+
15
+ end
16
+
17
+ def inspect
18
+ "Awestruct::Context{:page=>#{self.page.inspect}}"
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,102 @@
1
+
2
+ module Awestruct
3
+ class Dependencies
4
+
5
+ attr_reader :page
6
+ attr_reader :dependencies
7
+ attr_reader :dependents
8
+
9
+
10
+ def self.top_page
11
+ @pages ||= []
12
+ @pages.first
13
+ end
14
+
15
+ def self.push_page(page)
16
+ if ( top_page.nil? )
17
+ page.dependencies.clear
18
+ else
19
+ top_page.dependencies.add_dependency( page )
20
+ end
21
+ @pages.push( page )
22
+ end
23
+
24
+ def self.pop_page
25
+ page = @pages.pop
26
+ if ( @pages.empty? && ! page.nil? )
27
+ page.dependencies.persist!
28
+ end
29
+ end
30
+
31
+
32
+ def self.track_dependency(dep)
33
+ return if top_page.nil?
34
+ return if top_page == dep
35
+ top_page.dependencies.add_dependency(dep)
36
+ end
37
+
38
+ def initialize(page)
39
+ @page = page
40
+ @dependencies = Set.new
41
+ @dependents = Set.new
42
+ end
43
+
44
+ def <<(dep)
45
+ add_dependency( dep )
46
+ end
47
+
48
+ def add_dependency(dep)
49
+ return if @page.do_not_track_dependencies
50
+ return if @page.output_path.nil?
51
+ return if dep == @page
52
+ @dependencies << dep
53
+ dep.dependencies.add_dependent( page )
54
+ end
55
+
56
+ def add_dependent(dep)
57
+ @dependents << dep
58
+ end
59
+
60
+ def remove_dependent(dep)
61
+ @dependents.delete( dep )
62
+ end
63
+
64
+ def clear
65
+ @dependencies.clear
66
+ @dependents.each{|d| d.remove_dependent( page ) }
67
+ end
68
+
69
+ def persist!
70
+ return if page.output_path.nil? || page.output_path == ''
71
+ file = File.join( @page.site.config.dir, '.awestruct', 'dependency-cache', page.output_path )
72
+ FileUtils.mkdir_p( File.dirname( file ) )
73
+ File.open( file, 'w' ) do |file|
74
+ @dependencies.collect{|e| e.relative_source_path }.uniq.each do |d|
75
+ file.puts d unless d.nil?
76
+ end
77
+ end
78
+ end
79
+
80
+ def load!
81
+ return if page.output_path.nil? || page.output_path == ''
82
+ file = File.join( @page.site.config.dir, '.awestruct', 'dependency-cache', page.output_path )
83
+ #puts "load #{file}"
84
+ if ( File.exist?( file ) )
85
+ File.open( file, 'r' ) do |file|
86
+ file.lines.each do |line|
87
+ d = find_page_by_path( line.strip )
88
+ add_dependency( d ) unless d.nil?
89
+ end
90
+ end
91
+ return true
92
+ end
93
+ false
94
+ end
95
+
96
+ def find_page_by_path(path)
97
+ page.site.pages_by_relative_source_path[ path ]
98
+ end
99
+
100
+
101
+ end
102
+ end
@@ -0,0 +1,61 @@
1
+ require 'awestruct/deployers'
2
+
3
+ module Awestruct
4
+ module Deploy
5
+
6
+ class GitHubPagesDeploy
7
+ def initialize( site_config, deploy_config )
8
+ @site_path = site_config.output_dir
9
+ @branch = deploy_config[ 'branch' ] || 'gh-pages'
10
+ end
11
+
12
+ def run
13
+ git.status.changed.empty? ? publish_site : message_for(:existing_changes)
14
+ end
15
+
16
+ private
17
+ def git
18
+ @git ||= Git.open('.')
19
+ end
20
+
21
+ def publish_site
22
+ current_branch = git.branch
23
+ checkout_pages_branch
24
+ add_and_commit_site @site_path
25
+ push_and_restore current_branch
26
+ end
27
+
28
+ def checkout_pages_branch
29
+ git.branch( @branch ).checkout
30
+ end
31
+
32
+ def add_and_commit_site( path )
33
+ git.with_working( path ) do
34
+ git.add(".")
35
+ begin
36
+ git.commit("Published #{@branch} to GitHub pages.")
37
+ rescue Git::GitExecuteError => e
38
+ $stderr.puts "Can't commit. #{e}."
39
+ end
40
+ end
41
+ end
42
+
43
+ def push_and_restore( original_branch )
44
+ git.reset_hard
45
+ git.push( 'origin', @branch )
46
+ git.checkout( original_branch )
47
+ end
48
+
49
+ def message_for( key )
50
+ $stderr.puts case key
51
+ when :existing_changes
52
+ "You have uncommitted changes in the working branch. Please commit or stash them."
53
+ else
54
+ "An error occured."
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ Awestruct::Deployers.instance[ :github_pages ] = Awestruct::Deploy::GitHubPagesDeploy