1
1
require 'fileutils'
2
+ require 'google-yaml'
2
3
3
4
module Jekyll
4
5
5
- class GoogleYAMLTree < Psych ::Visitors ::YAMLTree
6
- def accept target
7
- if target . respond_to? ( :to_yaml )
8
- begin
9
- loc = target . method ( :to_yaml ) . source_location . first
10
- if loc !~ /(syck\/ rubytypes.rb|psych\/ core_ext.rb)/
11
- unless target . respond_to? ( :encode_with )
12
- if $VERBOSE
13
- warn "implementing to_yaml is deprecated, please implement \" encode_with\" "
14
- end
15
-
16
- target . to_yaml ( :nodump => true )
17
- end
18
- end
19
- rescue
20
- # public_method or source_location might be overridden,
21
- # and it's OK to skip it since it's only to emit a warning
22
- end
23
- end
24
-
25
- if target . respond_to? ( :encode_with )
26
- dump_coder target
27
- else
28
- send ( @dispatch_cache [ target . class ] , target )
29
- end
30
- end
31
- end
32
-
33
6
class PageWithoutAFile < Page
34
7
def read_yaml ( *)
35
8
@data ||= { }
@@ -89,6 +62,7 @@ def write
89
62
end
90
63
91
64
def app_yaml_content
65
+ # HACK: use sub-classed YAML implementation which disables anchors and aliases
92
66
builder = GoogleYAMLTree . create
93
67
builder << generate_app_engine_yaml
94
68
@@ -99,6 +73,34 @@ def app_yaml_content
99
73
return app_yaml . output
100
74
end
101
75
76
+ def page_types
77
+ page_types_array = [
78
+ {
79
+ "content_type" => "posts" ,
80
+ "content_collection" => @site . posts . docs
81
+ } ,
82
+ {
83
+ "content_type" => "pages" ,
84
+ "content_collection" => @site . pages
85
+ } ,
86
+ {
87
+ "content_type" => "static" ,
88
+ "content_collection" => @site . static_files
89
+ } ,
90
+ ]
91
+
92
+ @site . collections . each_pair do |label , collection |
93
+ unless label == "posts"
94
+ page_types_array << {
95
+ "content_type" => "collections" ,
96
+ "content_collection" => collection . docs
97
+ }
98
+ end
99
+ end
100
+
101
+ return page_types_array
102
+ end
103
+
102
104
def generate_app_engine_yaml
103
105
if source_partial_exists?
104
106
app_yaml = YAML . load_file ( source_path )
@@ -108,28 +110,23 @@ def generate_app_engine_yaml
108
110
109
111
app_yaml [ "handlers" ] ||= [ ]
110
112
111
- generate_handlers ( "posts" , @site . posts . docs ) . each { |handler | app_yaml [ "handlers" ] << handler }
112
- generate_handlers ( "pages" , @site . pages ) . each { |handler | app_yaml [ "handlers" ] << handler }
113
-
114
- @site . collections . each_pair do |label , collection |
115
- unless label == "posts"
116
- generate_handlers ( "collections" , collection . docs ) . each { |handler | app_yaml [ "handlers" ] << handler }
117
- end
113
+ page_types . each do |content |
114
+ generate_handlers ( content ) . each { |handler | app_yaml [ "handlers" ] << handler }
118
115
end
119
116
120
- generate_handlers ( "static" , @site . static_files ) . each { |handler | app_yaml [ "handlers" ] << handler }
121
-
122
117
return app_yaml
123
118
end
124
119
125
- def generate_handlers ( content_type , collection )
120
+ def generate_handlers ( content )
121
+ content_type = content [ "content_type" ]
122
+ content_collection = content [ "content_collection" ]
126
123
handlers = [ ]
127
124
128
125
handler_template = @app_engine [ "handlers" ] [ content_type ] || { }
129
126
if handler_template . kind_of? ( Array ) or handler_template . has_key? ( "url" )
130
127
handlers << handler_template
131
128
else
132
- collection . each do |doc |
129
+ content_collection . each do |doc |
133
130
handler = {
134
131
"url" => doc . url ,
135
132
"static_files" => doc . destination ( "" ) . sub ( "#{ Dir . pwd } /" , "" ) ,
0 commit comments