ngage 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Filters
5
+ module GroupingFilters
6
+ # Group an array of items by a property
7
+ #
8
+ # input - the inputted Enumerable
9
+ # property - the property
10
+ #
11
+ # Returns an array of Hashes, each looking something like this:
12
+ # {"name" => "larry"
13
+ # "items" => [...] } # all the items where `property` == "larry"
14
+ def group_by(input, property)
15
+ if groupable?(input)
16
+ groups = input.group_by { |item| item_property(item, property).to_s }
17
+ grouped_array(groups)
18
+ else
19
+ input
20
+ end
21
+ end
22
+
23
+ # Group an array of items by an expression
24
+ #
25
+ # input - the object array
26
+ # variable - the variable to assign each item to in the expression
27
+ # expression -a Liquid comparison expression passed in as a string
28
+ #
29
+ # Returns the filtered array of objects
30
+ def group_by_exp(input, variable, expression)
31
+ return input unless groupable?(input)
32
+
33
+ parsed_expr = parse_expression(expression)
34
+ @context.stack do
35
+ groups = input.group_by do |item|
36
+ @context[variable] = item
37
+ parsed_expr.render(@context)
38
+ end
39
+ grouped_array(groups)
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def parse_expression(str)
46
+ Liquid::Variable.new(str, Liquid::ParseContext.new)
47
+ end
48
+
49
+ def groupable?(element)
50
+ element.respond_to?(:group_by)
51
+ end
52
+
53
+ def grouped_array(groups)
54
+ groups.each_with_object([]) do |item, array|
55
+ array << {
56
+ "name" => item.first,
57
+ "items" => item.last,
58
+ "size" => item.last.size,
59
+ }
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Filters
5
+ module URLFilters
6
+ # Produces an absolute URL based on site.url and site.baseurl.
7
+ #
8
+ # input - the URL to make absolute.
9
+ #
10
+ # Returns the absolute URL as a String.
11
+ def absolute_url(input)
12
+ return if input.nil?
13
+
14
+ input = input.url if input.respond_to?(:url)
15
+ return input if Addressable::URI.parse(input.to_s).absolute?
16
+
17
+ site = @context.registers[:site]
18
+ return relative_url(input) if site.config["url"].nil?
19
+
20
+ Addressable::URI.parse(
21
+ site.config["url"].to_s + relative_url(input)
22
+ ).normalize.to_s
23
+ end
24
+
25
+ # Produces a URL relative to the domain root based on site.baseurl
26
+ # unless it is already an absolute url with an authority (host).
27
+ #
28
+ # input - the URL to make relative to the domain root
29
+ #
30
+ # Returns a URL relative to the domain root as a String.
31
+ def relative_url(input)
32
+ return if input.nil?
33
+
34
+ input = input.url if input.respond_to?(:url)
35
+ return input if Addressable::URI.parse(input.to_s).absolute?
36
+
37
+ parts = [sanitized_baseurl, input]
38
+ Addressable::URI.parse(
39
+ parts.compact.map { |part| ensure_leading_slash(part.to_s) }.join
40
+ ).normalize.to_s
41
+ end
42
+
43
+ # Strips trailing `/index.html` from URLs to create pretty permalinks
44
+ #
45
+ # input - the URL with a possible `/index.html`
46
+ #
47
+ # Returns a URL with the trailing `/index.html` removed
48
+ def strip_index(input)
49
+ return if input.nil? || input.to_s.empty?
50
+
51
+ input.sub(%r!/index\.html?$!, "/")
52
+ end
53
+
54
+ private
55
+
56
+ def sanitized_baseurl
57
+ site = @context.registers[:site]
58
+ site.config["baseurl"].to_s.chomp("/")
59
+ end
60
+
61
+ def ensure_leading_slash(input)
62
+ return input if input.nil? || input.empty? || input.start_with?("/")
63
+
64
+ "/#{input}"
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,233 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ # This class handles custom defaults for YAML frontmatter settings.
5
+ # These are set in _config.yml and apply both to internal use (e.g. layout)
6
+ # and the data available to liquid.
7
+ #
8
+ # It is exposed via the frontmatter_defaults method on the site class.
9
+ class FrontmatterDefaults
10
+ # Initializes a new instance.
11
+ def initialize(site)
12
+ @site = site
13
+ end
14
+
15
+ def update_deprecated_types(set)
16
+ return set unless set.key?("scope") && set["scope"].key?("type")
17
+
18
+ set["scope"]["type"] =
19
+ case set["scope"]["type"]
20
+ when "page"
21
+ Deprecator.defaults_deprecate_type("page", "pages")
22
+ "pages"
23
+ when "post"
24
+ Deprecator.defaults_deprecate_type("post", "posts")
25
+ "posts"
26
+ when "draft"
27
+ Deprecator.defaults_deprecate_type("draft", "drafts")
28
+ "drafts"
29
+ else
30
+ set["scope"]["type"]
31
+ end
32
+
33
+ set
34
+ end
35
+
36
+ def ensure_time!(set)
37
+ return set unless set.key?("values") && set["values"].key?("date")
38
+ return set if set["values"]["date"].is_a?(Time)
39
+
40
+ set["values"]["date"] = Utils.parse_date(
41
+ set["values"]["date"],
42
+ "An invalid date format was found in a front-matter default set: #{set}"
43
+ )
44
+ set
45
+ end
46
+
47
+ # Finds a default value for a given setting, filtered by path and type
48
+ #
49
+ # path - the path (relative to the source) of the page,
50
+ # post or :draft the default is used in
51
+ # type - a symbol indicating whether a :page,
52
+ # a :post or a :draft calls this method
53
+ #
54
+ # Returns the default value or nil if none was found
55
+ def find(path, type, setting)
56
+ value = nil
57
+ old_scope = nil
58
+
59
+ matching_sets(path, type).each do |set|
60
+ if set["values"].key?(setting) && has_precedence?(old_scope, set["scope"])
61
+ value = set["values"][setting]
62
+ old_scope = set["scope"]
63
+ end
64
+ end
65
+ value
66
+ end
67
+
68
+ # Collects a hash with all default values for a page or post
69
+ #
70
+ # path - the relative path of the page or post
71
+ # type - a symbol indicating the type (:post, :page or :draft)
72
+ #
73
+ # Returns a hash with all default values (an empty hash if there are none)
74
+ def all(path, type)
75
+ defaults = {}
76
+ old_scope = nil
77
+ matching_sets(path, type).each do |set|
78
+ if has_precedence?(old_scope, set["scope"])
79
+ defaults = Utils.deep_merge_hashes(defaults, set["values"])
80
+ old_scope = set["scope"]
81
+ else
82
+ defaults = Utils.deep_merge_hashes(set["values"], defaults)
83
+ end
84
+ end
85
+ defaults
86
+ end
87
+
88
+ private
89
+
90
+ # Checks if a given default setting scope matches the given path and type
91
+ #
92
+ # scope - the hash indicating the scope, as defined in _config.yml
93
+ # path - the path to check for
94
+ # type - the type (:post, :page or :draft) to check for
95
+ #
96
+ # Returns true if the scope applies to the given type and path
97
+ def applies?(scope, path, type)
98
+ applies_type?(scope, type) && applies_path?(scope, path)
99
+ end
100
+
101
+ # rubocop:disable Metrics/AbcSize
102
+ def applies_path?(scope, path)
103
+ return true if !scope.key?("path") || scope["path"].empty?
104
+
105
+ sanitized_path = Pathname.new(sanitize_path(path))
106
+ site_path = Pathname.new(@site.source)
107
+ rel_scope_path = Pathname.new(scope["path"])
108
+ abs_scope_path = File.join(@site.source, rel_scope_path)
109
+
110
+ if scope["path"].to_s.include?("*")
111
+ Dir.glob(abs_scope_path).each do |scope_path|
112
+ scope_path = Pathname.new(scope_path).relative_path_from(site_path)
113
+ scope_path = strip_collections_dir(scope_path)
114
+ Jekyll.logger.debug "Globbed Scope Path:", scope_path
115
+ return true if path_is_subpath?(sanitized_path, scope_path)
116
+ end
117
+ false
118
+ else
119
+ path_is_subpath?(sanitized_path, strip_collections_dir(rel_scope_path))
120
+ end
121
+ end
122
+ # rubocop:enable Metrics/AbcSize
123
+
124
+ def path_is_subpath?(path, parent_path)
125
+ path.ascend do |ascended_path|
126
+ return true if ascended_path.to_s == parent_path.to_s
127
+ end
128
+
129
+ false
130
+ end
131
+
132
+ def strip_collections_dir(path)
133
+ collections_dir = @site.config["collections_dir"]
134
+ slashed_coll_dir = "#{collections_dir}/"
135
+ return path if collections_dir.empty? || !path.to_s.start_with?(slashed_coll_dir)
136
+
137
+ path.sub(slashed_coll_dir, "")
138
+ end
139
+
140
+ # Determines whether the scope applies to type.
141
+ # The scope applies to the type if:
142
+ # 1. no 'type' is specified
143
+ # 2. the 'type' in the scope is the same as the type asked about
144
+ #
145
+ # scope - the Hash defaults set being asked about application
146
+ # type - the type of the document being processed / asked about
147
+ # its defaults.
148
+ #
149
+ # Returns true if either of the above conditions are satisfied,
150
+ # otherwise returns false
151
+ def applies_type?(scope, type)
152
+ !scope.key?("type") || scope["type"].eql?(type.to_s)
153
+ end
154
+
155
+ # Checks if a given set of default values is valid
156
+ #
157
+ # set - the default value hash, as defined in _config.yml
158
+ #
159
+ # Returns true if the set is valid and can be used in this class
160
+ def valid?(set)
161
+ set.is_a?(Hash) && set["values"].is_a?(Hash)
162
+ end
163
+
164
+ # Determines if a new scope has precedence over an old one
165
+ #
166
+ # old_scope - the old scope hash, or nil if there's none
167
+ # new_scope - the new scope hash
168
+ #
169
+ # Returns true if the new scope has precedence over the older
170
+ # rubocop: disable PredicateName
171
+ def has_precedence?(old_scope, new_scope)
172
+ return true if old_scope.nil?
173
+
174
+ new_path = sanitize_path(new_scope["path"])
175
+ old_path = sanitize_path(old_scope["path"])
176
+
177
+ if new_path.length != old_path.length
178
+ new_path.length >= old_path.length
179
+ elsif new_scope.key?("type")
180
+ true
181
+ else
182
+ !old_scope.key? "type"
183
+ end
184
+ end
185
+ # rubocop: enable PredicateName
186
+
187
+ # Collects a list of sets that match the given path and type
188
+ #
189
+ # Returns an array of hashes
190
+ def matching_sets(path, type)
191
+ @matched_set_cache ||= {}
192
+ @matched_set_cache[path] ||= {}
193
+ @matched_set_cache[path][type] ||= begin
194
+ valid_sets.select do |set|
195
+ !set.key?("scope") || applies?(set["scope"], path, type)
196
+ end
197
+ end
198
+ end
199
+
200
+ # Returns a list of valid sets
201
+ #
202
+ # This is not cached to allow plugins to modify the configuration
203
+ # and have their changes take effect
204
+ #
205
+ # Returns an array of hashes
206
+ def valid_sets
207
+ sets = @site.config["defaults"]
208
+ return [] unless sets.is_a?(Array)
209
+
210
+ sets.map do |set|
211
+ if valid?(set)
212
+ ensure_time!(update_deprecated_types(set))
213
+ else
214
+ Jekyll.logger.warn "Defaults:", "An invalid front-matter default set was found:"
215
+ Jekyll.logger.warn set.to_s
216
+ nil
217
+ end
218
+ end.compact
219
+ end
220
+
221
+ # Sanitizes the given path by removing a leading and adding a trailing slash
222
+
223
+ SANITIZATION_REGEX = %r!\A/|(?<=[^/])\z!
224
+
225
+ def sanitize_path(path)
226
+ if path.nil? || path.empty?
227
+ ""
228
+ else
229
+ path.gsub(SANITIZATION_REGEX, "")
230
+ end
231
+ end
232
+ end
233
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ Generator = Class.new(Plugin)
5
+ end
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Hooks
5
+ DEFAULT_PRIORITY = 20
6
+
7
+ # compatibility layer for octopress-hooks users
8
+ PRIORITY_MAP = {
9
+ :low => 10,
10
+ :normal => 20,
11
+ :high => 30,
12
+ }.freeze
13
+
14
+ # initial empty hooks
15
+ @registry = {
16
+ :site => {
17
+ :after_init => [],
18
+ :after_reset => [],
19
+ :post_read => [],
20
+ :pre_render => [],
21
+ :post_render => [],
22
+ :post_write => [],
23
+ },
24
+ :pages => {
25
+ :post_init => [],
26
+ :pre_render => [],
27
+ :post_render => [],
28
+ :post_write => [],
29
+ },
30
+ :posts => {
31
+ :post_init => [],
32
+ :pre_render => [],
33
+ :post_render => [],
34
+ :post_write => [],
35
+ },
36
+ :documents => {
37
+ :post_init => [],
38
+ :pre_render => [],
39
+ :post_render => [],
40
+ :post_write => [],
41
+ },
42
+ :clean => {
43
+ :on_obsolete => [],
44
+ },
45
+ }
46
+
47
+ # map of all hooks and their priorities
48
+ @hook_priority = {}
49
+
50
+ NotAvailable = Class.new(RuntimeError)
51
+ Uncallable = Class.new(RuntimeError)
52
+
53
+ # register hook(s) to be called later, public API
54
+ def self.register(owners, event, priority: DEFAULT_PRIORITY, &block)
55
+ Array(owners).each do |owner|
56
+ register_one(owner, event, priority_value(priority), &block)
57
+ end
58
+ end
59
+
60
+ # Ensure the priority is a Fixnum
61
+ def self.priority_value(priority)
62
+ return priority if priority.is_a?(Integer)
63
+
64
+ PRIORITY_MAP[priority] || DEFAULT_PRIORITY
65
+ end
66
+
67
+ # register a single hook to be called later, internal API
68
+ def self.register_one(owner, event, priority, &block)
69
+ @registry[owner] ||= {
70
+ :post_init => [],
71
+ :pre_render => [],
72
+ :post_render => [],
73
+ :post_write => [],
74
+ }
75
+
76
+ unless @registry[owner][event]
77
+ raise NotAvailable, "Invalid hook. #{owner} supports only the " \
78
+ "following hooks #{@registry[owner].keys.inspect}"
79
+ end
80
+
81
+ raise Uncallable, "Hooks must respond to :call" unless block.respond_to? :call
82
+
83
+ insert_hook owner, event, priority, &block
84
+ end
85
+
86
+ def self.insert_hook(owner, event, priority, &block)
87
+ @hook_priority[block] = [-priority, @hook_priority.size]
88
+ @registry[owner][event] << block
89
+ end
90
+
91
+ # interface for Jekyll core components to trigger hooks
92
+ def self.trigger(owner, event, *args)
93
+ # proceed only if there are hooks to call
94
+ return unless @registry[owner]
95
+ return unless @registry[owner][event]
96
+
97
+ # hooks to call for this owner and event
98
+ hooks = @registry[owner][event]
99
+
100
+ # sort and call hooks according to priority and load order
101
+ hooks.sort_by { |h| @hook_priority[h] }.each do |hook|
102
+ hook.call(*args)
103
+ end
104
+ end
105
+ end
106
+ end