marfa 0.3.1 → 0.3.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/controllers/base_controller.rb +5 -1
- data/lib/marfa/file_templates.rb +8 -1
- data/lib/marfa/helpers/controller.rb +25 -4
- 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: 8a5b74e48d8e52d1b839ab478b3ff904fa3603d0
|
|
4
|
+
data.tar.gz: baf352d3dd008c1ae56aa3cc9d8271807b722af8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a4417f1b8e6d7604a7bafa514eabce7cd8679614a582193a1ff8a183f9fe6bb2bbad8edbac2616c77c03cc37c632393bfdee3f6750be1d4e1f0be92274e7f23f
|
|
7
|
+
data.tar.gz: a50ce5b4026964bd194cc0863aa9c58e4d3bd555e459fee5fb39b1e77cc036f63128097bc6dcf42521d0921338f4cffc02b7cf82deb50dcbcc58620229d831c7
|
|
@@ -12,7 +12,11 @@ module Marfa
|
|
|
12
12
|
# base controller
|
|
13
13
|
class BaseController < Sinatra::Base
|
|
14
14
|
before do
|
|
15
|
-
|
|
15
|
+
if Marfa.config.device_detector[:enabled]
|
|
16
|
+
@device = DeviceDetector.new(request.user_agent).device_type
|
|
17
|
+
@device = Marfa.config.device_detector[:default_device] if @device.nil?
|
|
18
|
+
end
|
|
19
|
+
|
|
16
20
|
@css_version = Marfa.css_version
|
|
17
21
|
end
|
|
18
22
|
|
data/lib/marfa/file_templates.rb
CHANGED
|
@@ -27,7 +27,8 @@ Marfa.configure do |cfg|
|
|
|
27
27
|
host: '',
|
|
28
28
|
port: 0,
|
|
29
29
|
db: 0,
|
|
30
|
-
expiration_time: 3600
|
|
30
|
+
expiration_time: 3600,
|
|
31
|
+
use_device: true # use device name in page, blocks cache
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
# Static files content path
|
|
@@ -48,6 +49,12 @@ Marfa.configure do |cfg|
|
|
|
48
49
|
# CSRF Protection
|
|
49
50
|
cfg.csrf_enabled = false
|
|
50
51
|
|
|
52
|
+
# gem device_detector
|
|
53
|
+
cfg.device_detector = {
|
|
54
|
+
enabled: true,
|
|
55
|
+
default_device: 'smartphone'
|
|
56
|
+
}
|
|
57
|
+
|
|
51
58
|
# HTML Compression
|
|
52
59
|
cfg.html_compression_options = {
|
|
53
60
|
enabled: true,
|
|
@@ -30,10 +30,13 @@ module Marfa
|
|
|
30
30
|
def render_page(options)
|
|
31
31
|
cache_time = options[:cache_time] || Marfa.config.cache[:expiration_time]
|
|
32
32
|
|
|
33
|
+
kind = 'page'
|
|
34
|
+
kind += "-#{@device}" if Marfa.config.cache[:use_device]
|
|
35
|
+
|
|
33
36
|
full_path = 'pages/' + options[:path]
|
|
34
37
|
return render_content(full_path, options[:data]) if cache_time == 0
|
|
35
38
|
|
|
36
|
-
cache_key = Marfa.cache.create_key(
|
|
39
|
+
cache_key = Marfa.cache.create_key(kind, options[:path], options[:tags])
|
|
37
40
|
render_cached_content(cache_key, full_path, options[:data])
|
|
38
41
|
end
|
|
39
42
|
|
|
@@ -51,6 +54,17 @@ module Marfa
|
|
|
51
54
|
nil
|
|
52
55
|
end
|
|
53
56
|
|
|
57
|
+
# convert query json to tags
|
|
58
|
+
# @param query [Hash] - hash of params
|
|
59
|
+
# @return [Array] of strings key-value or []
|
|
60
|
+
def query_to_tags(query)
|
|
61
|
+
result = []
|
|
62
|
+
if query.is_a? Hash
|
|
63
|
+
query.each { |key, value| result << "#{key}-#{value}" }
|
|
64
|
+
end
|
|
65
|
+
result
|
|
66
|
+
end
|
|
67
|
+
|
|
54
68
|
# Render block from cache, return html
|
|
55
69
|
# @param options [Hash] - options hash
|
|
56
70
|
# @example
|
|
@@ -61,8 +75,12 @@ module Marfa
|
|
|
61
75
|
cache_time = options[:cache_time] || Marfa.config.cache[:expiration_time]
|
|
62
76
|
tags = options[:tags] || []
|
|
63
77
|
|
|
78
|
+
kind = 'block'
|
|
79
|
+
kind += "-#{@device}" if Marfa.config.cache[:use_device]
|
|
80
|
+
tags += query_to_tags(options[:query])
|
|
81
|
+
|
|
64
82
|
if cache_time > 0
|
|
65
|
-
content = get_cached_content(
|
|
83
|
+
content = get_cached_content(kind, options[:path], tags)
|
|
66
84
|
return content unless content.nil?
|
|
67
85
|
end
|
|
68
86
|
|
|
@@ -80,7 +98,7 @@ module Marfa
|
|
|
80
98
|
|
|
81
99
|
return render_content(full_path, data) if cache_time == 0
|
|
82
100
|
|
|
83
|
-
cache_key = Marfa.cache.create_key(
|
|
101
|
+
cache_key = Marfa.cache.create_key(kind, options[:path], tags)
|
|
84
102
|
render_cached_content(cache_key, full_path, data)
|
|
85
103
|
end
|
|
86
104
|
|
|
@@ -122,7 +140,10 @@ module Marfa
|
|
|
122
140
|
cache_time = options[:cache_time] || Marfa.config.cache[:expiration_time]
|
|
123
141
|
|
|
124
142
|
if cache_time > 0
|
|
125
|
-
|
|
143
|
+
kind = 'page'
|
|
144
|
+
kind += "-#{@device}" if Marfa.config.cache[:use_device]
|
|
145
|
+
|
|
146
|
+
html = get_cached_content(kind, options[:path], options[:tags])
|
|
126
147
|
html = render_page(options) if html.nil?
|
|
127
148
|
else
|
|
128
149
|
html = render_page(options)
|
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.3.
|
|
4
|
+
VERSION = '0.3.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.3.
|
|
4
|
+
version: 0.3.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-
|
|
13
|
+
date: 2017-04-04 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: haml
|