awestruct 0.5.4.beta1 → 0.5.4.rc

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 (58) hide show
  1. data/lib/awestruct/cli/deploy.rb +2 -2
  2. data/lib/awestruct/cli/generate.rb +3 -3
  3. data/lib/awestruct/cli/init.rb +1 -1
  4. data/lib/awestruct/cli/invoker.rb +11 -10
  5. data/lib/awestruct/cli/manifest.rb +1 -1
  6. data/lib/awestruct/cli/options.rb +16 -6
  7. data/lib/awestruct/cli/server.rb +4 -1
  8. data/lib/awestruct/compatibility.rb +5 -0
  9. data/lib/awestruct/config/default-site.yml +7 -0
  10. data/lib/awestruct/deploy/base_deploy.rb +74 -7
  11. data/lib/awestruct/deploy/github_pages_deploy.rb +20 -7
  12. data/lib/awestruct/deploy/rsync_deploy.rb +1 -1
  13. data/lib/awestruct/deploy/s3_deploy.rb +1 -1
  14. data/lib/awestruct/engine.rb +34 -30
  15. data/lib/awestruct/frameworks/base_Rakefile +22 -3
  16. data/lib/awestruct/handlers/asciidoctor_handler.rb +38 -10
  17. data/lib/awestruct/handlers/front_matter_handler.rb +18 -13
  18. data/lib/awestruct/handlers/interpolation_handler.rb +1 -1
  19. data/lib/awestruct/handlers/template/asciidoc.rb +22 -1
  20. data/lib/awestruct/page_loader.rb +1 -1
  21. data/lib/awestruct/version.rb +1 -1
  22. data/spec/asciidoc_handler_spec.rb +51 -1
  23. data/spec/awestruct/scm/git_spec.rb +2 -2
  24. data/spec/coffeescript_handler_spec.rb +1 -3
  25. data/spec/deploy_spec.rb +66 -1
  26. data/spec/engine_spec.rb +10 -6
  27. data/spec/erb_handler_spec.rb +4 -6
  28. data/spec/front_matter_handler_spec.rb +14 -0
  29. data/spec/github_pages_deploy_spec.rb +14 -9
  30. data/spec/haml_handler_spec.rb +2 -5
  31. data/spec/invoker_spec.rb +1 -0
  32. data/spec/javascript_handler_spec.rb +3 -6
  33. data/spec/markdown_handler_spec.rb +0 -2
  34. data/spec/mustache_handler_spec.rb +5 -8
  35. data/spec/orgmode_handler_spec.rb +1 -3
  36. data/spec/page_loader_spec.rb +18 -0
  37. data/spec/redirect_handler_spec.rb +2 -6
  38. data/spec/restructuredtext_handler_spec.rb +1 -3
  39. data/spec/sass_handler_spec.rb +1 -3
  40. data/spec/scss_handler_spec.rb +1 -3
  41. data/spec/slim_handler_spec.rb +2 -5
  42. data/spec/support/shared_handler_example.rb +18 -10
  43. data/spec/test-data/engine/_config/site.yml +2 -0
  44. data/spec/test-data/front-matter-file-no-content.txt +1 -0
  45. data/spec/test-data/front-matter-looking.txt +9 -0
  46. data/spec/test-data/front-matter-middle.txt +12 -0
  47. data/spec/test-data/gzip/no.html.gz +0 -0
  48. data/spec/test-data/gzip/no.txt +0 -0
  49. data/spec/test-data/gzip/subdir/yes.css +3 -0
  50. data/spec/test-data/gzip/yes.html +10 -0
  51. data/spec/test-data/gzip/yes.js +1 -0
  52. data/spec/test-data/handlers/asciidoc_with_attributes.ad +3 -0
  53. data/spec/test-data/handlers/asciidoc_with_interpolation.ad +4 -0
  54. data/spec/test-data/handlers/asciidoc_without_interpolation.ad +3 -0
  55. data/spec/test-data/handlers/asciidoctor_with_headers.ad +7 -4
  56. data/spec/test-data/handlers/textile-page.textile +3 -1
  57. data/spec/textile_handler_spec.rb +16 -6
  58. metadata +28 -7
@@ -14,7 +14,7 @@ module Awestruct
14
14
  @site_config = site_config
15
15
  @deploy_config = deploy_config
16
16
  @deploy_config['type'] ||= (is_github? ? :github_pages : :rsync)
17
- $LOG.info "Deploying to #{deploy_type}" if $LOG.info?
17
+ $LOG.info "Deploying to #{deploy_type}" if $LOG.info?
18
18
  end
19
19
 
20
20
  def deploy_type
@@ -31,7 +31,7 @@ module Awestruct
31
31
  end
32
32
 
33
33
  deployer = deployer_class.new( site_config, deploy_config )
34
- deployer.run(deploy_config)
34
+ deployer.run
35
35
  end
36
36
 
37
37
  private
@@ -5,7 +5,7 @@ module Awestruct
5
5
  module CLI
6
6
  class Generate
7
7
 
8
- def initialize(config, profile=nil, base_url=nil, default_base_url='http://localhost:4242', force=false)
8
+ def initialize(config, profile=nil, base_url=nil, default_base_url=Options::DEFAULT_BASE_URL, force=false)
9
9
  @profile = profile
10
10
  @base_url = base_url
11
11
  @default_base_url = default_base_url
@@ -15,9 +15,9 @@ module Awestruct
15
15
 
16
16
  def run()
17
17
  begin
18
- base_url = @profile['base_url'] || @default_base_url
18
+ base_url = @base_url || @default_base_url
19
19
  $LOG.info "Generating site: #{base_url}" if $LOG.info?
20
- @engine.run( @profile, @base_url, ( @profile ? @profile['base_url'] || @default_base_url : @default_base_url ), @force )
20
+ @engine.run( @profile, @base_url, @default_base_url, @force )
21
21
  rescue =>e
22
22
  $LOG.error e if $LOG.error?
23
23
  $LOG.error e.backtrace.join("\n") if $LOG.error?
@@ -22,7 +22,7 @@ module Awestruct
22
22
  mkdir('stylesheets')
23
23
  }
24
24
 
25
- def initialize(opts = Awestruct::CLI::Options.new, framework = 'compass', scaffold = true)
25
+ def initialize(dir = Dir.pwd, framework = 'compass', scaffold = true)
26
26
  @dir = dir
27
27
  @framework = framework
28
28
  @scaffold = scaffold
@@ -1,13 +1,7 @@
1
- require 'awestruct/cli/options'
2
-
3
- require 'awestruct/cli/init'
4
- require 'awestruct/cli/generate'
5
- require 'awestruct/cli/auto'
6
- require 'awestruct/cli/server'
7
- require 'awestruct/logger'
8
-
9
1
  require 'pathname'
10
2
  require 'logger'
3
+ require 'awestruct/logger'
4
+ require 'awestruct/cli/options'
11
5
 
12
6
  module Awestruct
13
7
  module CLI
@@ -34,6 +28,12 @@ module Awestruct
34
28
  $LOG = Logger.new(Awestruct::AwestructLoggerMultiIO.new(@options.verbose, STDOUT, File.open('.awestruct/debug.log', 'w')))
35
29
  $LOG.level = @options.verbose ? Logger::DEBUG : Logger::INFO
36
30
  $LOG.formatter = Awestruct::AwestructLogFormatter.new
31
+
32
+ # these requires are deferred until after $LOG is set
33
+ require 'awestruct/cli/init'
34
+ require 'awestruct/cli/generate'
35
+ require 'awestruct/cli/auto'
36
+ require 'awestruct/cli/server'
37
37
  end
38
38
 
39
39
  def invoke!
@@ -100,7 +100,8 @@ module Awestruct
100
100
  end
101
101
 
102
102
  def invoke_generate()
103
- @success = Awestruct::CLI::Generate.new( config, options.profile, options.base_url, 'http://localhost:4242', options.force ).run
103
+ base_url = profile['base_url'] || options.base_url
104
+ @success = Awestruct::CLI::Generate.new( config, options.profile, base_url, Options::DEFAULT_BASE_URL, options.force ).run
104
105
  end
105
106
 
106
107
  def invoke_deploy()
@@ -121,7 +122,7 @@ module Awestruct
121
122
  end
122
123
 
123
124
  def invoke_server()
124
- run_in_thread( Awestruct::CLI::Server.new( './_site', options.bind_addr, options.port ) )
125
+ run_in_thread( Awestruct::CLI::Server.new( options.output_dir, options.bind_addr, options.port ) )
125
126
  end
126
127
 
127
128
 
@@ -29,7 +29,7 @@ class Compass::AppIntegration::StandAlone::Installer
29
29
 
30
30
  rake
31
31
 
32
- then visit your site at: http://localhost:4242
32
+ then visit your site at: #{::Awestruct::CLI::Options::DEFAULT_BASE_URL}
33
33
  END
34
34
  end
35
35
  end
@@ -6,6 +6,16 @@ module Awestruct
6
6
  module CLI
7
7
 
8
8
  class Options
9
+ LOCAL_HOSTS = {
10
+ 'localhost' => 'localhost',
11
+ '0.0.0.0' => 'localhost',
12
+ '127.0.0.1' => 'localhost',
13
+ '::1' => '[::1]',
14
+ 'localhost6' => 'localhost6'
15
+ }
16
+ DEFAULT_BIND_ADDR = '0.0.0.0'
17
+ DEFAULT_PORT = 4242
18
+ DEFAULT_BASE_URL = %(http://#{LOCAL_HOSTS[DEFAULT_BIND_ADDR] || DEFAULT_BIND_ADDR}:#{DEFAULT_PORT})
9
19
 
10
20
  attr_accessor :generate
11
21
  attr_accessor :server
@@ -27,8 +37,8 @@ module Awestruct
27
37
  def initialize()
28
38
  @generate = nil
29
39
  @server = false
30
- @port = 4242
31
- @bind_addr = '0.0.0.0'
40
+ @port = DEFAULT_PORT
41
+ @bind_addr = DEFAULT_BIND_ADDR
32
42
  @auto = false
33
43
  @force = false
34
44
  @init = false
@@ -71,10 +81,10 @@ module Awestruct
71
81
  opts.on( '-u', '--url URL', 'Set site.base_url' ) do |url|
72
82
  self.base_url = url
73
83
  end
74
- opts.on( '-d', '--dev', 'Run site in development mode (--auto, --server, --port 4242 and --profile development)' ) do |url|
84
+ opts.on( '-d', '--dev', "Run site in development mode (--auto, --server, --port #{DEFAULT_PORT} and --profile development)" ) do |url|
75
85
  self.server = true
76
86
  self.auto = true
77
- self.port = 4242
87
+ self.port = DEFAULT_PORT
78
88
  self.profile = 'development'
79
89
  end
80
90
 
@@ -90,10 +100,10 @@ module Awestruct
90
100
  opts.on( '-a', '--auto', 'Auto-generate when changes are noticed' ) do |a|
91
101
  self.auto = a
92
102
  end
93
- opts.on( '-p', '--port PORT', Integer, 'Server port (default: 4242)' ) do |port|
103
+ opts.on( '-p', '--port PORT', Integer, "Server port (default: #{DEFAULT_PORT})" ) do |port|
94
104
  self.port = port
95
105
  end
96
- opts.on( '-b', '--bind ADDR', 'Server address (default: 0.0.0.0)' ) do |bind_addr|
106
+ opts.on( '-b', '--bind ADDR', "Server address (default: #{DEFAULT_BIND_ADDR})" ) do |bind_addr|
97
107
  self.bind_addr = bind_addr
98
108
  end
99
109
  opts.on( '-g', '--[no-]generate', 'Generate site' ) do |g|
@@ -7,13 +7,16 @@ module Awestruct
7
7
  class Server
8
8
  attr_reader :server
9
9
 
10
- def initialize(path, bind_addr='0.0.0.0', port=4242)
10
+ def initialize(path, bind_addr=Options::DEFAULT_BIND_ADDR, port=Options::DEFAULT_PORT)
11
11
  @path = path
12
12
  @bind_addr = bind_addr
13
13
  @port = port
14
14
  end
15
15
 
16
16
  def run
17
+ url = %(http://#{Options::LOCAL_HOSTS[@bind_addr] || @bind_addr}:#{@port})
18
+ msg = %(Starting preview server at #{url} (Press Ctrl-C to shutdown))
19
+ puts %(#{'*' * msg.length}\n#{msg}\n#{'*' * msg.length}\n)
17
20
  ::Rack::Server::start( :app => Awestruct::Rack::App.new( @path ),
18
21
  :Port => @port,
19
22
  :Host => @bind_addr
@@ -0,0 +1,5 @@
1
+ unless File.respond_to?(:binread)
2
+ def File.binread(file)
3
+ File.open(file,"rb") { |f| f.read }
4
+ end
5
+ end
@@ -30,3 +30,10 @@ asciidoctor:
30
30
  :attributes:
31
31
  imagesdir: /images
32
32
  stylesdir: /stylesheets
33
+
34
+ textile:
35
+ :no_span_caps: true
36
+
37
+ profiles:
38
+ development:
39
+ show_drafts: true
@@ -1,5 +1,6 @@
1
1
  require 'awestruct/deployers'
2
- Dir[ File.join( File.dirname(__FILE__), '..', 'scm' '*.rb' ) ].each do |f|
2
+ require 'awestruct/compatibility'
3
+ Dir[ File.join( File.dirname(__FILE__), '..', 'scm', '*.rb' ) ].each do |f|
3
4
  begin
4
5
  require f
5
6
  rescue LoadError => e
@@ -12,14 +13,27 @@ module Awestruct
12
13
  module Deploy
13
14
  class Base
14
15
  UNCOMMITTED_CHANGES = 'You have uncommitted changes in the working branch. Please commit or stash them.'
15
- def run(deploy_config)
16
- if deploy_config['uncommitted'] == true
16
+
17
+ def initialize(site_config, deploy_config)
18
+ # Add a single front slash at the end of output dir
19
+ @site_path = File.join( site_config.output_dir, '/' ).gsub(/^\w:\//, '/')
20
+ @gzip = deploy_config['gzip']
21
+ @source_dir = deploy_config['source_dir'] || site_config.dir
22
+ @ignore_uncommitted = deploy_config['uncommitted']
23
+ init_scm(deploy_config['scm'] || 'git')
24
+ end
25
+
26
+ def run
27
+ if @ignore_uncommitted == true
28
+ compress_site
17
29
  publish_site
18
30
  else
19
- scm = deploy_config['scm'] || 'git'
20
- #require "awestruct/scm/#{scm}"
21
- scm_class = Object.const_get('Awestruct').const_get('Scm').const_get(scm.slice(0, 1).capitalize + scm.slice(1..-1))
22
- scm_class.new.uncommitted_changes?(deploy_config['source_dir']) ? existing_changes() : publish_site()
31
+ if @scm.uncommitted_changes? @source_dir
32
+ existing_changes
33
+ else
34
+ compress_site
35
+ publish_site
36
+ end
23
37
  end
24
38
  end
25
39
 
@@ -30,6 +44,59 @@ module Awestruct
30
44
  def existing_changes
31
45
  $LOG.error UNCOMMITTED_CHANGES if $LOG.error?
32
46
  end
47
+
48
+ def compress_site
49
+ if @gzip
50
+ gzip_site @site_path
51
+ end
52
+ end
53
+
54
+ def gzip_site(site_path)
55
+ Dir.glob("#{site_path}/**/*") do |item|
56
+ next if item == '.' or item == '..'
57
+ ext = File.extname(item)
58
+ if !ext.empty?
59
+ ext_sym = ext[1..-1].to_sym
60
+ case ext_sym
61
+ when :css, :js, :html
62
+ require 'zlib'
63
+ if !is_gzipped item
64
+ gzip_file item
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ def gzip_file(filename)
72
+ $LOG.debug "Gzipping File #{filename}"
73
+ Zlib::GzipWriter.open("#{filename}.gz") do |gz|
74
+ gz.mtime = File.mtime(filename)
75
+ gz.orig_name = filename
76
+ gz.write File.binread(filename)
77
+ end
78
+ File.rename("#{filename}.gz", "#{filename}")
79
+ end
80
+
81
+ def is_gzipped(filename)
82
+ begin
83
+ File.open("#{filename}") do |f|
84
+ Zlib::GzipReader.new(f)
85
+ true
86
+ end
87
+ rescue
88
+ false
89
+ end
90
+ end
91
+
92
+ def init_scm type
93
+ begin
94
+ clazz = Object.const_get('Awestruct').const_get('Scm').const_get(type.capitalize)
95
+ @scm = clazz.new
96
+ rescue
97
+ $LOG.error( "Could not resolve class for scm type: #{type}" ) if $LOG.error?
98
+ end
99
+ end
33
100
  end
34
101
  end
35
102
  end
@@ -5,22 +5,35 @@ module Awestruct
5
5
  module Deploy
6
6
  class GitHubPagesDeploy < Base
7
7
  def initialize(site_config, deploy_config)
8
- @site_path = site_config.output_dir
8
+ super
9
9
  @branch = deploy_config['branch'] || 'gh-pages'
10
10
  @repo = deploy_config['repository'] || 'origin'
11
11
  end
12
12
 
13
13
  def publish_site
14
- current_branch = git.current_branch
15
- # we may be on a detached branch,
16
- # in which case use that commit as the branch
17
- if current_branch == '(no branch)'
18
- current_branch = git.revparse('HEAD')
14
+ tmp_branch = '__awestruct_deploy__'
15
+ detached_branch = nil
16
+
17
+ original_branch = git.current_branch
18
+
19
+ # detect a detached state
20
+ # values include (no branch), (detached from x), etc
21
+ if original_branch.start_with? '('
22
+ detached_branch = git.log(1).first.sha
23
+ git.branch(original_branch = tmp_branch).checkout
19
24
  end
25
+
26
+ # work in a branch, then revert to current branch
20
27
  git.branch(@branch).checkout
21
28
  add_and_commit_site @site_path
22
29
  git.push(@repo, @branch)
23
- git.checkout(current_branch)
30
+
31
+ if detached_branch
32
+ git.checkout detached_branch
33
+ git.branch(original_branch).delete
34
+ else
35
+ git.checkout original_branch
36
+ end
24
37
  end
25
38
 
26
39
  private
@@ -7,7 +7,7 @@ module Awestruct
7
7
  class RSyncDeploy < Base
8
8
 
9
9
  def initialize(site_config, deploy_config)
10
- @site_path = File.join( site_config.output_dir, '/' ).gsub(/^\w:\//, '/')
10
+ super
11
11
  @host = deploy_config['host']
12
12
  @path = File.join( deploy_config['path'], '/' )
13
13
  @exclude = deploy_config['exclude']
@@ -5,7 +5,7 @@ module Awestruct
5
5
  module Deploy
6
6
  class S3Deploy < Base
7
7
  def initialize( site_config, deploy_config )
8
- @site_path = site_config.output_dir
8
+ super
9
9
  @bucket = deploy_config['bucket']
10
10
  end
11
11
 
@@ -51,9 +51,9 @@ module Awestruct
51
51
  $LOG.debug 'adjust_load_path' if $LOG.debug?
52
52
  adjust_load_path
53
53
  $LOG.debug 'load_default_site_yaml' if $LOG.debug?
54
- load_default_site_yaml
55
- $LOG.debug 'load_site_yaml -- profile' if $LOG.debug?
56
- load_site_yaml(profile)
54
+ load_default_site_yaml( profile )
55
+ $LOG.debug 'load_user_site_yaml -- profile' if $LOG.debug?
56
+ load_user_site_yaml( profile )
57
57
  $LOG.debug 'set_base_url' if $LOG.debug?
58
58
  set_base_url( base_url, default_base_url )
59
59
  $LOG.debug 'load_yamls' if $LOG.debug?
@@ -105,35 +105,14 @@ module Awestruct
105
105
 
106
106
  end
107
107
 
108
- def load_default_site_yaml
109
- default_site_yaml = File.join( File.dirname( __FILE__ ), 'config', 'default-site.yml' )
110
- if ( File.exist?( default_site_yaml ) )
111
- data = YAML.load( File.read( default_site_yaml ) )
112
- data.each do |k,v|
113
- site.send( "#{k}=", v )
114
- end if data
115
- end
108
+ def load_default_site_yaml(profile = nil)
109
+ default_site_yaml_path = File.join( File.dirname( __FILE__ ), 'config', 'default-site.yml' )
110
+ load_site_yaml( default_site_yaml_path, profile )
116
111
  end
117
112
 
118
- def load_site_yaml(profile)
119
- site_yaml = File.join( site.config.config_dir, 'site.yml' )
120
- if ( File.exist?( site_yaml ) )
121
- data = YAML.load( File.read( site_yaml ) )
122
- site.interpolate = true
123
- profile_data = {}
124
- data.each do |k,v|
125
- if ( ( k == 'profiles' ) && ( ! profile.nil? ) )
126
- profile_data = ( v[profile] || {} )
127
- else
128
- site.send( "#{k}=", merge_data( site.send( "#{k}" ), v ) )
129
- end
130
- end if data
131
- site.profile = profile
132
-
133
- profile_data.each do |k,v|
134
- site.send( "#{k}=", merge_data( site.send( "#{k}" ), v ) )
135
- end
136
- end
113
+ def load_user_site_yaml(profile = nil)
114
+ site_yaml_path = File.join( site.config.config_dir, 'site.yml' )
115
+ load_site_yaml( site_yaml_path, profile )
137
116
  end
138
117
 
139
118
  def load_yamls
@@ -142,6 +121,31 @@ module Awestruct
142
121
  end
143
122
  end
144
123
 
124
+ def load_site_yaml(yaml_path, profile = nil)
125
+ if ( File.exist?( yaml_path ) )
126
+ data = YAML.load( File.read( yaml_path ) )
127
+ if ( profile )
128
+ site.interpolate = true
129
+ profile_data = {}
130
+ data.each do |k,v|
131
+ if ( ( k == 'profiles' ) && ( ! profile.nil? ) )
132
+ profile_data = ( v[profile] || {} )
133
+ else
134
+ site.send( "#{k}=", merge_data( site.send( "#{k}" ), v ) )
135
+ end
136
+ end if data
137
+ site.profile = profile
138
+ profile_data.each do |k,v|
139
+ site.send( "#{k}=", merge_data( site.send( "#{k}" ), v ) )
140
+ end
141
+ else
142
+ data.each do |k,v|
143
+ site.send( "#{k}=", v )
144
+ end if data
145
+ end
146
+ end
147
+ end
148
+
145
149
  def load_yaml(yaml_path)
146
150
  data = YAML.load( File.read( yaml_path ) )
147
151
  name = File.basename( yaml_path, '.yml' )