artifact 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/artifact.rb +21 -3
- data/lib/artifact/middleman.rb +2 -2
- data/lib/artifact/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 358f90040914655f57b8587936f038b9dd9a50db
|
4
|
+
data.tar.gz: ccc85a4d53981b2cfa5949964a982cecad6289d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb1275829dc2f91e8ff319c8a6cb1eb2dba4a147c2a1a8e28f655119e43d96e51082908e899f846e32a8c2b436598cdf0007b85083dae3f9a03ad74a4503d797
|
7
|
+
data.tar.gz: f22c0273c39cf19f9d48ad232129cbb35a9c59ba20bff78df481d12af229c70260cfbc9b64cd91bb3cdeb0678186685c9951c202a11cb2af468b3d0fa0ecc750
|
data/lib/artifact.rb
CHANGED
@@ -57,11 +57,19 @@ module Artifact
|
|
57
57
|
FileUtils.mkdir_p(dir) unless File.exist?(dir)
|
58
58
|
end
|
59
59
|
|
60
|
+
def self.run_hook(name, *args)
|
61
|
+
if proc = config.send(name)
|
62
|
+
puts " ------------> Running hook: #{name}"
|
63
|
+
proc.call(*args)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
60
67
|
class Config
|
61
68
|
|
62
69
|
attr_accessor *%w(
|
63
|
-
root source_root posts_path drafts_path uploads_path
|
70
|
+
root source_root posts_path drafts_path uploads_path
|
64
71
|
directory_indexes rebuild_args author_name author_email
|
72
|
+
before_update after_update
|
65
73
|
)
|
66
74
|
|
67
75
|
def initialize
|
@@ -72,6 +80,8 @@ module Artifact
|
|
72
80
|
@uploads_path = 'uploads'
|
73
81
|
@directory_indexes = true
|
74
82
|
@rebuild_args = ''
|
83
|
+
@before_update = nil
|
84
|
+
@after_update = nil
|
75
85
|
end
|
76
86
|
|
77
87
|
end
|
@@ -264,11 +274,19 @@ module Artifact
|
|
264
274
|
|
265
275
|
class WritableFile < ReadableFile
|
266
276
|
|
267
|
-
def update(
|
277
|
+
def update(new_content, meta = nil)
|
278
|
+
if new_content == read
|
279
|
+
return puts "No changes. No need to write changes to disk."
|
280
|
+
end
|
281
|
+
|
268
282
|
Artifact.ensure_dir!(@full_path)
|
283
|
+
Artifact.run_hook :before_update, new_content
|
284
|
+
|
269
285
|
# File.open(@full_path, 'wb') { |f| f.write(content.gsub("\r\n", "\n")) }
|
270
|
-
File.open(@full_path, 'wb') { |f| f.write(
|
286
|
+
File.open(@full_path, 'wb') { |f| f.write(new_content) }
|
271
287
|
@content = nil
|
288
|
+
|
289
|
+
Artifact.run_hook :after_update, new_content
|
272
290
|
end
|
273
291
|
|
274
292
|
def delete
|
data/lib/artifact/middleman.rb
CHANGED
@@ -113,7 +113,7 @@ module Artifact
|
|
113
113
|
@post = MarkdownFile.new(params[:splat][0])
|
114
114
|
|
115
115
|
# ensure date is valid and insert author/last_updated_by
|
116
|
-
meta = check_post_meta! or halt(422, "Invalid meta.")
|
116
|
+
meta = check_post_meta! or halt(422, "Invalid meta.")
|
117
117
|
|
118
118
|
# puts "Writing content and meta to file: #{meta.inspect}"
|
119
119
|
@post.update(params[:content].gsub("\r\n", "\n"), meta)
|
@@ -177,7 +177,7 @@ module Artifact
|
|
177
177
|
meta = (params[:meta] || {}).symbolize_keys.merge(:last_updated_by => current_user[:email])
|
178
178
|
|
179
179
|
if meta[:date]
|
180
|
-
puts "Meta date is #{meta[:date]}"
|
180
|
+
# puts "Meta date is #{meta[:date]}"
|
181
181
|
return false unless valid_date?(meta[:date])
|
182
182
|
else # no date, set current
|
183
183
|
meta[:date] = Time.now.utc.strftime("%Y-%m-%d %H:%M %Z")
|
data/lib/artifact/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: artifact
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomás Pollak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|