ngage 0.0.0

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 (109) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/exe/ngage +55 -0
  4. data/lib/ngage.rb +3 -0
  5. data/lib/ngage/jekyll.rb +204 -0
  6. data/lib/ngage/jekyll/cleaner.rb +111 -0
  7. data/lib/ngage/jekyll/collection.rb +235 -0
  8. data/lib/ngage/jekyll/command.rb +103 -0
  9. data/lib/ngage/jekyll/commands/build.rb +93 -0
  10. data/lib/ngage/jekyll/commands/clean.rb +45 -0
  11. data/lib/ngage/jekyll/commands/doctor.rb +173 -0
  12. data/lib/ngage/jekyll/commands/help.rb +34 -0
  13. data/lib/ngage/jekyll/commands/new.rb +157 -0
  14. data/lib/ngage/jekyll/commands/new_theme.rb +42 -0
  15. data/lib/ngage/jekyll/commands/serve.rb +354 -0
  16. data/lib/ngage/jekyll/commands/serve/live_reload_reactor.rb +122 -0
  17. data/lib/ngage/jekyll/commands/serve/livereload_assets/livereload.js +1183 -0
  18. data/lib/ngage/jekyll/commands/serve/servlet.rb +203 -0
  19. data/lib/ngage/jekyll/commands/serve/websockets.rb +81 -0
  20. data/lib/ngage/jekyll/configuration.rb +391 -0
  21. data/lib/ngage/jekyll/converter.rb +54 -0
  22. data/lib/ngage/jekyll/converters/identity.rb +41 -0
  23. data/lib/ngage/jekyll/converters/markdown.rb +116 -0
  24. data/lib/ngage/jekyll/converters/markdown/kramdown_parser.rb +122 -0
  25. data/lib/ngage/jekyll/converters/smartypants.rb +70 -0
  26. data/lib/ngage/jekyll/convertible.rb +253 -0
  27. data/lib/ngage/jekyll/deprecator.rb +50 -0
  28. data/lib/ngage/jekyll/document.rb +503 -0
  29. data/lib/ngage/jekyll/drops/collection_drop.rb +20 -0
  30. data/lib/ngage/jekyll/drops/document_drop.rb +69 -0
  31. data/lib/ngage/jekyll/drops/drop.rb +209 -0
  32. data/lib/ngage/jekyll/drops/excerpt_drop.rb +15 -0
  33. data/lib/ngage/jekyll/drops/jekyll_drop.rb +32 -0
  34. data/lib/ngage/jekyll/drops/site_drop.rb +56 -0
  35. data/lib/ngage/jekyll/drops/static_file_drop.rb +14 -0
  36. data/lib/ngage/jekyll/drops/unified_payload_drop.rb +26 -0
  37. data/lib/ngage/jekyll/drops/url_drop.rb +89 -0
  38. data/lib/ngage/jekyll/entry_filter.rb +127 -0
  39. data/lib/ngage/jekyll/errors.rb +20 -0
  40. data/lib/ngage/jekyll/excerpt.rb +180 -0
  41. data/lib/ngage/jekyll/external.rb +76 -0
  42. data/lib/ngage/jekyll/filters.rb +390 -0
  43. data/lib/ngage/jekyll/filters/date_filters.rb +110 -0
  44. data/lib/ngage/jekyll/filters/grouping_filters.rb +64 -0
  45. data/lib/ngage/jekyll/filters/url_filters.rb +68 -0
  46. data/lib/ngage/jekyll/frontmatter_defaults.rb +233 -0
  47. data/lib/ngage/jekyll/generator.rb +5 -0
  48. data/lib/ngage/jekyll/hooks.rb +106 -0
  49. data/lib/ngage/jekyll/layout.rb +62 -0
  50. data/lib/ngage/jekyll/liquid_extensions.rb +22 -0
  51. data/lib/ngage/jekyll/liquid_renderer.rb +63 -0
  52. data/lib/ngage/jekyll/liquid_renderer/file.rb +56 -0
  53. data/lib/ngage/jekyll/liquid_renderer/table.rb +98 -0
  54. data/lib/ngage/jekyll/log_adapter.rb +151 -0
  55. data/lib/ngage/jekyll/mime.types +825 -0
  56. data/lib/ngage/jekyll/page.rb +185 -0
  57. data/lib/ngage/jekyll/page_without_a_file.rb +14 -0
  58. data/lib/ngage/jekyll/plugin.rb +92 -0
  59. data/lib/ngage/jekyll/plugin_manager.rb +115 -0
  60. data/lib/ngage/jekyll/publisher.rb +23 -0
  61. data/lib/ngage/jekyll/reader.rb +154 -0
  62. data/lib/ngage/jekyll/readers/collection_reader.rb +22 -0
  63. data/lib/ngage/jekyll/readers/data_reader.rb +75 -0
  64. data/lib/ngage/jekyll/readers/layout_reader.rb +70 -0
  65. data/lib/ngage/jekyll/readers/page_reader.rb +25 -0
  66. data/lib/ngage/jekyll/readers/post_reader.rb +72 -0
  67. data/lib/ngage/jekyll/readers/static_file_reader.rb +25 -0
  68. data/lib/ngage/jekyll/readers/theme_assets_reader.rb +51 -0
  69. data/lib/ngage/jekyll/regenerator.rb +195 -0
  70. data/lib/ngage/jekyll/related_posts.rb +52 -0
  71. data/lib/ngage/jekyll/renderer.rb +266 -0
  72. data/lib/ngage/jekyll/site.rb +476 -0
  73. data/lib/ngage/jekyll/static_file.rb +169 -0
  74. data/lib/ngage/jekyll/stevenson.rb +60 -0
  75. data/lib/ngage/jekyll/tags/highlight.rb +108 -0
  76. data/lib/ngage/jekyll/tags/include.rb +226 -0
  77. data/lib/ngage/jekyll/tags/link.rb +40 -0
  78. data/lib/ngage/jekyll/tags/post_url.rb +104 -0
  79. data/lib/ngage/jekyll/theme.rb +73 -0
  80. data/lib/ngage/jekyll/theme_builder.rb +121 -0
  81. data/lib/ngage/jekyll/url.rb +160 -0
  82. data/lib/ngage/jekyll/utils.rb +370 -0
  83. data/lib/ngage/jekyll/utils/ansi.rb +57 -0
  84. data/lib/ngage/jekyll/utils/exec.rb +26 -0
  85. data/lib/ngage/jekyll/utils/internet.rb +37 -0
  86. data/lib/ngage/jekyll/utils/platforms.rb +82 -0
  87. data/lib/ngage/jekyll/utils/thread_event.rb +31 -0
  88. data/lib/ngage/jekyll/utils/win_tz.rb +75 -0
  89. data/lib/ngage/site_template/.gitignore +5 -0
  90. data/lib/ngage/site_template/404.html +25 -0
  91. data/lib/ngage/site_template/_config.yml +47 -0
  92. data/lib/ngage/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb +29 -0
  93. data/lib/ngage/site_template/about.markdown +18 -0
  94. data/lib/ngage/site_template/index.markdown +6 -0
  95. data/lib/ngage/theme_template/CODE_OF_CONDUCT.md.erb +74 -0
  96. data/lib/ngage/theme_template/Gemfile +4 -0
  97. data/lib/ngage/theme_template/LICENSE.txt.erb +21 -0
  98. data/lib/ngage/theme_template/README.md.erb +52 -0
  99. data/lib/ngage/theme_template/_layouts/default.html +1 -0
  100. data/lib/ngage/theme_template/_layouts/page.html +5 -0
  101. data/lib/ngage/theme_template/_layouts/post.html +5 -0
  102. data/lib/ngage/theme_template/example/_config.yml.erb +1 -0
  103. data/lib/ngage/theme_template/example/_post.md +12 -0
  104. data/lib/ngage/theme_template/example/index.html +14 -0
  105. data/lib/ngage/theme_template/example/style.scss +7 -0
  106. data/lib/ngage/theme_template/gitignore.erb +6 -0
  107. data/lib/ngage/theme_template/theme.gemspec.erb +19 -0
  108. data/lib/ngage/version.rb +5 -0
  109. metadata +328 -0
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ class Converter < Plugin
5
+ # Public: Get or set the highlighter prefix. When an argument is specified,
6
+ # the prefix will be set. If no argument is specified, the current prefix
7
+ # will be returned.
8
+ #
9
+ # highlighter_prefix - The String prefix (default: nil).
10
+ #
11
+ # Returns the String prefix.
12
+ def self.highlighter_prefix(highlighter_prefix = nil)
13
+ unless defined?(@highlighter_prefix) && highlighter_prefix.nil?
14
+ @highlighter_prefix = highlighter_prefix
15
+ end
16
+ @highlighter_prefix
17
+ end
18
+
19
+ # Public: Get or set the highlighter suffix. When an argument is specified,
20
+ # the suffix will be set. If no argument is specified, the current suffix
21
+ # will be returned.
22
+ #
23
+ # highlighter_suffix - The String suffix (default: nil).
24
+ #
25
+ # Returns the String suffix.
26
+ def self.highlighter_suffix(highlighter_suffix = nil)
27
+ unless defined?(@highlighter_suffix) && highlighter_suffix.nil?
28
+ @highlighter_suffix = highlighter_suffix
29
+ end
30
+ @highlighter_suffix
31
+ end
32
+
33
+ # Initialize the converter.
34
+ #
35
+ # Returns an initialized Converter.
36
+ def initialize(config = {})
37
+ @config = config
38
+ end
39
+
40
+ # Get the highlighter prefix.
41
+ #
42
+ # Returns the String prefix.
43
+ def highlighter_prefix
44
+ self.class.highlighter_prefix
45
+ end
46
+
47
+ # Get the highlighter suffix.
48
+ #
49
+ # Returns the String suffix.
50
+ def highlighter_suffix
51
+ self.class.highlighter_suffix
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Converters
5
+ # Identify converter. Returns same content as given.
6
+ # For more info on converters see https://jekyllrb.com/docs/plugins/converters/
7
+ class Identity < Converter
8
+ safe true
9
+
10
+ priority :lowest
11
+
12
+ # Public: Does the given extension match this converter's list of acceptable extensions?
13
+ # Takes one argument: the file's extension (including the dot).
14
+ #
15
+ # ext - The String extension to check (not relevant here)
16
+ #
17
+ # Returns true since it always matches.
18
+ def matches(_ext)
19
+ true
20
+ end
21
+
22
+ # Public: The extension to be given to the output file (including the dot).
23
+ #
24
+ # ext - The String extension or original file.
25
+ #
26
+ # Returns The String output file extension.
27
+ def output_ext(ext)
28
+ ext
29
+ end
30
+
31
+ # Logic to do the content conversion.
32
+ #
33
+ # content - String content of file (without front matter).
34
+ #
35
+ # Returns a String of the converted content.
36
+ def convert(content)
37
+ content
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Converters
5
+ # Markdown converter.
6
+ # For more info on converters see https://jekyllrb.com/docs/plugins/converters/
7
+ class Markdown < Converter
8
+ highlighter_prefix "\n"
9
+ highlighter_suffix "\n"
10
+ safe true
11
+
12
+ def setup
13
+ return if @setup ||= false
14
+
15
+ unless (@parser = get_processor)
16
+ Jekyll.logger.error "Invalid Markdown processor given:", @config["markdown"]
17
+ Jekyll.logger.info "", "Custom processors are not loaded in safe mode" if @config["safe"]
18
+ Jekyll.logger.error(
19
+ "",
20
+ "Available processors are: #{valid_processors.join(", ")}"
21
+ )
22
+ raise Errors::FatalException, "Bailing out; invalid Markdown processor."
23
+ end
24
+
25
+ @setup = true
26
+ end
27
+
28
+ # Rubocop does not allow reader methods to have names starting with `get_`
29
+ # To ensure compatibility, this check has been disabled on this method
30
+ #
31
+ # rubocop:disable Naming/AccessorMethodName
32
+ def get_processor
33
+ case @config["markdown"].downcase
34
+ when "kramdown" then KramdownParser.new(@config)
35
+ else
36
+ custom_processor
37
+ end
38
+ end
39
+ # rubocop:enable Naming/AccessorMethodName
40
+
41
+ # Public: Provides you with a list of processors, the ones we
42
+ # support internally and the ones that you have provided to us (if you
43
+ # are not in safe mode.)
44
+
45
+ def valid_processors
46
+ %w(kramdown) + third_party_processors
47
+ end
48
+
49
+ # Public: A list of processors that you provide via plugins.
50
+ # This is really only available if you are not in safe mode, if you are
51
+ # in safe mode (re: GitHub) then there will be none.
52
+
53
+ def third_party_processors
54
+ self.class.constants - \
55
+ %w(KramdownParser PRIORITIES).map(
56
+ &:to_sym
57
+ )
58
+ end
59
+
60
+ def extname_list
61
+ @extname_list ||= @config["markdown_ext"].split(",").map do |e|
62
+ ".#{e.downcase}"
63
+ end
64
+ end
65
+
66
+ # Does the given extension match this converter's list of acceptable extensions?
67
+ # Takes one argument: the file's extension (including the dot).
68
+ #
69
+ # ext - The String extension to check.
70
+ #
71
+ # Returns true if it matches, false otherwise.
72
+ def matches(ext)
73
+ extname_list.include?(ext.downcase)
74
+ end
75
+
76
+ # Public: The extension to be given to the output file (including the dot).
77
+ #
78
+ # ext - The String extension or original file.
79
+ #
80
+ # Returns The String output file extension.
81
+ def output_ext(_ext)
82
+ ".html"
83
+ end
84
+
85
+ # Logic to do the content conversion.
86
+ #
87
+ # content - String content of file (without front matter).
88
+ #
89
+ # Returns a String of the converted content.
90
+ def convert(content)
91
+ setup
92
+ @parser.convert(content)
93
+ end
94
+
95
+ private
96
+
97
+ def custom_processor
98
+ converter_name = @config["markdown"]
99
+ self.class.const_get(converter_name).new(@config) if custom_class_allowed?(converter_name)
100
+ end
101
+
102
+ # Private: Determine whether a class name is an allowed custom
103
+ # markdown class name.
104
+ #
105
+ # parser_name - the name of the parser class
106
+ #
107
+ # Returns true if the parser name contains only alphanumeric
108
+ # characters and is defined within Jekyll::Converters::Markdown
109
+ def custom_class_allowed?(parser_name)
110
+ parser_name !~ %r![^A-Za-z0-9_]! && self.class.constants.include?(
111
+ parser_name.to_sym
112
+ )
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,122 @@
1
+ # Frozen-string-literal: true
2
+
3
+ module Jekyll
4
+ module Converters
5
+ class Markdown
6
+ class KramdownParser
7
+ CODERAY_DEFAULTS = {
8
+ "css" => "style",
9
+ "bold_every" => 10,
10
+ "line_numbers" => "inline",
11
+ "line_number_start" => 1,
12
+ "tab_width" => 4,
13
+ "wrap" => "div",
14
+ }.freeze
15
+
16
+ def initialize(config)
17
+ @main_fallback_highlighter = config["highlighter"] || "rouge"
18
+ @config = config["kramdown"] || {}
19
+ @highlighter = nil
20
+ setup
21
+ end
22
+
23
+ # Setup and normalize the configuration:
24
+ # * Create Kramdown if it doesn't exist.
25
+ # * Set syntax_highlighter, detecting enable_coderay and merging
26
+ # highlighter if none.
27
+ # * Merge kramdown[coderay] into syntax_highlighter_opts stripping coderay_.
28
+ # * Make sure `syntax_highlighter_opts` exists.
29
+
30
+ def setup
31
+ @config["syntax_highlighter"] ||= highlighter
32
+ @config["syntax_highlighter_opts"] ||= {}
33
+ @config["coderay"] ||= {} # XXX: Legacy.
34
+ modernize_coderay_config
35
+ make_accessible
36
+ end
37
+
38
+ def convert(content)
39
+ document = Kramdown::Document.new(content, @config)
40
+ html_output = document.to_html
41
+ if @config["show_warnings"]
42
+ document.warnings.each do |warning|
43
+ Jekyll.logger.warn "Kramdown warning:", warning
44
+ end
45
+ end
46
+ html_output
47
+ end
48
+
49
+ private
50
+
51
+ def make_accessible(hash = @config)
52
+ hash.keys.each do |key|
53
+ hash[key.to_sym] = hash[key]
54
+ make_accessible(hash[key]) if hash[key].is_a?(Hash)
55
+ end
56
+ end
57
+
58
+ # config[kramdown][syntax_higlighter] >
59
+ # config[kramdown][enable_coderay] >
60
+ # config[highlighter]
61
+ # Where `enable_coderay` is now deprecated because Kramdown
62
+ # supports Rouge now too.
63
+ def highlighter
64
+ return @highlighter if @highlighter
65
+
66
+ if @config["syntax_highlighter"]
67
+ return @highlighter = @config[
68
+ "syntax_highlighter"
69
+ ]
70
+ end
71
+
72
+ @highlighter = begin
73
+ if @config.key?("enable_coderay") && @config["enable_coderay"]
74
+ Jekyll::Deprecator.deprecation_message(
75
+ "You are using 'enable_coderay', " \
76
+ "use syntax_highlighter: coderay in your configuration file."
77
+ )
78
+
79
+ "coderay"
80
+ else
81
+ @main_fallback_highlighter
82
+ end
83
+ end
84
+ end
85
+
86
+ def strip_coderay_prefix(hash)
87
+ hash.each_with_object({}) do |(key, val), hsh|
88
+ cleaned_key = key.to_s.gsub(%r!\Acoderay_!, "")
89
+
90
+ if key != cleaned_key
91
+ Jekyll::Deprecator.deprecation_message(
92
+ "You are using '#{key}'. Normalizing to #{cleaned_key}."
93
+ )
94
+ end
95
+
96
+ hsh[cleaned_key] = val
97
+ end
98
+ end
99
+
100
+ # If our highlighter is CodeRay we go in to merge the CodeRay defaults
101
+ # with your "coderay" key if it's there, deprecating it in the
102
+ # process of you using it.
103
+ def modernize_coderay_config
104
+ unless @config["coderay"].empty?
105
+ Jekyll::Deprecator.deprecation_message(
106
+ "You are using 'kramdown.coderay' in your configuration, " \
107
+ "please use 'syntax_highlighter_opts' instead."
108
+ )
109
+
110
+ @config["syntax_highlighter_opts"] = begin
111
+ strip_coderay_prefix(
112
+ @config["syntax_highlighter_opts"] \
113
+ .merge(CODERAY_DEFAULTS) \
114
+ .merge(@config["coderay"])
115
+ )
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kramdown
4
+ module Parser
5
+ class SmartyPants < Kramdown::Parser::Kramdown
6
+ def initialize(source, options)
7
+ super
8
+ @block_parsers = [:block_html, :content]
9
+ @span_parsers = [:smart_quotes, :html_entity, :typographic_syms, :span_html]
10
+ end
11
+
12
+ def parse_content
13
+ add_text @src.scan(%r!\A.*\n!)
14
+ end
15
+ define_parser(:content, %r!\A!)
16
+ end
17
+ end
18
+ end
19
+
20
+ module Jekyll
21
+ module Converters
22
+ # SmartyPants converter.
23
+ # For more info on converters see https://jekyllrb.com/docs/plugins/converters/
24
+ class SmartyPants < Converter
25
+ safe true
26
+ priority :low
27
+
28
+ def initialize(config)
29
+ Jekyll::External.require_with_graceful_fail "kramdown" unless defined?(Kramdown)
30
+ @config = config["kramdown"].dup || {}
31
+ @config[:input] = :SmartyPants
32
+ end
33
+
34
+ # Does the given extension match this converter's list of acceptable extensions?
35
+ # Takes one argument: the file's extension (including the dot).
36
+ #
37
+ # ext - The String extension to check.
38
+ #
39
+ # Returns true if it matches, false otherwise.
40
+ def matches(_)
41
+ false
42
+ end
43
+
44
+ # Public: The extension to be given to the output file (including the dot).
45
+ #
46
+ # ext - The String extension or original file.
47
+ #
48
+ # Returns The String output file extension.
49
+ def output_ext(_)
50
+ nil
51
+ end
52
+
53
+ # Logic to do the content conversion.
54
+ #
55
+ # content - String content of file (without front matter).
56
+ #
57
+ # Returns a String of the converted content.
58
+ def convert(content)
59
+ document = Kramdown::Document.new(content, @config)
60
+ html_output = document.to_html.chomp
61
+ if @config["show_warnings"]
62
+ document.warnings.each do |warning|
63
+ Jekyll.logger.warn "Kramdown warning:", warning.sub(%r!^Warning:\s+!, "")
64
+ end
65
+ end
66
+ html_output
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,253 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Convertible provides methods for converting a pagelike item
4
+ # from a certain type of markup into actual content
5
+ #
6
+ # Requires
7
+ # self.site -> Jekyll::Site
8
+ # self.content
9
+ # self.content=
10
+ # self.data=
11
+ # self.ext=
12
+ # self.output=
13
+ # self.name
14
+ # self.path
15
+ # self.type -> :page, :post or :draft
16
+
17
+ module Jekyll
18
+ module Convertible
19
+ # Returns the contents as a String.
20
+ def to_s
21
+ content || ""
22
+ end
23
+
24
+ # Whether the file is published or not, as indicated in YAML front-matter
25
+ def published?
26
+ !(data.key?("published") && data["published"] == false)
27
+ end
28
+
29
+ # Read the YAML frontmatter.
30
+ #
31
+ # base - The String path to the dir containing the file.
32
+ # name - The String filename of the file.
33
+ # opts - optional parameter to File.read, default at site configs
34
+ #
35
+ # Returns nothing.
36
+ # rubocop:disable Metrics/AbcSize
37
+ def read_yaml(base, name, opts = {})
38
+ filename = File.join(base, name)
39
+
40
+ begin
41
+ self.content = File.read(@path || site.in_source_dir(base, name),
42
+ Utils.merged_file_read_opts(site, opts))
43
+ if content =~ Document::YAML_FRONT_MATTER_REGEXP
44
+ self.content = $POSTMATCH
45
+ self.data = SafeYAML.load(Regexp.last_match(1))
46
+ end
47
+ rescue Psych::SyntaxError => e
48
+ Jekyll.logger.warn "YAML Exception reading #{filename}: #{e.message}"
49
+ raise e if site.config["strict_front_matter"]
50
+ rescue StandardError => e
51
+ Jekyll.logger.warn "Error reading file #{filename}: #{e.message}"
52
+ raise e if site.config["strict_front_matter"]
53
+ end
54
+
55
+ self.data ||= {}
56
+
57
+ validate_data! filename
58
+ validate_permalink! filename
59
+
60
+ self.data
61
+ end
62
+ # rubocop:enable Metrics/AbcSize
63
+
64
+ def validate_data!(filename)
65
+ unless self.data.is_a?(Hash)
66
+ raise Errors::InvalidYAMLFrontMatterError,
67
+ "Invalid YAML front matter in #{filename}"
68
+ end
69
+ end
70
+
71
+ def validate_permalink!(filename)
72
+ if self.data["permalink"]&.to_s&.empty?
73
+ raise Errors::InvalidPermalinkError, "Invalid permalink in #{filename}"
74
+ end
75
+ end
76
+
77
+ # Transform the contents based on the content type.
78
+ #
79
+ # Returns the transformed contents.
80
+ def transform
81
+ _renderer.convert(content)
82
+ end
83
+
84
+ # Determine the extension depending on content_type.
85
+ #
86
+ # Returns the String extension for the output file.
87
+ # e.g. ".html" for an HTML output file.
88
+ def output_ext
89
+ _renderer.output_ext
90
+ end
91
+
92
+ # Determine which converter to use based on this convertible's
93
+ # extension.
94
+ #
95
+ # Returns the Converter instance.
96
+ def converters
97
+ _renderer.converters
98
+ end
99
+
100
+ # Render Liquid in the content
101
+ #
102
+ # content - the raw Liquid content to render
103
+ # payload - the payload for Liquid
104
+ # info - the info for Liquid
105
+ #
106
+ # Returns the converted content
107
+ def render_liquid(content, payload, info, path)
108
+ _renderer.render_liquid(content, payload, info, path)
109
+ end
110
+
111
+ # Convert this Convertible's data to a Hash suitable for use by Liquid.
112
+ #
113
+ # Returns the Hash representation of this Convertible.
114
+ def to_liquid(attrs = nil)
115
+ further_data = Hash[(attrs || self.class::ATTRIBUTES_FOR_LIQUID).map do |attribute|
116
+ [attribute, send(attribute)]
117
+ end]
118
+
119
+ defaults = site.frontmatter_defaults.all(relative_path, type)
120
+ Utils.deep_merge_hashes defaults, Utils.deep_merge_hashes(data, further_data)
121
+ end
122
+
123
+ # The type of a document,
124
+ # i.e., its classname downcase'd and to_sym'd.
125
+ #
126
+ # Returns the type of self.
127
+ def type
128
+ :pages if is_a?(Page)
129
+ end
130
+
131
+ # returns the owner symbol for hook triggering
132
+ def hook_owner
133
+ :pages if is_a?(Page)
134
+ end
135
+
136
+ # Determine whether the document is an asset file.
137
+ # Asset files include CoffeeScript files and Sass/SCSS files.
138
+ #
139
+ # Returns true if the extname belongs to the set of extensions
140
+ # that asset files use.
141
+ def asset_file?
142
+ sass_file? || coffeescript_file?
143
+ end
144
+
145
+ # Determine whether the document is a Sass file.
146
+ #
147
+ # Returns true if extname == .sass or .scss, false otherwise.
148
+ def sass_file?
149
+ %w(.sass .scss).include?(ext)
150
+ end
151
+
152
+ # Determine whether the document is a CoffeeScript file.
153
+ #
154
+ # Returns true if extname == .coffee, false otherwise.
155
+ def coffeescript_file?
156
+ ext == ".coffee"
157
+ end
158
+
159
+ # Determine whether the file should be rendered with Liquid.
160
+ #
161
+ # Returns true if the file has Liquid Tags or Variables, false otherwise.
162
+ def render_with_liquid?
163
+ return false if data["render_with_liquid"] == false
164
+
165
+ Jekyll::Utils.has_liquid_construct?(content)
166
+ end
167
+
168
+ # Determine whether the file should be placed into layouts.
169
+ #
170
+ # Returns false if the document is an asset file or if the front matter
171
+ # specifies `layout: none`
172
+ def place_in_layout?
173
+ !(asset_file? || no_layout?)
174
+ end
175
+
176
+ # Checks if the layout specified in the document actually exists
177
+ #
178
+ # layout - the layout to check
179
+ #
180
+ # Returns true if the layout is invalid, false if otherwise
181
+ def invalid_layout?(layout)
182
+ !data["layout"].nil? && layout.nil? && !(is_a? Jekyll::Excerpt)
183
+ end
184
+
185
+ # Recursively render layouts
186
+ #
187
+ # layouts - a list of the layouts
188
+ # payload - the payload for Liquid
189
+ # info - the info for Liquid
190
+ #
191
+ # Returns nothing
192
+ def render_all_layouts(layouts, payload, info)
193
+ _renderer.layouts = layouts
194
+ self.output = _renderer.place_in_layouts(output, payload, info)
195
+ ensure
196
+ @_renderer = nil # this will allow the modifications above to disappear
197
+ end
198
+
199
+ # Add any necessary layouts to this convertible document.
200
+ #
201
+ # payload - The site payload Drop or Hash.
202
+ # layouts - A Hash of {"name" => "layout"}.
203
+ #
204
+ # Returns nothing.
205
+ def do_layout(payload, layouts)
206
+ self.output = _renderer.tap do |renderer|
207
+ renderer.layouts = layouts
208
+ renderer.payload = payload
209
+ end.run
210
+
211
+ Jekyll.logger.debug "Post-Render Hooks:", relative_path
212
+ Jekyll::Hooks.trigger hook_owner, :post_render, self
213
+ ensure
214
+ @_renderer = nil # this will allow the modifications above to disappear
215
+ end
216
+
217
+ # Write the generated page file to the destination directory.
218
+ #
219
+ # dest - The String path to the destination dir.
220
+ #
221
+ # Returns nothing.
222
+ def write(dest)
223
+ path = destination(dest)
224
+ FileUtils.mkdir_p(File.dirname(path))
225
+ Jekyll.logger.debug "Writing:", path
226
+ File.write(path, output, :mode => "wb")
227
+ Jekyll::Hooks.trigger hook_owner, :post_write, self
228
+ end
229
+
230
+ # Accessor for data properties by Liquid.
231
+ #
232
+ # property - The String name of the property to retrieve.
233
+ #
234
+ # Returns the String value or nil if the property isn't included.
235
+ def [](property)
236
+ if self.class::ATTRIBUTES_FOR_LIQUID.include?(property)
237
+ send(property)
238
+ else
239
+ data[property]
240
+ end
241
+ end
242
+
243
+ private
244
+
245
+ def _renderer
246
+ @_renderer ||= Jekyll::Renderer.new(site, self)
247
+ end
248
+
249
+ def no_layout?
250
+ data["layout"] == "none"
251
+ end
252
+ end
253
+ end