marfa 0.2.1 → 0.2.2
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/marfa/cache.rb +7 -2
- data/lib/marfa/helpers/controller.rb +29 -12
- data/lib/marfa/version.rb +1 -1
- data/marfa.gemspec +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: c3d5a42f314e9baa5f4a7a0b1f61836c3eb9aed8
|
4
|
+
data.tar.gz: cd3210d2a966c921c7940588d18358d8f91e6a9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81629c24e7a78183c4e913f9623213e4d8e3f965e35dcf6801a66aefbb3438a4767d43500502517a1c278314ef7503b4c667e281871d8b4dde8ac53aa14494cb
|
7
|
+
data.tar.gz: d762340e9ba8850f4956460144d6a844b7cb6002180b18a29026281fb2329656e35fd8ef056397ea2b7df4f8f14462ddcdfee62730b70837be91654e00ebc07a
|
data/lib/marfa/cache.rb
CHANGED
@@ -12,9 +12,14 @@ module Marfa
|
|
12
12
|
# Write data to cache
|
13
13
|
# @example
|
14
14
|
# Marfa.cache.set('key', 'value', 7200)
|
15
|
-
def set(key, value, _time =
|
15
|
+
def set(key, value, _time = nil)
|
16
16
|
return unless @config[:enabled]
|
17
|
-
|
17
|
+
if _time.is_a? Numeric
|
18
|
+
@redis.set(key, value, ex: _time) # ex - is seconds
|
19
|
+
else
|
20
|
+
@redis.set(key, value) #infinite
|
21
|
+
end
|
22
|
+
|
18
23
|
end
|
19
24
|
|
20
25
|
# Get data from cache
|
@@ -3,6 +3,11 @@ require 'marfa/configuration'
|
|
3
3
|
module Marfa
|
4
4
|
module Helpers
|
5
5
|
module Controller
|
6
|
+
|
7
|
+
def render_content(path, data)
|
8
|
+
haml :"#{path}", locals: data
|
9
|
+
end
|
10
|
+
|
6
11
|
# Rendering cached content
|
7
12
|
# @param cache_key [String] key
|
8
13
|
# @param path [String] - URL
|
@@ -10,10 +15,10 @@ module Marfa
|
|
10
15
|
# @example
|
11
16
|
# render_cached_content('some_key', 'path/url', {})
|
12
17
|
# @return [String] rendered content
|
13
|
-
def render_cached_content(cache_key, path, data = {})
|
18
|
+
def render_cached_content(cache_key, path, data = {}, cache_time = Marfa.config.cache[:expiration_time])
|
14
19
|
return Marfa.cache.get(cache_key) if Marfa.cache.exist?(cache_key)
|
15
|
-
output =
|
16
|
-
Marfa.cache.set(cache_key, output)
|
20
|
+
output = render_content(path, data)
|
21
|
+
Marfa.cache.set(cache_key, output, cache_time)
|
17
22
|
output
|
18
23
|
end
|
19
24
|
|
@@ -24,9 +29,11 @@ module Marfa
|
|
24
29
|
# @example
|
25
30
|
# render_page('index', ['tag1', 'tag2'], {})
|
26
31
|
# @return [String] rendered content
|
27
|
-
def render_page(path, tags, data)
|
28
|
-
cache_key = Marfa.cache.create_key('page', path, tags)
|
32
|
+
def render_page(path, tags, data, cache_time = Marfa.config.cache[:expiration_time])
|
29
33
|
full_path = 'pages/' + path
|
34
|
+
return render_content(full_path, data) if cache_time == 0
|
35
|
+
|
36
|
+
cache_key = Marfa.cache.create_key('page', path, tags)
|
30
37
|
render_cached_content(cache_key, full_path, data)
|
31
38
|
end
|
32
39
|
|
@@ -51,10 +58,12 @@ module Marfa
|
|
51
58
|
# @example
|
52
59
|
# render_block('index/index', ['tag1', 'tag2'])
|
53
60
|
# @return [String] rendered block
|
54
|
-
def render_block(path, tags = [], query = {}, class_name = nil)
|
61
|
+
def render_block(path, tags = [], query = {}, class_name = nil, cache_time = Marfa.config.cache[:expiration_time])
|
55
62
|
# TODO: Improve caching with parameters
|
56
|
-
|
57
|
-
|
63
|
+
if cache_time > 0
|
64
|
+
content = get_cached_content('block', path, tags)
|
65
|
+
return content unless content.nil?
|
66
|
+
end
|
58
67
|
|
59
68
|
classname = class_name || (path.to_class_name + 'Block')
|
60
69
|
return unless Object.const_defined?(classname)
|
@@ -66,9 +75,13 @@ module Marfa
|
|
66
75
|
|
67
76
|
block = Object.const_get(classname).new
|
68
77
|
data = block.get_data(attrs)
|
69
|
-
|
78
|
+
|
79
|
+
|
70
80
|
full_path = Marfa.config.block_templates_path + '/' + path
|
71
81
|
|
82
|
+
return render_content(full_path, data) if cache_time == 0
|
83
|
+
|
84
|
+
cache_key = Marfa.cache.create_key('block', path, tags)
|
72
85
|
render_cached_content(cache_key, full_path, data)
|
73
86
|
end
|
74
87
|
|
@@ -107,9 +120,13 @@ module Marfa
|
|
107
120
|
# @example
|
108
121
|
# get_html('index/index', ['tag1', 'tag2'], {})
|
109
122
|
# @return [String] HTML
|
110
|
-
def get_html(path, tags, data)
|
111
|
-
|
112
|
-
|
123
|
+
def get_html(path, tags, data, cache_time = Marfa.config.cache[:expiration_time])
|
124
|
+
if cache_time > 0
|
125
|
+
html = get_cached_content('page', path, tags)
|
126
|
+
html = render_page(path, tags, data, cache_time) if html.nil?
|
127
|
+
else
|
128
|
+
html = render_page(path, tags, data, cache_time)
|
129
|
+
end
|
113
130
|
html
|
114
131
|
end
|
115
132
|
|
data/lib/marfa/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Version constant
|
2
2
|
module Marfa
|
3
3
|
# The version constant for the current version of Marfa
|
4
|
-
VERSION = '0.2.
|
4
|
+
VERSION = '0.2.2' unless defined?(Marfa::VERSION)
|
5
5
|
|
6
6
|
# The current Marfa version.
|
7
7
|
# @return [String] The version number
|
data/marfa.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marfa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Krechetov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-02-
|
13
|
+
date: 2017-02-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: haml
|