marfa 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3d5a42f314e9baa5f4a7a0b1f61836c3eb9aed8
4
- data.tar.gz: cd3210d2a966c921c7940588d18358d8f91e6a9f
3
+ metadata.gz: c1a41778eb844114cb830fe48aa4c3be812e263d
4
+ data.tar.gz: a60191698afc032ffcfa2bf242a52353c897744d
5
5
  SHA512:
6
- metadata.gz: 81629c24e7a78183c4e913f9623213e4d8e3f965e35dcf6801a66aefbb3438a4767d43500502517a1c278314ef7503b4c667e281871d8b4dde8ac53aa14494cb
7
- data.tar.gz: d762340e9ba8850f4956460144d6a844b7cb6002180b18a29026281fb2329656e35fd8ef056397ea2b7df4f8f14462ddcdfee62730b70837be91654e00ebc07a
6
+ metadata.gz: a54094bfc1431e0dd77016f45617fc9218f07d76c35d1ae6866e94ae3ada5d13e1a9572a6dd9dda3d74e9ff3ed0648ae320b70a117095d371b3bb093fec123e0
7
+ data.tar.gz: 6a56ad0267d509005b5a16f5c36b5f0ed3387199899019c0653012d5d5721bae8b734b3842729084df3b054936213512338eea9f2f2b0dd56f6bf08f060e581a
@@ -2,6 +2,6 @@
2
2
  module Marfa
3
3
  # return css version
4
4
  def self.css_version
5
- @css_version ||= Time.now.to_i.freeze
5
+ @css_version ||= Time.now.to_i.to_s.freeze
6
6
  end
7
7
  end
@@ -23,18 +23,18 @@ module Marfa
23
23
  end
24
24
 
25
25
  # Render page from cache, return html
26
- # @param path [String] - URL
27
- # @param tags [Array] - tag list
28
- # @param data [Hash] - options hash
26
+ # @param options [Hash] - options hash
29
27
  # @example
30
- # render_page('index', ['tag1', 'tag2'], {})
28
+ # render_page({ path: 'index', tags: ['tag1', 'tag2'], data: {} })
31
29
  # @return [String] rendered content
32
- def render_page(path, tags, data, cache_time = Marfa.config.cache[:expiration_time])
33
- full_path = 'pages/' + path
34
- return render_content(full_path, data) if cache_time == 0
30
+ def render_page(options)
31
+ cache_time = options[:cache_time] || Marfa.config.cache[:expiration_time]
35
32
 
36
- cache_key = Marfa.cache.create_key('page', path, tags)
37
- render_cached_content(cache_key, full_path, data)
33
+ full_path = 'pages/' + options[:path]
34
+ return render_content(full_path, options[:data]) if cache_time == 0
35
+
36
+ cache_key = Marfa.cache.create_key('page', options[:path], options[:tags])
37
+ render_cached_content(cache_key, full_path, options[:data])
38
38
  end
39
39
 
40
40
  # Render page from cache, store to cache, return html
@@ -48,40 +48,39 @@ module Marfa
48
48
  def get_cached_content(kind, path, tags = [])
49
49
  cache_key = Marfa.cache.create_key(kind, path, tags)
50
50
  return Marfa.cache.get(cache_key) if Marfa.cache.exist?(cache_key)
51
+ nil
51
52
  end
52
53
 
53
54
  # Render block from cache, return html
54
- # @param path [String] - URL
55
- # @param tags [Array] - tag list
56
- # @param query [Hash] - query params
57
- # @param class_name [String] - class name to block
55
+ # @param options [Hash] - options hash
58
56
  # @example
59
- # render_block('index/index', ['tag1', 'tag2'])
57
+ # render_block({ path: 'index/index', tags: ['tag1', 'tag2'] })
60
58
  # @return [String] rendered block
61
- def render_block(path, tags = [], query = {}, class_name = nil, cache_time = Marfa.config.cache[:expiration_time])
59
+ def render_block(options)
62
60
  # TODO: Improve caching with parameters
61
+ cache_time = options[:cache_time] || Marfa.config.cache[:expiration_time]
62
+ tags = options[:tags] || []
63
+
63
64
  if cache_time > 0
64
- content = get_cached_content('block', path, tags)
65
+ content = get_cached_content('block', options[:path], tags)
65
66
  return content unless content.nil?
66
67
  end
67
68
 
68
- classname = class_name || (path.to_class_name + 'Block')
69
+ classname = options[:class_name] || (options[:path].to_class_name + 'Block')
69
70
  return unless Object.const_defined?(classname)
70
71
 
71
72
  attrs = {
72
73
  user_data: @user_data || {},
73
- query: query
74
+ query: options[:query] || {}
74
75
  }
75
76
 
76
77
  block = Object.const_get(classname).new
77
78
  data = block.get_data(attrs)
78
-
79
-
80
- full_path = Marfa.config.block_templates_path + '/' + path
79
+ full_path = Marfa.config.block_templates_path + '/' + options[:path]
81
80
 
82
81
  return render_content(full_path, data) if cache_time == 0
83
82
 
84
- cache_key = Marfa.cache.create_key('block', path, tags)
83
+ cache_key = Marfa.cache.create_key('block', options[:path], tags)
85
84
  render_cached_content(cache_key, full_path, data)
86
85
  end
87
86
 
@@ -114,18 +113,19 @@ module Marfa
114
113
  end
115
114
 
116
115
  # Get HTML from cache or render new
117
- # @param path [String] - URL
118
- # @param tags [Array] - tag list
119
- # @param data [Hash] - data to render
116
+ # @param options [Hash] - params
120
117
  # @example
121
- # get_html('index/index', ['tag1', 'tag2'], {})
118
+ # get_html({ path: 'index', tags: ['tag1', 'tag2'], data: {} })
122
119
  # @return [String] HTML
123
- def get_html(path, tags, data, cache_time = Marfa.config.cache[:expiration_time])
120
+ # def get_html(path, tags, data, cache_time = Marfa.config.cache[:expiration_time])
121
+ def get_html(options)
122
+ cache_time = options[:cache_time] || Marfa.config.cache[:expiration_time]
123
+
124
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?
125
+ html = get_cached_content('page', options[:path], options[:tags])
126
+ html = render_page(options) if html.nil?
127
127
  else
128
- html = render_page(path, tags, data, cache_time)
128
+ html = render_page(options)
129
129
  end
130
130
  html
131
131
  end
@@ -7,25 +7,23 @@ module Marfa
7
7
  # Provide helpers for Sinatra controllers
8
8
  module Email
9
9
  # Send email using mailbox config
10
- # @param template [String] - path to template file
11
- # @param to [String] - email address to send
12
- # @param subject [String] - email subject
13
- # @param data [Hash] - data to render in template
14
- # @param mailbox [Symbol] - mailbox config
10
+ # @param options [Hash] - params
15
11
  # @example:
16
- # send_email('mail', 'user@example.com', :admin, 'Hello', { title: 'Hello!' })
17
- def send_email(template, to, mailbox = :default, subject = '', data = {})
12
+ # send_email({ template: 'mail', to: 'user@example.com', mailbox: :admin, subject: 'Hello', data: { title: 'Hello!' } })
13
+ def send_email(options)
14
+ mailbox = options[:mailbox] || :default
15
+
18
16
  config = Marfa.config.email[mailbox]
19
17
  return if config.nil?
20
18
 
21
- body = haml :"#{template}", locals: data, layout: false
19
+ body = haml :"#{options[:template]}", locals: options[:data], layout: false
22
20
 
23
21
  Pony.options = {
24
22
  via: :smtp,
25
23
  via_options: config
26
24
  }
27
25
 
28
- Pony.mail(to: to, subject: subject, html_body: body)
26
+ Pony.mail(to: options[:to], subject: options[:subject], html_body: body)
29
27
  end
30
28
  end
31
29
  end
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.2' unless defined?(Marfa::VERSION)
4
+ VERSION = '0.3.0' 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.2.2'
6
+ s.version = '0.3.0'
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.2.2
4
+ version: 0.3.0
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-17 00:00:00.000000000 Z
13
+ date: 2017-02-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: haml