jekyll-haml-markup 0.1.0 → 0.1.6
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.
- checksums.yaml +5 -5
- data/.github/workflows/gem-push.yml +40 -0
- data/.gitignore +3 -0
- data/.travis.yml +8 -2
- data/Gemfile +2 -2
- data/README.md +9 -19
- data/Rakefile +6 -6
- data/jekyll-haml-markup.gemspec +20 -16
- data/lib/jekyll-haml-markup.rb +1 -13
- data/lib/jekyll/haml/markup.rb +16 -0
- data/lib/jekyll/haml/markup/converter.rb +20 -0
- data/lib/jekyll/haml/markup/hooks.rb +10 -0
- data/lib/jekyll/haml/markup/include.rb +37 -0
- data/lib/jekyll/haml/markup/parser.rb +19 -0
- data/lib/{jekyll-haml-markup → jekyll/haml/markup}/version.rb +1 -1
- metadata +82 -33
- data/Gemfile.lock +0 -80
- data/lib/jekyll/configuration.rb +0 -92
- data/lib/jekyll/converters/haml.rb +0 -34
- data/lib/jekyll/convertible.rb +0 -15
- data/lib/jekyll/excerpt.rb +0 -9
- data/lib/jekyll/haml.rb +0 -11
- data/lib/jekyll/haml/include.rb +0 -225
- data/lib/jekyll/haml/parser.rb +0 -40
- data/lib/jekyll/haml_renderer.rb +0 -51
- data/lib/jekyll/haml_renderer/file.rb +0 -54
- data/lib/jekyll/haml_renderer/table.rb +0 -94
- data/lib/jekyll/renderer.rb +0 -60
- data/lib/jekyll/site.rb +0 -14
- data/lib/jekyll/tags/include.rb +0 -15
data/lib/jekyll/haml/parser.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'haml'
|
2
|
-
|
3
|
-
module Jekyll
|
4
|
-
module Haml
|
5
|
-
class Parser
|
6
|
-
|
7
|
-
def initialize(config)
|
8
|
-
unless defined?(Haml)
|
9
|
-
Jekyll::External.require_with_graceful_fail "haml"
|
10
|
-
end
|
11
|
-
@config = config["lib-haml"] || {}
|
12
|
-
setup
|
13
|
-
end
|
14
|
-
|
15
|
-
def setup
|
16
|
-
make_accessible
|
17
|
-
end
|
18
|
-
|
19
|
-
def convert(content)
|
20
|
-
document = ::Haml::Engine.new(content, @config)
|
21
|
-
html_output = document.render
|
22
|
-
if @config["show_warnings"]
|
23
|
-
document.warnings.each do |warning|
|
24
|
-
Jekyll.logger.warn "Haml warning:", warning
|
25
|
-
end
|
26
|
-
end
|
27
|
-
html_output
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
def make_accessible(hash = @config)
|
32
|
-
hash.keys.each do |key|
|
33
|
-
hash[key.to_sym] = hash[key]
|
34
|
-
make_accessible(hash[key]) if hash[key].is_a?(Hash)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/lib/jekyll/haml_renderer.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'jekyll/haml_renderer'
|
3
|
-
require_relative 'haml_renderer/file'
|
4
|
-
require_relative 'haml_renderer/table'
|
5
|
-
|
6
|
-
module Jekyll
|
7
|
-
class HamlRenderer
|
8
|
-
def initialize(site)
|
9
|
-
@site = site
|
10
|
-
# Haml::Template.error_mode = @site.config["haml"]["error_mode"].to_sym
|
11
|
-
reset
|
12
|
-
end
|
13
|
-
|
14
|
-
def reset
|
15
|
-
@stats = {}
|
16
|
-
end
|
17
|
-
|
18
|
-
def file(filename)
|
19
|
-
filename = @site.in_source_dir(filename).sub(
|
20
|
-
%r!\A#{Regexp.escape(@site.source)}/!,
|
21
|
-
""
|
22
|
-
)
|
23
|
-
|
24
|
-
HamlRenderer::File.new(self, filename).tap do
|
25
|
-
@stats[filename] ||= new_profile_hash
|
26
|
-
@stats[filename][:count] += 1
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def increment_bytes(filename, bytes)
|
31
|
-
@stats[filename][:bytes] += bytes
|
32
|
-
end
|
33
|
-
|
34
|
-
def increment_time(filename, time)
|
35
|
-
@stats[filename][:time] += time
|
36
|
-
end
|
37
|
-
|
38
|
-
def stats_table(n = 50)
|
39
|
-
HamlRenderer::Table.new(@stats).to_s(n)
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.format_error(e, path)
|
43
|
-
"#{e.message} in #{path}"
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
def new_profile_hash
|
48
|
-
Hash.new { |hash, key| hash[key] = 0 }
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module Jekyll
|
2
|
-
class HamlRenderer
|
3
|
-
class File
|
4
|
-
def initialize(renderer, filename)
|
5
|
-
@renderer = renderer
|
6
|
-
@filename = filename
|
7
|
-
end
|
8
|
-
|
9
|
-
def parse(content)
|
10
|
-
measure_time do
|
11
|
-
@template = ::Haml::Engine.new(content) #, :line_numbers => true)
|
12
|
-
end
|
13
|
-
|
14
|
-
self
|
15
|
-
end
|
16
|
-
|
17
|
-
def render(*args)
|
18
|
-
measure_time do
|
19
|
-
measure_bytes do
|
20
|
-
@template.render(*args)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def render!(*args)
|
26
|
-
measure_time do
|
27
|
-
measure_bytes do
|
28
|
-
@template = @template.render(*args)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def warnings
|
34
|
-
[] # @template.warnings
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def measure_bytes
|
40
|
-
yield.tap do |str|
|
41
|
-
@renderer.increment_bytes(@filename, str.bytesize)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def measure_time
|
46
|
-
before = Time.now
|
47
|
-
yield
|
48
|
-
ensure
|
49
|
-
after = Time.now
|
50
|
-
@renderer.increment_time(@filename, after - before)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
module Jekyll
|
2
|
-
class HamlRenderer::Table
|
3
|
-
def initialize(stats)
|
4
|
-
@stats = stats
|
5
|
-
end
|
6
|
-
|
7
|
-
def to_s(n = 50)
|
8
|
-
data = data_for_table(n)
|
9
|
-
widths = table_widths(data)
|
10
|
-
generate_table(data, widths)
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def generate_table(data, widths)
|
16
|
-
str = String.new("\n")
|
17
|
-
|
18
|
-
table_head = data.shift
|
19
|
-
str << generate_row(table_head, widths)
|
20
|
-
str << generate_table_head_border(table_head, widths)
|
21
|
-
|
22
|
-
data.each do |row_data|
|
23
|
-
str << generate_row(row_data, widths)
|
24
|
-
end
|
25
|
-
|
26
|
-
str << "\n"
|
27
|
-
str
|
28
|
-
end
|
29
|
-
|
30
|
-
def generate_table_head_border(row_data, widths)
|
31
|
-
str = String.new("")
|
32
|
-
|
33
|
-
row_data.each_index do |cell_index|
|
34
|
-
str << "-" * widths[cell_index]
|
35
|
-
str << "-+-" unless cell_index == row_data.length - 1
|
36
|
-
end
|
37
|
-
|
38
|
-
str << "\n"
|
39
|
-
str
|
40
|
-
end
|
41
|
-
|
42
|
-
def generate_row(row_data, widths)
|
43
|
-
str = String.new("")
|
44
|
-
|
45
|
-
row_data.each_with_index do |cell_data, cell_index|
|
46
|
-
str << if cell_index.zero?
|
47
|
-
cell_data.ljust(widths[cell_index], " ")
|
48
|
-
else
|
49
|
-
cell_data.rjust(widths[cell_index], " ")
|
50
|
-
end
|
51
|
-
|
52
|
-
str << " | " unless cell_index == row_data.length - 1
|
53
|
-
end
|
54
|
-
|
55
|
-
str << "\n"
|
56
|
-
str
|
57
|
-
end
|
58
|
-
|
59
|
-
def table_widths(data)
|
60
|
-
widths = []
|
61
|
-
|
62
|
-
data.each do |row|
|
63
|
-
row.each_with_index do |cell, index|
|
64
|
-
widths[index] = [ cell.length, widths[index] ].compact.max
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
widths
|
69
|
-
end
|
70
|
-
|
71
|
-
def data_for_table(n)
|
72
|
-
sorted = @stats.sort_by { |_, file_stats| -file_stats[:time] }
|
73
|
-
sorted = sorted.slice(0, n)
|
74
|
-
|
75
|
-
table = [%w(Filename Count Bytes Time)]
|
76
|
-
|
77
|
-
sorted.each do |filename, file_stats|
|
78
|
-
row = []
|
79
|
-
row << filename
|
80
|
-
row << file_stats[:count].to_s
|
81
|
-
row << format_bytes(file_stats[:bytes])
|
82
|
-
row << format("%.3f", file_stats[:time])
|
83
|
-
table << row
|
84
|
-
end
|
85
|
-
|
86
|
-
table
|
87
|
-
end
|
88
|
-
|
89
|
-
def format_bytes(bytes)
|
90
|
-
bytes /= 1024.0
|
91
|
-
format("%.2fK", bytes)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
data/lib/jekyll/renderer.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'jekyll/renderer'
|
2
|
-
|
3
|
-
module Jekyll
|
4
|
-
class Renderer
|
5
|
-
def render_document
|
6
|
-
info = {
|
7
|
-
:registers => { :site => site, :page => payload["page"] },
|
8
|
-
}
|
9
|
-
output = document.content
|
10
|
-
|
11
|
-
if document.render_with_haml?
|
12
|
-
Jekyll.logger.debug "Rendering Haml:", document.relative_path
|
13
|
-
output = render_haml(output, payload, info, document.path)
|
14
|
-
end
|
15
|
-
|
16
|
-
if document.render_with_liquid?
|
17
|
-
Jekyll.logger.debug "Rendering Liquid:", document.relative_path
|
18
|
-
output = render_liquid(output, payload, info, document.path)
|
19
|
-
end
|
20
|
-
|
21
|
-
Jekyll.logger.debug "Rendering Markup:", document.relative_path
|
22
|
-
output = convert(output)
|
23
|
-
document.content = output
|
24
|
-
|
25
|
-
if document.place_in_layout?
|
26
|
-
Jekyll.logger.debug "Rendering Layout:", document.relative_path
|
27
|
-
output = place_in_layouts(output, payload, info)
|
28
|
-
end
|
29
|
-
|
30
|
-
output
|
31
|
-
end
|
32
|
-
|
33
|
-
def render_haml(content, payload, info, path = nil)
|
34
|
-
template = site.haml_renderer.file(path).parse(content)
|
35
|
-
template.warnings.each do |e|
|
36
|
-
Jekyll.logger.warn "Haml Warning:",
|
37
|
-
HamlRenderer.format_error(e, path || document.relative_path)
|
38
|
-
end
|
39
|
-
template.render!(payload, info)
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
def render_layout(output, layout, info)
|
44
|
-
payload["content"] = output
|
45
|
-
payload["layout"] = Utils.deep_merge_hashes(layout.data, payload["layout"] || {})
|
46
|
-
|
47
|
-
if layout.render_with_haml?
|
48
|
-
Jekyll.logger.debug "Rendering Haml:", layout.relative_path
|
49
|
-
layout.content = ::Haml::Engine.new(layout.content).render
|
50
|
-
end
|
51
|
-
|
52
|
-
render_liquid(
|
53
|
-
layout.content,
|
54
|
-
payload,
|
55
|
-
info,
|
56
|
-
layout.relative_path
|
57
|
-
)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
data/lib/jekyll/site.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'jekyll/site'
|
2
|
-
|
3
|
-
module Jekyll
|
4
|
-
class Site
|
5
|
-
attr_reader :haml_renderer
|
6
|
-
|
7
|
-
alias_method :pre_haml_initialize, :initialize
|
8
|
-
|
9
|
-
def initialize(config)
|
10
|
-
pre_haml_initialize(config)
|
11
|
-
@haml_renderer = HamlRenderer.new(self)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
data/lib/jekyll/tags/include.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'jekyll/tags/include'
|
2
|
-
|
3
|
-
# frozen_string_literal: true
|
4
|
-
|
5
|
-
module Jekyll
|
6
|
-
module Tags
|
7
|
-
class IncludeTag < Liquid::Tag
|
8
|
-
|
9
|
-
def read_file(file, context)
|
10
|
-
::Haml::Engine.new(File.read(file, file_read_opts(context))).render
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|