Class: Jekyll::JekyllAppEngine
- Inherits:
-
Generator
- Object
- Generator
- Jekyll::JekyllAppEngine
- Defined in:
- lib/jekyll-app-engine.rb
Instance Method Summary collapse
- #app_yaml_content ⇒ Object
-
#app_yaml_exists? ⇒ Boolean
Checks if a app.yaml already exists in the site source.
-
#destination_path ⇒ Object
Destination for app.yaml file within the site source directory.
-
#document_overrides(document) ⇒ Object
Document specific app.yaml configuration provided in yaml frontmatter.
-
#generate(site) ⇒ Object
Main plugin action, called by Jekyll-core.
- #generate_app_engine_yaml ⇒ Object
- #generate_handlers(content) ⇒ Object
- #output_collection?(label) ⇒ Boolean
- #page_types ⇒ Object
- #source_config ⇒ Object
-
#source_partial_exists? ⇒ Boolean
Checks if a optional _app.yaml partial already exists.
-
#source_path ⇒ Object
Path to optional _app.yaml partial.
- #write ⇒ Object
Instance Method Details
#app_yaml_content ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/jekyll-app-engine.rb', line 74 def app_yaml_content # HACK: use sub-classed YAML implementation which disables anchors and aliases builder = GoogleYAMLTree.create builder << generate_app_engine_yaml app_yaml = PageWithoutAFile.new(@site, File.dirname(__FILE__), "", "app.yaml") app_yaml.content = builder.tree.yaml app_yaml.data["layout"] = nil app_yaml.render({}, @site.site_payload) return app_yaml.output end |
#app_yaml_exists? ⇒ Boolean
Checks if a app.yaml already exists in the site source
163 164 165 166 167 168 169 |
# File 'lib/jekyll-app-engine.rb', line 163 def app_yaml_exists? if @site.respond_to?(:in_source_dir) File.exists? @site.in_source_dir("app.yaml") else File.exists? Jekyll.sanitized_path(@site.source, "app.yaml") end end |
#destination_path ⇒ Object
Destination for app.yaml file within the site source directory
61 62 63 64 65 66 67 |
# File 'lib/jekyll-app-engine.rb', line 61 def destination_path if @site.respond_to?(:in_dest_dir) @site.in_dest_dir("app.yaml") else Jekyll.sanitized_path(@site.dest, "app.yaml") end end |
#document_overrides(document) ⇒ Object
Document specific app.yaml configuration provided in yaml frontmatter
154 155 156 157 158 159 160 |
# File 'lib/jekyll-app-engine.rb', line 154 def document_overrides(document) if document.respond_to?(:data) and document.data.has_key?("app_engine") document.data.fetch("app_engine") else {} end end |
#generate(site) ⇒ Object
Main plugin action, called by Jekyll-core
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/jekyll-app-engine.rb', line 17 def generate(site) @site = site @app_engine = source_config unless app_yaml_exists? unless @app_engine raise "App engine base configration not found" end @app_engine["handlers"] ||= {} write @site.keep_files ||= [] @site.keep_files << "app.yaml" end end |
#generate_app_engine_yaml ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/jekyll-app-engine.rb', line 118 def generate_app_engine_yaml app_yaml = @app_engine.dup generated_handlers = [] page_types.each do |content| generate_handlers(content).each { |handler| generated_handlers << handler } end app_yaml["handlers"] = generated_handlers return app_yaml end |
#generate_handlers(content) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/jekyll-app-engine.rb', line 131 def generate_handlers(content) content_type = content["content_type"] content_collection = content["content_collection"] handlers = [] handler_template = @app_engine["handlers"][content_type] || {} if handler_template.kind_of?(Array) or handler_template.has_key?("url") handlers << handler_template else content_collection.each do |doc| handler = { "url" => doc.url, "static_files" => doc.destination("").sub("#{Dir.pwd}/", ""), "upload" => doc.destination("").sub("#{Dir.pwd}/", "") } handlers << handler.merge!(handler_template.dup).merge!(document_overrides(doc)) end end return handlers end |
#output_collection?(label) ⇒ Boolean
86 87 88 |
# File 'lib/jekyll-app-engine.rb', line 86 def output_collection?(label) @site.config["collections"]["#{label}"]["output"] end |
#page_types ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/jekyll-app-engine.rb', line 90 def page_types page_types_array = [ { "content_type" => "posts", "content_collection" => @site.posts.docs }, { "content_type" => "pages", "content_collection" => @site.pages }, { "content_type" => "static", "content_collection" => @site.static_files }, ] @site.collections.each_pair do |label, collection| if label != "posts" and output_collection?(label) page_types_array << { "content_type" => "collections", "content_collection" => collection.docs } end end return page_types_array end |
#source_config ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/jekyll-app-engine.rb', line 34 def source_config if @site.config.has_key?("app_engine") @site.config["app_engine"] elsif source_partial_exists? YAML.load_file(source_path) end end |
#source_partial_exists? ⇒ Boolean
Checks if a optional _app.yaml partial already exists
43 44 45 46 47 48 49 |
# File 'lib/jekyll-app-engine.rb', line 43 def source_partial_exists? if @site.respond_to?(:in_source_dir) File.exists? @site.in_source_dir("_app.yaml") else File.exists? Jekyll.sanitized_path(@site.source, "_app.yaml") end end |
#source_path ⇒ Object
Path to optional _app.yaml partial
52 53 54 55 56 57 58 |
# File 'lib/jekyll-app-engine.rb', line 52 def source_path if @site.respond_to?(:in_source_dir) @site.in_source_dir("_app.yaml") else Jekyll.sanitized_path(@site.source, "_app.yaml") end end |
#write ⇒ Object
69 70 71 72 |
# File 'lib/jekyll-app-engine.rb', line 69 def write FileUtils.mkdir_p File.dirname(destination_path) File.open(destination_path, 'w') { |f| f.write(app_yaml_content) } end |