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,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ class Layout
5
+ include Convertible
6
+
7
+ # Gets the Site object.
8
+ attr_reader :site
9
+
10
+ # Gets the name of this layout.
11
+ attr_reader :name
12
+
13
+ # Gets the path to this layout.
14
+ attr_reader :path
15
+
16
+ # Gets the path to this layout relative to its base
17
+ attr_reader :relative_path
18
+
19
+ # Gets/Sets the extension of this layout.
20
+ attr_accessor :ext
21
+
22
+ # Gets/Sets the Hash that holds the metadata for this layout.
23
+ attr_accessor :data
24
+
25
+ # Gets/Sets the content of this layout.
26
+ attr_accessor :content
27
+
28
+ # Initialize a new Layout.
29
+ #
30
+ # site - The Site.
31
+ # base - The String path to the source.
32
+ # name - The String filename of the post file.
33
+ def initialize(site, base, name)
34
+ @site = site
35
+ @base = base
36
+ @name = name
37
+
38
+ if site.theme && site.theme.layouts_path.eql?(base)
39
+ @base_dir = site.theme.root
40
+ @path = site.in_theme_dir(base, name)
41
+ else
42
+ @base_dir = site.source
43
+ @path = site.in_source_dir(base, name)
44
+ end
45
+ @relative_path = @path.sub(@base_dir, "")
46
+
47
+ self.data = {}
48
+
49
+ process(name)
50
+ read_yaml(base, name)
51
+ end
52
+
53
+ # Extract information from the layout filename.
54
+ #
55
+ # name - The String filename of the layout file.
56
+ #
57
+ # Returns nothing.
58
+ def process(name)
59
+ self.ext = File.extname(name)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module LiquidExtensions
5
+ # Lookup a Liquid variable in the given context.
6
+ #
7
+ # context - the Liquid context in question.
8
+ # variable - the variable name, as a string.
9
+ #
10
+ # Returns the value of the variable in the context
11
+ # or the variable name if not found.
12
+ def lookup_variable(context, variable)
13
+ lookup = context
14
+
15
+ variable.split(".").each do |value|
16
+ lookup = lookup[value]
17
+ end
18
+
19
+ lookup || variable
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "liquid_renderer/file"
4
+ require_relative "liquid_renderer/table"
5
+
6
+ module Jekyll
7
+ class LiquidRenderer
8
+ extend Forwardable
9
+
10
+ private def_delegator :@site, :in_source_dir, :source_dir
11
+ private def_delegator :@site, :in_theme_dir, :theme_dir
12
+
13
+ def initialize(site)
14
+ @site = site
15
+ Liquid::Template.error_mode = @site.config["liquid"]["error_mode"].to_sym
16
+ reset
17
+ end
18
+
19
+ def reset
20
+ @stats = {}
21
+ end
22
+
23
+ def file(filename)
24
+ filename.match(filename_regex)
25
+ filename =
26
+ if Regexp.last_match(1) == theme_dir("")
27
+ ::File.join(::File.basename(Regexp.last_match(1)), Regexp.last_match(2))
28
+ else
29
+ Regexp.last_match(2)
30
+ end
31
+ LiquidRenderer::File.new(self, filename).tap do
32
+ @stats[filename] ||= new_profile_hash
33
+ @stats[filename][:count] += 1
34
+ end
35
+ end
36
+
37
+ def increment_bytes(filename, bytes)
38
+ @stats[filename][:bytes] += bytes
39
+ end
40
+
41
+ def increment_time(filename, time)
42
+ @stats[filename][:time] += time
43
+ end
44
+
45
+ def stats_table(num_of_rows = 50)
46
+ LiquidRenderer::Table.new(@stats).to_s(num_of_rows)
47
+ end
48
+
49
+ def self.format_error(error, path)
50
+ "#{error.message} in #{path}"
51
+ end
52
+
53
+ private
54
+
55
+ def filename_regex
56
+ @filename_regex ||= %r!\A(#{source_dir}/|#{theme_dir}/|\W*)(.*)!i
57
+ end
58
+
59
+ def new_profile_hash
60
+ Hash.new { |hash, key| hash[key] = 0 }
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ class LiquidRenderer
5
+ class File
6
+ def initialize(renderer, filename)
7
+ @renderer = renderer
8
+ @filename = filename
9
+ end
10
+
11
+ def parse(content)
12
+ measure_time do
13
+ @template = Liquid::Template.parse(content, :line_numbers => true)
14
+ end
15
+
16
+ self
17
+ end
18
+
19
+ def render(*args)
20
+ measure_time do
21
+ measure_bytes do
22
+ @template.render(*args)
23
+ end
24
+ end
25
+ end
26
+
27
+ def render!(*args)
28
+ measure_time do
29
+ measure_bytes do
30
+ @template.render!(*args)
31
+ end
32
+ end
33
+ end
34
+
35
+ def warnings
36
+ @template.warnings
37
+ end
38
+
39
+ private
40
+
41
+ def measure_bytes
42
+ yield.tap do |str|
43
+ @renderer.increment_bytes(@filename, str.bytesize)
44
+ end
45
+ end
46
+
47
+ def measure_time
48
+ before = Time.now
49
+ yield
50
+ ensure
51
+ after = Time.now
52
+ @renderer.increment_time(@filename, after - before)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ class LiquidRenderer
5
+ class Table
6
+ def initialize(stats)
7
+ @stats = stats
8
+ end
9
+
10
+ def to_s(num_of_rows = 50)
11
+ data = data_for_table(num_of_rows)
12
+ widths = table_widths(data)
13
+ generate_table(data, widths)
14
+ end
15
+
16
+ private
17
+
18
+ def generate_table(data, widths)
19
+ str = +"\n"
20
+
21
+ table_head = data.shift
22
+ str << generate_row(table_head, widths)
23
+ str << generate_table_head_border(table_head, widths)
24
+
25
+ data.each do |row_data|
26
+ str << generate_row(row_data, widths)
27
+ end
28
+
29
+ str << "\n"
30
+ str
31
+ end
32
+
33
+ def generate_table_head_border(row_data, widths)
34
+ str = +""
35
+
36
+ row_data.each_index do |cell_index|
37
+ str << "-" * widths[cell_index]
38
+ str << "-+-" unless cell_index == row_data.length - 1
39
+ end
40
+
41
+ str << "\n"
42
+ str
43
+ end
44
+
45
+ def generate_row(row_data, widths)
46
+ str = +""
47
+
48
+ row_data.each_with_index do |cell_data, cell_index|
49
+ str << if cell_index.zero?
50
+ cell_data.ljust(widths[cell_index], " ")
51
+ else
52
+ cell_data.rjust(widths[cell_index], " ")
53
+ end
54
+
55
+ str << " | " unless cell_index == row_data.length - 1
56
+ end
57
+
58
+ str << "\n"
59
+ str
60
+ end
61
+
62
+ def table_widths(data)
63
+ widths = []
64
+
65
+ data.each do |row|
66
+ row.each_with_index do |cell, index|
67
+ widths[index] = [cell.length, widths[index]].compact.max
68
+ end
69
+ end
70
+
71
+ widths
72
+ end
73
+
74
+ def data_for_table(num_of_rows)
75
+ sorted = @stats.sort_by { |_, file_stats| -file_stats[:time] }
76
+ sorted = sorted.slice(0, num_of_rows)
77
+
78
+ table = [%w(Filename Count Bytes Time)]
79
+
80
+ sorted.each do |filename, file_stats|
81
+ row = []
82
+ row << filename
83
+ row << file_stats[:count].to_s
84
+ row << format_bytes(file_stats[:bytes])
85
+ row << format("%.3f", file_stats[:time])
86
+ table << row
87
+ end
88
+
89
+ table
90
+ end
91
+
92
+ def format_bytes(bytes)
93
+ bytes /= 1024.0
94
+ format("%.2fK", bytes)
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,151 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ class LogAdapter
5
+ attr_reader :writer, :messages, :level
6
+
7
+ LOG_LEVELS = {
8
+ :debug => ::Logger::DEBUG,
9
+ :info => ::Logger::INFO,
10
+ :warn => ::Logger::WARN,
11
+ :error => ::Logger::ERROR,
12
+ }.freeze
13
+
14
+ # Public: Create a new instance of a log writer
15
+ #
16
+ # writer - Logger compatible instance
17
+ # log_level - (optional, symbol) the log level
18
+ #
19
+ # Returns nothing
20
+ def initialize(writer, level = :info)
21
+ @messages = []
22
+ @writer = writer
23
+ self.log_level = level
24
+ end
25
+
26
+ # Public: Set the log level on the writer
27
+ #
28
+ # level - (symbol) the log level
29
+ #
30
+ # Returns nothing
31
+ def log_level=(level)
32
+ writer.level = level if level.is_a?(Integer) && level.between?(0, 3)
33
+ writer.level = LOG_LEVELS[level] ||
34
+ raise(ArgumentError, "unknown log level")
35
+ @level = level
36
+ end
37
+
38
+ def adjust_verbosity(options = {})
39
+ # Quiet always wins.
40
+ if options[:quiet]
41
+ self.log_level = :error
42
+ elsif options[:verbose]
43
+ self.log_level = :debug
44
+ end
45
+ debug "Logging at level:", LOG_LEVELS.key(writer.level).to_s
46
+ debug "Jekyll Version:", Jekyll::VERSION
47
+ end
48
+
49
+ # Public: Print a debug message
50
+ #
51
+ # topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
52
+ # message - the message detail
53
+ #
54
+ # Returns nothing
55
+ def debug(topic, message = nil, &block)
56
+ write(:debug, topic, message, &block)
57
+ end
58
+
59
+ # Public: Print a message
60
+ #
61
+ # topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
62
+ # message - the message detail
63
+ #
64
+ # Returns nothing
65
+ def info(topic, message = nil, &block)
66
+ write(:info, topic, message, &block)
67
+ end
68
+
69
+ # Public: Print a message
70
+ #
71
+ # topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
72
+ # message - the message detail
73
+ #
74
+ # Returns nothing
75
+ def warn(topic, message = nil, &block)
76
+ write(:warn, topic, message, &block)
77
+ end
78
+
79
+ # Public: Print an error message
80
+ #
81
+ # topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
82
+ # message - the message detail
83
+ #
84
+ # Returns nothing
85
+ def error(topic, message = nil, &block)
86
+ write(:error, topic, message, &block)
87
+ end
88
+
89
+ # Public: Print an error message and immediately abort the process
90
+ #
91
+ # topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
92
+ # message - the message detail (can be omitted)
93
+ #
94
+ # Returns nothing
95
+ def abort_with(topic, message = nil, &block)
96
+ error(topic, message, &block)
97
+ abort
98
+ end
99
+
100
+ # Internal: Build a topic method
101
+ #
102
+ # topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
103
+ # message - the message detail
104
+ #
105
+ # Returns the formatted message
106
+ def message(topic, message = nil)
107
+ raise ArgumentError, "block or message, not both" if block_given? && message
108
+
109
+ message = yield if block_given?
110
+ message = message.to_s.gsub(%r!\s+!, " ")
111
+ topic = formatted_topic(topic, block_given?)
112
+ out = topic + message
113
+ messages << out
114
+ out
115
+ end
116
+
117
+ # Internal: Format the topic
118
+ #
119
+ # topic - the topic of the message, e.g. "Configuration file", "Deprecation", etc.
120
+ # colon -
121
+ #
122
+ # Returns the formatted topic statement
123
+ def formatted_topic(topic, colon = false)
124
+ "#{topic}#{colon ? ": " : " "}".rjust(20)
125
+ end
126
+
127
+ # Internal: Check if the message should be written given the log level.
128
+ #
129
+ # level_of_message - the Symbol level of message, one of :debug, :info, :warn, :error
130
+ #
131
+ # Returns whether the message should be written.
132
+ def write_message?(level_of_message)
133
+ LOG_LEVELS.fetch(level) <= LOG_LEVELS.fetch(level_of_message)
134
+ end
135
+
136
+ # Internal: Log a message.
137
+ #
138
+ # level_of_message - the Symbol level of message, one of :debug, :info, :warn, :error
139
+ # topic - the String topic or full message
140
+ # message - the String message (optional)
141
+ # block - a block containing the message (optional)
142
+ #
143
+ # Returns false if the message was not written, otherwise returns the value of calling
144
+ # the appropriate writer method, e.g. writer.info.
145
+ def write(level_of_message, topic, message = nil, &block)
146
+ return false unless write_message?(level_of_message)
147
+
148
+ writer.public_send(level_of_message, message(topic, message, &block))
149
+ end
150
+ end
151
+ end