prez 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82d042197610a8de84aefe9c5d966f5d5c218eba
4
- data.tar.gz: 67e617fa968d220c919ddeea986ca007f3a2e55c
3
+ metadata.gz: e325c1dbad022344147a475103c01c68b9592584
4
+ data.tar.gz: 784d73087e3934e7b5310e624fd1666e4a7f6f99
5
5
  SHA512:
6
- metadata.gz: 25b2fddcb34be8dd5a376698d011bc9cfd1c949700c5af3eb9a82500c1be6c438d0ded954caaca8c956a713a6a504c1fde5eb407d1beb2f34444ece76985c62e
7
- data.tar.gz: 9888f3403ac1575ba470643ee616e7471db98caef858dd6eed70eb3844a9e5933a63b0339878d79e53361af7a79913c1ef2065993aa1ffc1b2081c07b050a249
6
+ metadata.gz: 3359570ebebc0c6904d9d1edbedd04002b32dacd03ab1fd6ffa55c03e48906d0d0b97cd99beacc624a3bdfc02d6faa0b8af7452a894678ea7c87debd2f98dcd2
7
+ data.tar.gz: c5f7a441190afbfcb7c1ad1fe7cf1da6d8032f564bfc7f3e92ca7fb6e8ed3b235989182291a40fb6bf987a357da3c7458737f858a8f6fc84c63cc963c90f2256
data/bin/prez CHANGED
@@ -2,7 +2,7 @@
2
2
  require "rubygems"
3
3
  gem "coffee-script", "~> 2.3"
4
4
  gem "launchy", "~> 2.4"
5
- gem "prez", "= 0.0.3"
5
+ gem "prez", "= 0.0.4"
6
6
  gem "sass", "~> 3.4"
7
7
  gem "therubyracer", "~> 0.12"
8
8
  gem "thor", "~> 0.19"
data/lib/prez/assets.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "coffee-script"
2
+ require "prez/cache"
2
3
  require "prez/data_uri"
3
4
  require "prez/error"
4
5
  require "prez/files"
@@ -26,8 +27,20 @@ module Prez
26
27
  false
27
28
  end
28
29
 
30
+ def compiled_contents
31
+ Prez::Cache.get "asset:#{extension}:compiled:#{file}", contents do
32
+ compile contents
33
+ end
34
+ end
35
+
36
+ def compile(contents)
37
+ contents
38
+ end
39
+
29
40
  def minified_contents
30
- minify contents
41
+ Prez::Cache.get "asset:#{extension}:minified:#{file}", compiled_contents do
42
+ minify compiled_contents
43
+ end
31
44
  end
32
45
 
33
46
  def minify(contents)
@@ -36,7 +49,7 @@ module Prez
36
49
 
37
50
  def to_tag
38
51
  if dev? && !self_closing?
39
- "#{open}\n#{contents}#{close}"
52
+ "#{open}\n#{compiled_contents}#{close}"
40
53
  else
41
54
  "#{open}#{minified_contents.strip}#{close}"
42
55
  end
@@ -89,7 +102,7 @@ module Prez
89
102
  end
90
103
  end
91
104
 
92
- def minify(contents)
105
+ def compile(contents)
93
106
  Prez::DataUri.new(image_type, contents).to_s
94
107
  end
95
108
  end
@@ -107,8 +120,15 @@ module Prez
107
120
  %{</script>}
108
121
  end
109
122
 
123
+ def compile(contents)
124
+ if file =~ /\.coffee$/
125
+ CoffeeScript.compile contents
126
+ else
127
+ contents
128
+ end
129
+ end
130
+
110
131
  def minify(contents)
111
- contents = CoffeeScript.compile contents if file =~ /\.coffee$/
112
132
  Uglifier.compile contents
113
133
  end
114
134
  end
@@ -126,11 +146,18 @@ module Prez
126
146
  %{</style>}
127
147
  end
128
148
 
149
+ def compile(contents)
150
+ Sass::Engine.new(contents,
151
+ syntax: :scss,
152
+ style: :expanded,
153
+ load_paths: [File.dirname(file)]).render
154
+ end
155
+
129
156
  def minify(contents)
130
157
  Sass::Engine.new(contents,
131
158
  syntax: :scss,
132
159
  style: :compressed,
133
- load_paths: [File.expand_path("..", file)]).render
160
+ load_paths: [File.dirname(file)]).render
134
161
  end
135
162
  end
136
163
 
data/lib/prez/cache.rb ADDED
@@ -0,0 +1,95 @@
1
+ require "digest"
2
+ require "fileutils"
3
+ require "prez/version"
4
+ require "yaml"
5
+
6
+ module Prez
7
+ class Cache
8
+ DIR = ".prez-cache"
9
+
10
+ attr_reader :toc
11
+
12
+ def initialize
13
+ unless File.directory?(dir)
14
+ Dir.mkdir dir
15
+ end
16
+
17
+ if File.exists?(toc_file)
18
+ @toc = YAML.load File.read(toc_file)
19
+ else
20
+ @toc = { prez_version: Prez::Version.to_s }
21
+ end
22
+ end
23
+
24
+ def dir
25
+ Prez::Cache::DIR
26
+ end
27
+
28
+ def toc_file
29
+ File.join dir, "toc.yml"
30
+ end
31
+
32
+ def include?(key, hash)
33
+ toc.include?(key) && File.file?(cached_path(key, hash))
34
+ end
35
+
36
+ def cached_path(key, hash)
37
+ File.join dir, Prez::Cache.md5(key), hash
38
+ end
39
+
40
+ def get(key, hash)
41
+ File.read cached_path(key, hash)
42
+ ensure
43
+ toc[key][:last_touched][hash] = Time.now
44
+ save
45
+ end
46
+
47
+ def put(key, hash, contents)
48
+ unless include?(key, hash)
49
+ toc[key] = {
50
+ last_touched: {},
51
+ saved: {}
52
+ }
53
+ end
54
+
55
+ path = cached_path key, hash
56
+
57
+ unless File.directory?(File.dirname(path))
58
+ FileUtils.makedirs File.dirname(path)
59
+ end
60
+
61
+ File.write path, contents
62
+ toc[key][:key_hash] = Prez::Cache.md5 key
63
+ toc[key][:last_touched][hash] = Time.now
64
+ toc[key][:saved][hash] = Time.now
65
+ ensure
66
+ save
67
+ end
68
+
69
+ def save
70
+ File.write toc_file, YAML.dump(toc)
71
+ end
72
+
73
+ class << self
74
+ def get(key, pre_cache_contents)
75
+ hash = md5 pre_cache_contents
76
+
77
+ if instance.include?(key, hash)
78
+ instance.get key, hash
79
+ else
80
+ yield.tap do |results|
81
+ instance.put key, hash, results
82
+ end
83
+ end
84
+ end
85
+
86
+ def md5(contents)
87
+ Digest::MD5.hexdigest contents
88
+ end
89
+
90
+ def instance
91
+ @instance ||= Prez::Cache.new
92
+ end
93
+ end
94
+ end
95
+ end
data/lib/prez/version.rb CHANGED
@@ -2,7 +2,7 @@ module Prez
2
2
  module Version
3
3
  class << self
4
4
  def to_s
5
- "0.0.3"
5
+ "0.0.4"
6
6
  end
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prez
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Virata-Stone
@@ -135,6 +135,7 @@ files:
135
135
  - lib/prez/assets.rb
136
136
  - lib/prez/build.rb
137
137
  - lib/prez/builder.rb
138
+ - lib/prez/cache.rb
138
139
  - lib/prez/cli.rb
139
140
  - lib/prez/data_uri.rb
140
141
  - lib/prez/error.rb