awestructx 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/bin/awestruct +8 -0
  2. data/lib/awestruct/astruct.rb +22 -0
  3. data/lib/awestruct/astruct_mixin.rb +71 -0
  4. data/lib/awestruct/cli/auto.rb +20 -0
  5. data/lib/awestruct/cli/generate.rb +26 -0
  6. data/lib/awestruct/cli/invoker.rb +109 -0
  7. data/lib/awestruct/cli/options.rb +116 -0
  8. data/lib/awestruct/cli/server.rb +24 -0
  9. data/lib/awestruct/config.rb +30 -0
  10. data/lib/awestruct/context.rb +22 -0
  11. data/lib/awestruct/context_helper.rb +68 -0
  12. data/lib/awestruct/engine.rb +254 -0
  13. data/lib/awestruct/extensions/assets.rb +39 -0
  14. data/lib/awestruct/extensions/atomizer.rb +44 -0
  15. data/lib/awestruct/extensions/cachebuster.rb +12 -0
  16. data/lib/awestruct/extensions/coffeescripttransform.rb +42 -0
  17. data/lib/awestruct/extensions/data_dir.rb +31 -0
  18. data/lib/awestruct/extensions/disqus.rb +62 -0
  19. data/lib/awestruct/extensions/extend_string.rb +97 -0
  20. data/lib/awestruct/extensions/flattr.rb +42 -0
  21. data/lib/awestruct/extensions/google_analytics.rb +38 -0
  22. data/lib/awestruct/extensions/gsub.rb +20 -0
  23. data/lib/awestruct/extensions/indexifier.rb +17 -0
  24. data/lib/awestruct/extensions/intense_debate.rb +38 -0
  25. data/lib/awestruct/extensions/minify.rb +178 -0
  26. data/lib/awestruct/extensions/obfuscate.rb +32 -0
  27. data/lib/awestruct/extensions/paginator.rb +105 -0
  28. data/lib/awestruct/extensions/partial.rb +25 -0
  29. data/lib/awestruct/extensions/pipeline.rb +50 -0
  30. data/lib/awestruct/extensions/posts.rb +70 -0
  31. data/lib/awestruct/extensions/relative.rb +11 -0
  32. data/lib/awestruct/extensions/remotePartial.rb +17 -0
  33. data/lib/awestruct/extensions/sitemap.rb +85 -0
  34. data/lib/awestruct/extensions/sitemap.xml.haml +16 -0
  35. data/lib/awestruct/extensions/tag_cloud.html.haml +7 -0
  36. data/lib/awestruct/extensions/tag_cloud.rb +34 -0
  37. data/lib/awestruct/extensions/tagger.rb +107 -0
  38. data/lib/awestruct/extensions/template.atom.haml +39 -0
  39. data/lib/awestruct/handler_chain.rb +28 -0
  40. data/lib/awestruct/handler_chains.rb +65 -0
  41. data/lib/awestruct/handlers/base_handler.rb +92 -0
  42. data/lib/awestruct/handlers/base_sass_handler.rb +42 -0
  43. data/lib/awestruct/handlers/file_handler.rb +61 -0
  44. data/lib/awestruct/handlers/front_matter_handler.rb +80 -0
  45. data/lib/awestruct/handlers/haml_handler.rb +42 -0
  46. data/lib/awestruct/handlers/interpolation_handler.rb +28 -0
  47. data/lib/awestruct/handlers/layout_handler.rb +61 -0
  48. data/lib/awestruct/handlers/markdown_handler.rb +36 -0
  49. data/lib/awestruct/handlers/no_op_handler.rb +34 -0
  50. data/lib/awestruct/handlers/sass_handler.rb +14 -0
  51. data/lib/awestruct/handlers/scss_handler.rb +14 -0
  52. data/lib/awestruct/handlers/string_handler.rb +29 -0
  53. data/lib/awestruct/handlers/textile_handler.rb +43 -0
  54. data/lib/awestruct/handlers/yaml_handler.rb +25 -0
  55. data/lib/awestruct/layouts.rb +15 -0
  56. data/lib/awestruct/page.rb +128 -0
  57. data/lib/awestruct/page_loader.rb +72 -0
  58. data/lib/awestruct/pipeline.rb +49 -0
  59. data/lib/awestruct/site.rb +51 -0
  60. data/lib/awestruct/util/default_inflections.rb +45 -0
  61. data/lib/awestruct/util/inflector.rb +242 -0
  62. data/lib/awestruct/version.rb +4 -0
  63. data/lib/guard/awestruct.rb +38 -0
  64. metadata +427 -0
@@ -0,0 +1,42 @@
1
+
2
+ require 'awestruct/handlers/base_handler'
3
+
4
+ require 'haml'
5
+
6
+ module Awestruct
7
+ module Handlers
8
+ class HamlHandler < BaseHandler
9
+
10
+ def initialize(site, delegate)
11
+ super( site, delegate )
12
+ end
13
+
14
+ def simple_name
15
+ File.basename( self.path, "#{output_extension}.haml" )
16
+ end
17
+
18
+ def output_filename
19
+ File.basename( relative_source_path, '.haml' )
20
+ end
21
+
22
+ def output_extension
23
+ File.extname( File.basename( path, '.haml' ) )
24
+ end
25
+
26
+ def rendered_content(context, with_layouts=true)
27
+ options = context.site.haml? ? context.site.haml : {}
28
+ options = options.inject({}){ |hash,(key,value)|
29
+ hash[key.to_sym] = value
30
+ hash
31
+ }
32
+ options[:relative_source_path] = context.page.relative_source_path
33
+ options[:filename] = delegate.path
34
+ options[:line] = delegate.content_line_offset + 1
35
+ options[:site] = context.site
36
+ haml_engine = Haml::Engine.new( delegate.raw_content, options )
37
+ haml_engine.render( context )
38
+ end
39
+
40
+ end
41
+ end
42
+ 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,61 @@
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
+ current_page = page
37
+ while ( ! ( current_page.nil? || current_page.layout.nil? ) )
38
+ current_page = site.layouts.find_matching( current_page.layout, current_page.output_extension )
39
+ if ( ! current_page.nil? )
40
+ block.call( current_page )
41
+ end
42
+ end
43
+ end
44
+
45
+ def rendered_content(context, with_layouts=true)
46
+ content = delegate.rendered_content( context, with_layouts )
47
+
48
+ if ( with_layouts )
49
+ for_layout_chain(context.__effective_page || context.page) do |layout|
50
+ context.content = content
51
+ context.__effective_page = layout
52
+ content = layout.rendered_content( context, true )
53
+ end
54
+ end
55
+
56
+ content
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,36 @@
1
+
2
+ require 'awestruct/handlers/base_handler'
3
+ require 'rdiscount'
4
+
5
+ module Awestruct
6
+ module Handlers
7
+ class MarkdownHandler < BaseHandler
8
+
9
+ def initialize(site, delegate)
10
+ super( site, delegate )
11
+ end
12
+
13
+ def simple_name
14
+ File.basename( relative_source_path, '.md' )
15
+ end
16
+
17
+ def output_filename
18
+ File.basename( relative_source_path, '.md' ) + '.html'
19
+ end
20
+
21
+ def output_extension
22
+ '.html'
23
+ end
24
+
25
+ def content_syntax
26
+ :markdown
27
+ end
28
+
29
+ def rendered_content(context, with_layouts=true)
30
+ doc = RDiscount.new( raw_content )
31
+ doc.to_html
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,34 @@
1
+
2
+ require 'awestruct/handlers/base_handler'
3
+
4
+ module Awestruct
5
+ module Handlers
6
+ class NoOpHandler < BaseHandler
7
+
8
+ def initialize(site)
9
+ super( site )
10
+ end
11
+
12
+ def output_filename
13
+ nil
14
+ end
15
+
16
+ def relative_source_path
17
+ nil
18
+ end
19
+
20
+ def stale?
21
+ false
22
+ end
23
+
24
+ def raw_content
25
+ nil
26
+ end
27
+
28
+ def rendered_content(context, with_layouts=true)
29
+ nil
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,14 @@
1
+
2
+ require 'awestruct/handlers/base_sass_handler'
3
+
4
+ module Awestruct
5
+ module Handlers
6
+ class SassHandler < BaseSassHandler
7
+
8
+ def initialize(site, delegate)
9
+ super( site, delegate, :sass )
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+
2
+ require 'awestruct/handlers/base_sass_handler'
3
+
4
+ module Awestruct
5
+ module Handlers
6
+ class ScssHandler < BaseSassHandler
7
+
8
+ def initialize(site, delegate)
9
+ super( site, delegate, :scss )
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ require 'awestruct/handlers/base_handler'
2
+
3
+ module Awestruct
4
+ module Handlers
5
+ class StringHandler < BaseHandler
6
+
7
+
8
+ def initialize(site, content, output_extension='.html')
9
+ super( site )
10
+ @content = content
11
+ @output_extension = output_extension
12
+ end
13
+
14
+ def output_extension
15
+ @output_extension
16
+ end
17
+
18
+
19
+ def raw_content
20
+ @content
21
+ end
22
+
23
+ def rendered_content(context, with_layouts=true)
24
+ raw_content
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,43 @@
1
+
2
+ require 'awestruct/handlers/base_handler'
3
+ require 'redcloth'
4
+
5
+ module Awestruct
6
+ module Handlers
7
+ class TextileHandler < BaseHandler
8
+
9
+ def initialize(site, delegate)
10
+ super( site, delegate )
11
+ end
12
+
13
+ def simple_name
14
+ File.basename( relative_source_path, '.textile' )
15
+ end
16
+
17
+ def output_filename
18
+ File.basename( relative_source_path, '.textile' ) + '.html'
19
+ end
20
+
21
+ def output_extension
22
+ '.html'
23
+ end
24
+
25
+ def content_syntax
26
+ :textile
27
+ end
28
+
29
+ def rendered_content(context, with_layouts=true)
30
+ rendered = ''
31
+ # security and rendering restrictions
32
+ # ex. site.textile = ['no_span_caps']
33
+ restrictions = (site.textile || []).map { |r| r.to_sym }
34
+ # a module of rule functions is included in RedCloth using RedCloth.send(:include, MyRules)
35
+ # rule functions on that module are activated by setting the property site.textile_rules
36
+ # ex. site.textile_rules = ['emoticons']
37
+ rules = context.site.textile_rules ? context.site.textile_rules.map { |r| r.to_sym } : []
38
+ RedCloth.new( delegate.rendered_content( context, with_layouts ), restrictions ).to_html(*rules)
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,25 @@
1
+
2
+ require 'awestruct/handlers/base_handler'
3
+ require 'yaml'
4
+
5
+ module Awestruct
6
+ module Handlers
7
+ class YamlHandler < BaseHandler
8
+
9
+ def initialize(site, delegate)
10
+ super
11
+ end
12
+
13
+ def front_matter
14
+ return @front_matter if @front_matter
15
+ @front_matter = YAML.load( delegate.raw_content )
16
+ @front_matter
17
+ end
18
+
19
+ def raw_content
20
+ nil
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+
2
+ module Awestruct
3
+
4
+ class Layouts < Array
5
+
6
+ def find_matching(simple_name, output_extension)
7
+ self.find{|e|
8
+ ( e.simple_name == simple_name ) && ( e.output_extension == output_extension )
9
+ }
10
+ end
11
+
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,128 @@
1
+
2
+ require 'awestruct/context'
3
+
4
+ require 'awestruct/handlers/no_op_handler'
5
+ require 'hashery/open_cascade'
6
+ require 'ostruct'
7
+ require 'awestruct/astruct'
8
+
9
+ module Awestruct
10
+
11
+ class Page < Awestruct::AStruct
12
+
13
+ attr_accessor :site
14
+ attr_accessor :handler
15
+
16
+ attr_reader :dependencies
17
+
18
+ def initialize(site, handler=nil)
19
+ @site = site
20
+ @handler = handler || Awestruct::Handlers::NoOpHandler.new( site )
21
+ @dependencies = []
22
+ end
23
+
24
+ def prepare!
25
+ handler.inherit_front_matter( self )
26
+ end
27
+
28
+ def inspect
29
+ "Awestruct::Page{ #{self.object_id}: output_path=>#{output_path}, source_path=>#{source_path}, layout=>#{layout} }"
30
+ end
31
+
32
+ def create_context(content='')
33
+ context = Awestruct::Context.new( :site=>site, :page=>self, :content=>content )
34
+ site.engine.pipeline.mixin_helpers( context )
35
+ context
36
+ end
37
+
38
+ def inherit_front_matter_from(hash)
39
+ hash.each do |k,v|
40
+ unless ( key?( k ) )
41
+ self[k.to_sym] = v
42
+ end
43
+ end
44
+ end
45
+
46
+ def relative_source_path
47
+ @relative_source_path || handler.relative_source_path
48
+ end
49
+
50
+ def relative_source_path=(path)
51
+ @relative_source_path = path
52
+ end
53
+
54
+ def simple_name
55
+ handler.simple_name
56
+ end
57
+
58
+ def output_path
59
+ (@output_path || handler.output_path).to_s
60
+ end
61
+
62
+ def output_extension
63
+ handler.output_extension
64
+ end
65
+
66
+ def output_path=(path)
67
+ case ( path )
68
+ when Pathname:
69
+ @output_path = path
70
+ else
71
+ @output_path = Pathname.new( path )
72
+ end
73
+ end
74
+
75
+ def source_path
76
+ handler.path.to_s
77
+ end
78
+
79
+ def stale?
80
+ handler.stale? || @dependencies.any?(&:stale?)
81
+ end
82
+
83
+ def stale_output?(output_path)
84
+ return true if ! File.exist?( output_path )
85
+ return true if input_mtime > File.mtime( output_path )
86
+ false
87
+ end
88
+
89
+ def input_mtime
90
+ handler.input_mtime( self )
91
+ end
92
+
93
+ def collective_dependencies_mtime
94
+ t = nil
95
+ @dependencies.each do |e|
96
+ if ( t == nil )
97
+ t = e.mtime
98
+ elsif ( t < e.mtime )
99
+ t = e.mtime
100
+ end
101
+ end
102
+ t
103
+ end
104
+
105
+ def content_syntax
106
+ handler.content_syntax
107
+ end
108
+
109
+ def raw_content
110
+ handler.raw_content
111
+ end
112
+
113
+ def rendered_content(context=create_context(), with_layouts=true)
114
+ handler.rendered_content( context, with_layouts )
115
+ end
116
+
117
+ def content(with_layouts=false)
118
+ rendered_content( create_context(), with_layouts )
119
+ end
120
+
121
+ def ==(other_page)
122
+ self.object_id == other_page.object_id
123
+ end
124
+
125
+
126
+ end
127
+
128
+ end