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
@@ -0,0 +1,42 @@
1
+
2
+ require 'awestruct/handlers/base_handler'
3
+
4
+ require 'compass'
5
+ require 'ninesixty'
6
+ require 'bootstrap-sass'
7
+
8
+ module Awestruct
9
+ module Handlers
10
+ class BaseSassHandler < BaseHandler
11
+
12
+ attr_reader :syntax
13
+
14
+ def initialize(site, delegate, syntax)
15
+ super( site, delegate )
16
+ @syntax = syntax
17
+ end
18
+
19
+ def simple_name
20
+ File.basename( relative_source_path, ".#{syntax}" )
21
+ end
22
+
23
+ def output_filename
24
+ simple_name + '.css'
25
+ end
26
+
27
+ def rendered_content(context, with_layouts=true)
28
+ sass_opts = Compass.sass_engine_options
29
+ sass_opts[:load_paths] ||= []
30
+ Compass::Frameworks::ALL.each do |framework|
31
+ sass_opts[:load_paths] << framework.stylesheets_directory
32
+ end
33
+ sass_opts[:load_paths] << File.dirname( context.page.source_path )
34
+ sass_opts[:syntax] = syntax
35
+ sass_opts[:custom] = site
36
+ sass_engine = Sass::Engine.new( raw_content, sass_opts )
37
+ sass_engine.render
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,48 @@
1
+
2
+ require 'awestruct/handler_chain'
3
+ require 'awestruct/handlers/base_handler'
4
+ require 'awestruct/handlers/file_handler'
5
+ require 'awestruct/handlers/front_matter_handler'
6
+ require 'awestruct/handlers/interpolation_handler'
7
+
8
+ require 'coffee-script'
9
+
10
+ module Awestruct
11
+ module Handlers
12
+ class CoffeescriptHandler < BaseHandler
13
+
14
+
15
+ CHAIN = Awestruct::HandlerChain.new( /\.coffee$/,
16
+ Awestruct::Handlers::FileHandler,
17
+ Awestruct::Handlers::FrontMatterHandler,
18
+ Awestruct::Handlers::InterpolationHandler,
19
+ Awestruct::Handlers::CoffeescriptHandler
20
+ )
21
+
22
+ def initialize(site, delegate)
23
+ super( site, delegate )
24
+ end
25
+
26
+ def simple_name
27
+ File.basename( relative_source_path, '.coffee' )
28
+ end
29
+
30
+ def output_filename
31
+ File.basename( relative_source_path, '.coffee' ) + '.js'
32
+ end
33
+
34
+ def output_extension
35
+ '.js'
36
+ end
37
+
38
+ def content_syntax
39
+ :coffeescript
40
+ end
41
+
42
+ def rendered_content(context, with_layouts=true)
43
+ CoffeeScript.compile( delegate.rendered_content( context, with_layouts ) )
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,44 @@
1
+
2
+ require 'awestruct/handlers/base_handler'
3
+ require 'awestruct/handlers/file_handler'
4
+ require 'awestruct/handlers/front_matter_handler'
5
+ require 'awestruct/handlers/layout_handler'
6
+
7
+ module Awestruct
8
+ module Handlers
9
+ class ErbHandler < BaseHandler
10
+
11
+ CHAIN = Awestruct::HandlerChain.new( /\.erb$/,
12
+ Awestruct::Handlers::FileHandler,
13
+ Awestruct::Handlers::FrontMatterHandler,
14
+ Awestruct::Handlers::ErbHandler,
15
+ Awestruct::Handlers::LayoutHandler
16
+ )
17
+
18
+ def initialize(site, delegate)
19
+ super( site, delegate )
20
+ end
21
+
22
+ def simple_name
23
+ File.basename( File.basename( relative_source_path, '.erb' ), output_extension )
24
+ end
25
+
26
+ def output_filename
27
+ File.basename( relative_source_path, '.erb' )
28
+ end
29
+
30
+ def output_extension
31
+ File.extname( output_filename )
32
+ end
33
+
34
+ def content_syntax
35
+ :erb
36
+ end
37
+
38
+ def rendered_content(context, with_layouts=true)
39
+ erb = ERB.new( delegate.rendered_content( context, with_layouts) )
40
+ erb.result( context.send( :binding ) )
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,64 @@
1
+ require 'awestruct/handlers/base_handler'
2
+
3
+ module Awestruct
4
+ module Handlers
5
+ class FileHandler < BaseHandler
6
+
7
+ attr_accessor :path
8
+
9
+ def initialize(site, path)
10
+ super( site )
11
+ case ( path )
12
+ when Pathname
13
+ @path = path
14
+ else
15
+ @path = Pathname.new( path.to_s )
16
+ end
17
+ end
18
+
19
+ def output_filename
20
+ File.basename( @path )
21
+ end
22
+
23
+ def relative_source_path
24
+ begin
25
+ p = path.relative_path_from( site.dir )
26
+ if !! ( %r(^\.\.) =~ p.to_s )
27
+ return nil
28
+ end
29
+ r = File.join( '', p )
30
+ return r
31
+ rescue Exception=>e
32
+ nil
33
+ end
34
+ end
35
+
36
+ def stale?
37
+ return true if ( @content.nil? || ( File.mtime( @path ) > @mtime ) )
38
+ false
39
+ end
40
+
41
+ def input_mtime(page)
42
+ path.mtime
43
+ end
44
+
45
+ def raw_content
46
+ read
47
+ @content
48
+ end
49
+
50
+ def rendered_content(context, with_layouts=true)
51
+ raw_content
52
+ end
53
+
54
+ private
55
+
56
+ def read
57
+ ( @content = File.read( @path ) ) if stale?
58
+ @mtime = File.mtime( @path )
59
+ return @content
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,85 @@
1
+ require 'awestruct/handlers/base_handler'
2
+
3
+ require 'yaml'
4
+
5
+ module Awestruct
6
+ module Handlers
7
+ class FrontMatterHandler < BaseHandler
8
+
9
+ def initialize(site, delegate)
10
+ super
11
+ @parsed_parts = false
12
+ end
13
+
14
+ def front_matter
15
+ parse_parts()
16
+ @front_matter
17
+ end
18
+
19
+ def raw_content
20
+ parse_parts()
21
+ @raw_content
22
+ end
23
+
24
+ def rendered_content(context, with_layouts)
25
+ parse_parts()
26
+ @raw_content
27
+ end
28
+
29
+ def content_line_offset
30
+ parse_parts()
31
+ @content_line_offset
32
+ end
33
+
34
+ def inherit_front_matter(page)
35
+ page.inherit_front_matter_from( front_matter )
36
+ super
37
+ end
38
+
39
+ private
40
+
41
+ def parse_parts
42
+ return if ( @parsed_parts && ! delegate.stale? )
43
+
44
+ full_content = delegate.raw_content
45
+ full_content.force_encoding(site.encoding) if site.encoding
46
+ yaml_content = ''
47
+
48
+ dash_lines = 0
49
+ mode = :yaml
50
+
51
+ @raw_content = ''
52
+ @content_line_offset = 0
53
+
54
+ full_content.each_line do |line|
55
+ if ( line.strip == '---' )
56
+ dash_lines = dash_lines +1
57
+ end
58
+ if ( mode == :yaml )
59
+ @content_line_offset += 1
60
+ yaml_content << line
61
+ else
62
+ @raw_content << line
63
+ end
64
+ if ( dash_lines == 2 )
65
+ mode = :page
66
+ end
67
+ end
68
+
69
+ if ( dash_lines == 0 )
70
+ @raw_content = yaml_content
71
+ yaml_content = ''
72
+ @content_line_offset = 0
73
+ elsif ( mode == :yaml )
74
+ @raw_content = nil
75
+ @content_line_offset = -1
76
+ end
77
+
78
+ @front_matter = YAML.load( yaml_content ) || {}
79
+ @parsed_parts = true
80
+
81
+ end
82
+
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,54 @@
1
+
2
+ require 'awestruct/handler_chain'
3
+ require 'awestruct/handlers/base_handler'
4
+ require 'awestruct/handlers/file_handler'
5
+ require 'awestruct/handlers/front_matter_handler'
6
+ require 'awestruct/handlers/layout_handler'
7
+
8
+ require 'haml'
9
+
10
+ module Awestruct
11
+ module Handlers
12
+ class HamlHandler < BaseHandler
13
+
14
+ CHAIN = Awestruct::HandlerChain.new( /\.haml$/,
15
+ Awestruct::Handlers::FileHandler,
16
+ Awestruct::Handlers::FrontMatterHandler,
17
+ Awestruct::Handlers::HamlHandler,
18
+ Awestruct::Handlers::LayoutHandler
19
+ )
20
+
21
+ def initialize(site, delegate)
22
+ super( site, delegate )
23
+ end
24
+
25
+ def simple_name
26
+ File.basename( self.path, "#{output_extension}.haml" )
27
+ end
28
+
29
+ def output_filename
30
+ return File.basename( relative_source_path, '.haml' ) unless relative_source_path.nil?
31
+ nil
32
+ end
33
+
34
+ def output_extension
35
+ File.extname( File.basename( path, '.haml' ) )
36
+ end
37
+
38
+ def rendered_content(context, with_layouts=true)
39
+ options = context.site.haml? ? context.site.haml : {}
40
+ options = options.inject({}){ |hash,(key,value)|
41
+ hash[key.to_sym] = value
42
+ hash
43
+ }
44
+ options[:relative_source_path] = context.page.relative_source_path
45
+ options[:filename] = delegate.path.to_s
46
+ options[:line] = delegate.content_line_offset + 1
47
+ options[:site] = context.site
48
+ haml_engine = Haml::Engine.new( delegate.raw_content, options )
49
+ haml_engine.render( context )
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,28 @@
1
+
2
+ require 'awestruct/handlers/base_handler'
3
+
4
+ module Awestruct
5
+ module Handlers
6
+ class InterpolationHandler < BaseHandler
7
+
8
+ def initialize(site, delegate)
9
+ super( site, delegate )
10
+ end
11
+
12
+ def rendered_content(context, with_layouts=true)
13
+ content = delegate.raw_content
14
+
15
+ return nil if content.nil?
16
+ return content unless site.interpolate
17
+
18
+ content = content.gsub( /\\/, '\\\\\\\\' )
19
+ content = content.gsub( /\\\\#/, '\\#' )
20
+ content = content.gsub( '@', '\@' )
21
+ content = "%@#{content}@"
22
+
23
+ context.instance_eval( content )
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,63 @@
1
+
2
+ require 'awestruct/handlers/base_handler'
3
+
4
+ require 'haml'
5
+
6
+ module Awestruct
7
+ module Handlers
8
+ class LayoutHandler < BaseHandler
9
+
10
+ def initialize(site, delegate)
11
+ super( site, delegate )
12
+ end
13
+
14
+ def input_mtime(page)
15
+ t = delegate.input_mtime( page )
16
+ for_layout_chain(page) do |layout|
17
+ layout_mtime = layout.input_mtime
18
+ if ( t == nil )
19
+ t = layout_mtime
20
+ elsif ( layout_mtime > t )
21
+ t = layout_mtime
22
+ end
23
+ end
24
+ page_mtime = delegate.input_mtime( page )
25
+ t
26
+ end
27
+
28
+ def inherit_front_matter(page)
29
+ delegate.inherit_front_matter( page )
30
+ for_layout_chain(page) do |layout|
31
+ page.inherit_front_matter_from( layout )
32
+ end
33
+ end
34
+
35
+ def for_layout_chain(page, &block)
36
+ # puts "for_layout_chain #{page.inspect}"
37
+ current_page = page
38
+ while ( ! ( current_page.nil? || current_page.layout.nil? ) )
39
+ current_page = site.layouts.find_matching( current_page.layout, current_page.output_extension )
40
+ # puts "layout #{current_page.inspect}"
41
+ if ( ! current_page.nil? )
42
+ block.call( current_page )
43
+ end
44
+ end
45
+ end
46
+
47
+ def rendered_content(context, with_layouts=true)
48
+ content = delegate.rendered_content( context, with_layouts )
49
+
50
+ if ( with_layouts )
51
+ for_layout_chain(context.__effective_page || context.page) do |layout|
52
+ context.content = content
53
+ context.__effective_page = layout
54
+ content = layout.rendered_content( context, false )
55
+ end
56
+ end
57
+
58
+ content
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,50 @@
1
+
2
+ require 'awestruct/handler_chain'
3
+ require 'awestruct/handlers/base_handler'
4
+ require 'awestruct/handlers/file_handler'
5
+ require 'awestruct/handlers/front_matter_handler'
6
+ require 'awestruct/handlers/interpolation_handler'
7
+ require 'awestruct/handlers/layout_handler'
8
+ require 'rdiscount'
9
+
10
+ module Awestruct
11
+ module Handlers
12
+ class MarkdownHandler < BaseHandler
13
+
14
+
15
+ CHAIN = Awestruct::HandlerChain.new( /\.md$/,
16
+ Awestruct::Handlers::FileHandler,
17
+ Awestruct::Handlers::FrontMatterHandler,
18
+ Awestruct::Handlers::InterpolationHandler,
19
+ Awestruct::Handlers::MarkdownHandler,
20
+ Awestruct::Handlers::LayoutHandler
21
+ )
22
+
23
+ def initialize(site, delegate)
24
+ super( site, delegate )
25
+ end
26
+
27
+ def simple_name
28
+ File.basename( relative_source_path, '.md' )
29
+ end
30
+
31
+ def output_filename
32
+ File.basename( relative_source_path, '.md' ) + '.html'
33
+ end
34
+
35
+ def output_extension
36
+ '.html'
37
+ end
38
+
39
+ def content_syntax
40
+ :markdown
41
+ end
42
+
43
+ def rendered_content(context, with_layouts=true)
44
+ doc = RDiscount.new( raw_content )
45
+ doc.to_html
46
+ end
47
+
48
+ end
49
+ end
50
+ end