jekyll-pug 1.0.1 → 1.5.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.
- checksums.yaml +4 -4
- data/lib/jekyll-pug.rb +5 -5
- data/lib/jekyll-pug/pug-renderer.rb +140 -32
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2545440203a83d292340950b7a17ddaa30dfe9c2
|
4
|
+
data.tar.gz: 51717567bb516056ebb2e9af0f4a327df5fed2dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c021d09c76298635aac255ed90e7f65a330ae60698189322a4256d8e7d1181ec261668bc31f399071efc9a0b2128df1c741174b7546cd394ce71561d86c0f82d
|
7
|
+
data.tar.gz: 9d72b78f4732811ca97f52811a5bf180b0ad219955d0653ab45cbca14e1245b9907e641b52f024b7f934deff84a9f741992b1c5fbe4dd97364a13a31d8d31d69
|
data/lib/jekyll-pug.rb
CHANGED
@@ -3,10 +3,10 @@ require "jekyll-pug/pug-renderer"
|
|
3
3
|
require "jekyll-pug/include-tag"
|
4
4
|
|
5
5
|
# Enable/Disable Minfify based on the user's config file.
|
6
|
-
jekyllConfig = Jekyll.configuration({})
|
6
|
+
$jekyllConfig = Jekyll.configuration({})
|
7
7
|
|
8
|
-
if jekyllConfig['jekyll-pug']
|
9
|
-
if jekyllConfig['jekyll-pug']['minify']
|
8
|
+
if $jekyllConfig['jekyll-pug']
|
9
|
+
if $jekyllConfig['jekyll-pug']['minify']
|
10
10
|
# Minify is enabled - pretty disabled
|
11
11
|
Pug.config.pretty = false
|
12
12
|
else
|
@@ -19,8 +19,8 @@ else
|
|
19
19
|
end
|
20
20
|
|
21
21
|
config_source = ""
|
22
|
-
if jekyllConfig['source']
|
23
|
-
config_source = jekyllConfig['source']
|
22
|
+
if $jekyllConfig['source']
|
23
|
+
config_source = $jekyllConfig['source']
|
24
24
|
end
|
25
25
|
|
26
26
|
$JEKYLLPUG_PROJECT_SOURCE = File.join(config_source, '_includes/.')
|
@@ -1,41 +1,149 @@
|
|
1
|
-
#
|
1
|
+
# # # # # # # # # # # #
|
2
|
+
# Jekyll-Pug-Renderer #
|
3
|
+
# # # # # # # # # # # #
|
4
|
+
|
5
|
+
# Simple function= to print data if debug is true.
|
6
|
+
|
7
|
+
$jekyll_pug_curFile = ""
|
8
|
+
|
9
|
+
def jp(string)
|
10
|
+
if $jekyllConfig['jekyll-pug']
|
11
|
+
if $jekyllConfig['jekyll-pug']['debug']
|
12
|
+
puts "[Jekyll-Pug] " + $jekyll_pug_curFile.to_s + " " + string.to_s
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_cache_and_compile(content, cached_file)
|
18
|
+
userSource = $JEKYLLPUG_PROJECT_SOURCE
|
19
|
+
pug_raw = content
|
20
|
+
content = Pug.compile(content, {"filename"=>userSource})
|
21
|
+
::File.write(cached_file, pug_raw)
|
22
|
+
::File.write(cached_file+".html", content)
|
23
|
+
return content
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_cache(content, cached_file)
|
27
|
+
::File.write(cached_file, content)
|
28
|
+
end
|
29
|
+
|
2
30
|
module Jekyll
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
31
|
+
class LiquidRenderer
|
32
|
+
File.class_eval do
|
33
|
+
def parse(content)
|
34
|
+
if @filename =~ /\.pug$/
|
35
|
+
filename_regex = /[a-zA-Z1-9\s\~\-\.\_\%\#\&\*\{\}\:\?\+\|\<\>\"\']+.pug/
|
36
|
+
|
37
|
+
$jekyll_pug_curFile = @filename.match(filename_regex)
|
38
|
+
jp("Processing Pug file.")
|
39
|
+
|
40
|
+
# Creating Cache Variables
|
41
|
+
cache_dir = ".pug-cache/"
|
42
|
+
cached_file = cache_dir + @filename
|
43
|
+
cached_file_dir = cached_file.sub(filename_regex, '')
|
44
|
+
|
45
|
+
# Creating cache directory neccesary (if needed)
|
46
|
+
FileUtils.mkdir_p(cached_file_dir) unless ::File.exists?(cached_file_dir)
|
47
|
+
|
48
|
+
# If cached pug file exists
|
49
|
+
if ::File.file?(cached_file)
|
50
|
+
jp("Cached file exists! Attempting to use it...")
|
51
|
+
cached_file_content = ::File.read(cached_file)
|
52
|
+
|
53
|
+
pugIncludeChange = false
|
54
|
+
# Check if Pug includes have changed.
|
55
|
+
# If Pug includes changed, we must recompile
|
56
|
+
|
57
|
+
# Loop through Pug includes to determine if any had been modified
|
58
|
+
includes_in_file = content.scan(/^\s+include\s[a-zA-Z1-9\/\_\-\.]+/)
|
59
|
+
for i in includes_in_file do
|
60
|
+
# Remove spaces/tabs in front of code
|
61
|
+
include_file = i.sub(/^\s+/, '')
|
62
|
+
# Remove include statement to be left with filename
|
63
|
+
include_file = include_file.sub(/include\s/, '')
|
64
|
+
# If no extension provided, add one
|
65
|
+
if include_file.scan(/.pug/).length == 0
|
66
|
+
include_file = include_file + ".pug"
|
67
|
+
end
|
68
|
+
jp("Checking the include " + include_file)
|
69
|
+
# Make the include file into an exact path into the user's project
|
70
|
+
include_file = $JEKYLLPUG_PROJECT_SOURCE + "/" + include_file
|
71
|
+
jp("The include file is " + include_file)
|
72
|
+
# Create the cached location of the include file and its path
|
73
|
+
include_cache_file = ".pug-cache/" + include_file
|
74
|
+
include_cache_file_dir = include_cache_file.sub(filename_regex, '')
|
75
|
+
# Make a cache folder for this include if not already created
|
76
|
+
FileUtils.mkdir_p(include_cache_file_dir) unless ::File.exists?(include_cache_file_dir)
|
77
|
+
|
78
|
+
# Read the file of the include
|
79
|
+
include_content = ::File.read(include_file)
|
80
|
+
|
81
|
+
# If cached version of include exists
|
82
|
+
if ::File.file?(include_cache_file)
|
83
|
+
jp("Cached file of include exists. Checking if modified...")
|
84
|
+
cached_include_content = ::File.read(include_cache_file)
|
85
|
+
if include_content == cached_include_content
|
86
|
+
jp("The include is identical to the cache. Not recompiling")
|
87
|
+
else
|
88
|
+
jp("There has been a change in an include")
|
89
|
+
pugIncludeChange = true
|
90
|
+
end
|
91
|
+
else
|
92
|
+
jp("Creating cache file for include...")
|
93
|
+
pugIncludeChange = true
|
94
|
+
create_cache(include_content, include_cache_file)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# If files are identical
|
99
|
+
if content == cached_file_content and not pugIncludeChange
|
100
|
+
jp("Cached file is identical and includes haven't changed. Using Cached file")
|
101
|
+
# If there is a cached HTML file availible
|
102
|
+
cached_html_filename = cached_file + ".html"
|
103
|
+
if ::File.file?(cached_html_filename)
|
104
|
+
content = ::File.read(cached_html_filename)
|
105
|
+
else
|
106
|
+
jp("Odd. The HTML cached file does not exist. Can't use cache right now. Creating it instead.")
|
107
|
+
content = create_cache_and_compile(content, cached_file)
|
108
|
+
end
|
109
|
+
# If not identical (There has been a change)
|
110
|
+
else
|
111
|
+
jp("There has been a change since last cache. Re-Caching...")
|
112
|
+
content = create_cache_and_compile(content, cached_file)
|
113
|
+
end
|
114
|
+
else
|
115
|
+
jp("No cached file availible. Creating one...")
|
116
|
+
content = create_cache_and_compile(content, cached_file)
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
if content.lines.first =~ /^$/
|
121
|
+
content = content.sub(/^$\n/, "")
|
122
|
+
end
|
123
|
+
measure_time do
|
124
|
+
@template = Liquid::Template.parse(content, :line_numbers => true)
|
125
|
+
end
|
10
126
|
end
|
11
|
-
# if content.lines.first =~ /^$/
|
12
|
-
# content = content.sub(/^$\n/, "")
|
13
|
-
# end
|
14
|
-
@template = Liquid::Template.parse(content, :line_numbers => true)
|
15
127
|
end
|
16
|
-
|
17
|
-
self
|
18
|
-
end
|
19
128
|
end
|
20
|
-
end
|
21
129
|
end
|
22
130
|
|
23
131
|
# This section ensures that Pug files are compiled as HTML.
|
24
132
|
module Jekyll
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
133
|
+
class PugConverter < Converter
|
134
|
+
safe true
|
135
|
+
priority :low
|
136
|
+
|
137
|
+
def matches(ext)
|
138
|
+
ext =~ /^\.pug$/i
|
139
|
+
end
|
140
|
+
|
141
|
+
def output_ext(ext)
|
142
|
+
".html"
|
143
|
+
end
|
144
|
+
|
145
|
+
def convert(content)
|
146
|
+
return content
|
147
|
+
end
|
148
|
+
end
|
41
149
|
end
|