jekyll-pug 1.5.0 → 1.5.1
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 +9 -1
- data/lib/jekyll-pug/pug-renderer.rb +62 -51
- 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: 78242721e883bcf4d30eacfd8203c3cf737c5c8b
|
4
|
+
data.tar.gz: 3cdf6c977fdca49ffe4f03dd6312bb31810f79f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8bf37f988274a2ae92dbf3a55c1b6cbc91097ca8bb42c63b79e4c3083b247031e1c9243f3124ada448cc49dd6957e5eab9847627a8e8336ccf664d45fde20af
|
7
|
+
data.tar.gz: a8f28a52c2b00bcc7da31d1af1ce734fd0d2e05d37aa30f18c51405602e13fa7c12dc05196972323b1edc85346ef8098ee362d3572082fed1dc551a48ea78a4c
|
data/lib/jekyll-pug.rb
CHANGED
@@ -23,4 +23,12 @@ if $jekyllConfig['source']
|
|
23
23
|
config_source = $jekyllConfig['source']
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
dir = Dir.pwd
|
27
|
+
|
28
|
+
$JEKYLLPUG_PROJECT_SOURCE_ABS = config_source
|
29
|
+
$JEKYLLPUG_PROJECT_SOURCE = config_source.sub(/#{dir}/, '')
|
30
|
+
$JEKYLLPUG_PROJECT_INCLUDES = File.join($JEKYLLPUG_PROJECT_SOURCE, '_includes/.')
|
31
|
+
.sub(/^\//, '')
|
32
|
+
.sub(/\/\.$/, '')
|
33
|
+
|
34
|
+
$PUG_INCLUDES = File.join(config_source, '_includes/.')
|
@@ -14,10 +14,21 @@ def jp(string)
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
def announce(string)
|
18
|
+
if $jekyllConfig['jekyll-pug']
|
19
|
+
if $jekyllConfig['jekyll-pug']['debug']
|
20
|
+
puts ""
|
21
|
+
puts "############################"
|
22
|
+
puts "# " + string.to_s
|
23
|
+
puts "############################"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
17
28
|
def create_cache_and_compile(content, cached_file)
|
18
|
-
userSource = $JEKYLLPUG_PROJECT_SOURCE
|
19
29
|
pug_raw = content
|
20
|
-
|
30
|
+
jp("Compiling.....")
|
31
|
+
content = Pug.compile(content, {"filename"=>$PUG_INCLUDES})
|
21
32
|
::File.write(cached_file, pug_raw)
|
22
33
|
::File.write(cached_file+".html", content)
|
23
34
|
return content
|
@@ -32,10 +43,10 @@ module Jekyll
|
|
32
43
|
File.class_eval do
|
33
44
|
def parse(content)
|
34
45
|
if @filename =~ /\.pug$/
|
35
|
-
filename_regex = /[a-zA-Z1-9\s\~\-\.\_\%\#\&\*\{\}\:\?\+\|\<\>\"\']
|
46
|
+
filename_regex = /[a-zA-Z1-9\s\~\-\.\_\%\#\&\*\{\}\:\?\+\|\<\>\"\']+.\w+$/
|
36
47
|
|
37
48
|
$jekyll_pug_curFile = @filename.match(filename_regex)
|
38
|
-
|
49
|
+
announce("Processing " + @filename)
|
39
50
|
|
40
51
|
# Creating Cache Variables
|
41
52
|
cache_dir = ".pug-cache/"
|
@@ -45,74 +56,74 @@ module Jekyll
|
|
45
56
|
# Creating cache directory neccesary (if needed)
|
46
57
|
FileUtils.mkdir_p(cached_file_dir) unless ::File.exists?(cached_file_dir)
|
47
58
|
|
59
|
+
# Loop through Pug includes to determine if any had been modified
|
60
|
+
jp("Checking the Pug includes of " + @filename)
|
61
|
+
pugIncludeChange = false
|
62
|
+
includes_in_file = content.scan(/^\s+include\s[a-zA-Z1-9\/\_\-\.]+/)
|
63
|
+
for i in includes_in_file do
|
64
|
+
# Remove spaces/tabs in front of code
|
65
|
+
include_file = i.sub(/^\s+/, '')
|
66
|
+
# Remove include statement to be left with filename
|
67
|
+
include_file = include_file.sub(/include\s/, '')
|
68
|
+
# If no extension provided, add one
|
69
|
+
if include_file.scan(/\.\w+/).length == 0
|
70
|
+
include_file = include_file + ".pug"
|
71
|
+
end
|
72
|
+
jp(" Checking the include " + include_file)
|
73
|
+
# Make the include file into an exact path into the user's project
|
74
|
+
include_file = $JEKYLLPUG_PROJECT_INCLUDES + "/" + include_file
|
75
|
+
# Create the cached location of the include file and its path
|
76
|
+
include_cache_file = ".pug-cache/" + include_file.sub(/#{$JEKYLLPUG_PROJECT_SOURCE}/, '')
|
77
|
+
include_cache_file_dir = include_cache_file.sub(filename_regex, '')
|
78
|
+
# Make a cache folder for this include if not already created
|
79
|
+
FileUtils.mkdir_p(include_cache_file_dir) unless ::File.exists?(include_cache_file_dir)
|
80
|
+
|
81
|
+
# Read the file of the include
|
82
|
+
include_content = ::File.read(include_file)
|
83
|
+
|
84
|
+
# If cached version of include exists
|
85
|
+
if ::File.file?(include_cache_file)
|
86
|
+
jp(" Cached file of include exists. Checking if modified...")
|
87
|
+
cached_include_content = ::File.read(include_cache_file)
|
88
|
+
if include_content == cached_include_content
|
89
|
+
jp(" The include is identical to the cache. Not recompiling")
|
90
|
+
else
|
91
|
+
jp(" There has been a change in an include")
|
92
|
+
pugIncludeChange = true
|
93
|
+
end
|
94
|
+
else
|
95
|
+
jp(" Cached file of include does not exist. Creating cache file for include...")
|
96
|
+
pugIncludeChange = true
|
97
|
+
create_cache(include_content, include_cache_file)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
48
101
|
# If cached pug file exists
|
49
102
|
if ::File.file?(cached_file)
|
50
|
-
jp("Cached file exists! Attempting to use it...")
|
103
|
+
jp("Cached file of " + @filename + " exists! Attempting to use it...")
|
51
104
|
cached_file_content = ::File.read(cached_file)
|
52
105
|
|
53
|
-
pugIncludeChange = false
|
54
106
|
# Check if Pug includes have changed.
|
55
107
|
# If Pug includes changed, we must recompile
|
56
108
|
|
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
109
|
# If files are identical
|
99
110
|
if content == cached_file_content and not pugIncludeChange
|
100
|
-
jp("Cached file is identical and includes haven't changed. Using Cached file")
|
111
|
+
jp("Cached file of " + @filename + " is identical and includes haven't changed. Using Cached file")
|
101
112
|
# If there is a cached HTML file availible
|
102
113
|
cached_html_filename = cached_file + ".html"
|
103
114
|
if ::File.file?(cached_html_filename)
|
104
115
|
content = ::File.read(cached_html_filename)
|
105
116
|
else
|
106
|
-
jp("
|
117
|
+
jp("The HTML cached file of " + @filename + " does not exist. Can't use cache file right now. Creating it instead.")
|
107
118
|
content = create_cache_and_compile(content, cached_file)
|
108
119
|
end
|
109
120
|
# If not identical (There has been a change)
|
110
121
|
else
|
111
|
-
jp("There has been a change since last cache. Re-Caching...")
|
122
|
+
jp("There has been a change since last cache. Re-Caching " + @filename + "...")
|
112
123
|
content = create_cache_and_compile(content, cached_file)
|
113
124
|
end
|
114
125
|
else
|
115
|
-
jp("No cached file availible. Creating one...")
|
126
|
+
jp("No cached file for " + @filename + " availible. Creating one...")
|
116
127
|
content = create_cache_and_compile(content, cached_file)
|
117
128
|
end
|
118
129
|
|