Top Level Namespace
Defined Under Namespace
Modules: Jekyll
Classes: Paths
Instance Method Summary
collapse
Instance Method Details
#all_steps_to_path(path) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/support/helpers.rb', line 58
def all_steps_to_path(path)
source = source_dir
dest = Pathname.new(path).expand_path
paths = []
dest.ascend do |f|
break if f == source
paths.unshift f.to_s
end
paths
end
|
#dst_active? ⇒ Boolean
Helper method for Windows
175
176
177
178
179
180
181
182
183
|
# File 'lib/support/helpers.rb', line 175
def dst_active?
config = Jekyll.configuration("quiet" => true)
ENV["TZ"] = config["timezone"]
dst = Time.now.isdst
ENV["TZ"] = nil
dst
end
|
#file_content_from_hash(input_hash) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/support/helpers.rb', line 26
def file_content_from_hash(input_hash)
matter_hash = input_hash.reject { |k, _v| k == "content" }
matter = matter_hash.map do |k, v|
"#{k}: #{v}\n"
end
matter = matter.join.chomp
content = \
if !input_hash["input"] || !input_hash["filter"]
then input_hash["content"]
else "{{ #{input_hash["input"]} | " \
"#{input_hash["filter"]} }}"
end
Jekyll::Utils.strip_heredoc(<<-EOF)
---
#{matter.gsub(
%r!\n!, "\n "
)}
---
#{content}
EOF
end
|
#file_contents(path) ⇒ Object
148
149
150
|
# File 'lib/support/helpers.rb', line 148
def file_contents(path)
return Pathname.new(path).read
end
|
#jekyll_run_output ⇒ Object
#jekyll_run_status ⇒ Object
#location(folder, direction) ⇒ Object
136
137
138
139
140
141
142
143
144
|
# File 'lib/support/helpers.rb', line 136
def location(folder, direction)
if folder
before = folder if direction == "in"
after = folder if direction == "under"
end
[before || ".",
after || ".",]
end
|
#run_bundle(args) ⇒ Object
89
90
91
|
# File 'lib/support/helpers.rb', line 89
def run_bundle(args)
run_in_shell("bundle", *args.strip.split(" "))
end
|
#run_in_shell(*args) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/support/helpers.rb', line 112
def run_in_shell(*args)
p, output = Jekyll::Utils::Exec.run(*args)
File.write(Paths.status_file, p.exitstatus)
File.open(Paths.output_file, "wb") do |f|
f.puts "$ " << args.join(" ")
f.puts output
f.puts "EXIT STATUS: #{p.exitstatus}"
end
p
end
|
#run_jekyll(args) ⇒ Object
101
102
103
104
105
106
107
108
109
|
# File 'lib/support/helpers.rb', line 101
def run_jekyll(args)
args = args.strip.split(" ")
process = run_in_shell("jekyll", *args, "--trace")
process.exitstatus.zero?
end
|
#run_rubygem(args) ⇒ Object
95
96
97
|
# File 'lib/support/helpers.rb', line 95
def run_rubygem(args)
run_in_shell("gem", *args.strip.split(" "))
end
|
#seconds_agnostic_datetime(datetime = Time.now) ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/support/helpers.rb', line 154
def seconds_agnostic_datetime(datetime = Time.now)
date, time, zone = datetime.to_s.split(" ")
time = seconds_agnostic_time(time)
[
Regexp.escape(date),
"#{time}:\\d{2}",
Regexp.escape(zone),
] \
.join("\\ ")
end
|
#seconds_agnostic_time(time) ⇒ Object
168
169
170
171
172
|
# File 'lib/support/helpers.rb', line 168
def seconds_agnostic_time(time)
time = time.strftime("%H:%M:%S") if time.is_a?(Time)
hour, minutes, = time.split(":")
"#{hour}:#{minutes}"
end
|
#slug(title = nil) ⇒ Object
127
128
129
130
131
132
|
# File 'lib/support/helpers.rb', line 127
def slug(title = nil)
if !title
then Time.now.strftime("%s%9N") else title.downcase.gsub(%r![^\w]!, " ").strip.gsub(%r!\s+!, "-")
end
end
|
#source_dir(*files) ⇒ Object
52
53
54
|
# File 'lib/support/helpers.rb', line 52
def source_dir(*files)
return Paths.test_dir(*files)
end
|