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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83259484f6fc95aecd48284b309768af5290b259
4
- data.tar.gz: 91a451bd1eb4f5f02ba0a36155f9c523059c62ab
3
+ metadata.gz: 8a5b74e48d8e52d1b839ab478b3ff904fa3603d0
4
+ data.tar.gz: baf352d3dd008c1ae56aa3cc9d8271807b722af8
5
5
  SHA512:
6
- metadata.gz: c3eff2798e4308cbb5582fc3b0a7556c10e24541ddc27958d7501e6fb6f21aacdf2e330a8ec5863922364b3e0a12d2cba610ea4453d306c22bf7d6f7de658fdc
7
- data.tar.gz: 96cb35e219ce11141531d8c7d83c895bf0edaa8ecc9c282197a91dd98c2e1ec6f0190c3a8415f7d10e91bd0b3183a264468eb18042e1377e09445b7abb9670e9
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
- @device = DeviceDetector.new(request.user_agent).device_type
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
 
@@ -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('page', options[:path], options[:tags])
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('block', options[:path], tags)
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('block', options[:path], tags)
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
- html = get_cached_content('page', options[:path], options[:tags])
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.1' unless defined?(Marfa::VERSION)
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
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'marfa'
6
- s.version = '0.3.1'
6
+ s.version = '0.3.2'
7
7
  s.required_ruby_version = '>= 2.3.0'
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.date = Time.now.strftime('%Y-%m-%d')
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.1
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-03-17 00:00:00.000000000 Z
13
+ date: 2017-04-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: haml