middleman-cache-do 0.1.0
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 +7 -0
- data/.gitignore +5 -0
- data/Gemfile +18 -0
- data/README.md +52 -0
- data/Rakefile +14 -0
- data/features/support/env.rb +4 -0
- data/lib/middleman-cache-do.rb +6 -0
- data/lib/middleman-cache-do/extension.rb +33 -0
- data/middleman-cache-do.gemspec +25 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e859598b349c4104c8353743745ee6d914299264
|
4
|
+
data.tar.gz: bacf12b225c7f44616d7b70fe106aa2da019915d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 51b0ce6bdeade859bd9fd174a2147e4a32c9a7781374d582f2c52dd5c21b7cef511998812ad8178a936371bc0428726ba095251cdbcf56bd12de26ebf6c7c525
|
7
|
+
data.tar.gz: 694237f8a6dc3ac79f01a418f48122107bcea36a23da7dcc324a0da28e77703b8f2edb52cf835bc9755db6b60f2b74948cfa4339616826c83ce1b1814c65855b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# If you do not have OpenSSL installed, update
|
2
|
+
# the following line to use "http://" instead
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in middleman-cache-do.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem 'rake'
|
10
|
+
gem 'rdoc'
|
11
|
+
gem 'yard'
|
12
|
+
end
|
13
|
+
|
14
|
+
group :test do
|
15
|
+
gem 'cucumber'
|
16
|
+
gem 'aruba'
|
17
|
+
gem 'rspec'
|
18
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Middleman Cache Do
|
2
|
+
|
3
|
+
Cache blocks of stuff into a memcache store. Handy for when you're making API calls between lots of builds.
|
4
|
+
|
5
|
+
## Example Usage
|
6
|
+
|
7
|
+
### Gemfile
|
8
|
+
|
9
|
+
gem 'dalli' # Your memcache client.
|
10
|
+
gem 'middleman-cache-do'
|
11
|
+
|
12
|
+
|
13
|
+
### Install memcache locally
|
14
|
+
|
15
|
+
brew install memcache
|
16
|
+
|
17
|
+
|
18
|
+
### .env
|
19
|
+
|
20
|
+
MEMCACHEDCLOUD_SERVERS="127.0.0.1:11211"
|
21
|
+
MEMCACHEDCLOUD_USERNAME=""
|
22
|
+
MEMCACHEDCLOUD_PASSWORD=""
|
23
|
+
|
24
|
+
|
25
|
+
### config.rb
|
26
|
+
|
27
|
+
activate :middleman_cache_do do |config|
|
28
|
+
config.client = Dalli::Client.new(ENV['MEMCACHEDCLOUD_SERVERS'].split(','), {
|
29
|
+
username: ENV['MEMCACHEDCLOUD_USERNAME'],
|
30
|
+
password: ENV['MEMCACHEDCLOUD_PASSWORD'],
|
31
|
+
namespace: 'middleman_cache_do',
|
32
|
+
compress: true
|
33
|
+
}) if ENV['MEMCACHEDCLOUD_SERVERS']
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
### In your Helpers
|
38
|
+
|
39
|
+
helpers do
|
40
|
+
def some_cached_method
|
41
|
+
app.cache 'some_method' do
|
42
|
+
{ json: :blob } # Call your external API here.
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
### In your views
|
49
|
+
|
50
|
+
<%= cache 'Some-Key' do %>
|
51
|
+
<!-- Some external call to an API -->
|
52
|
+
<% end %>
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'cucumber/rake/task'
|
5
|
+
|
6
|
+
Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
|
7
|
+
t.cucumber_opts = '--color --tags ~@wip --strict'
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rake/clean'
|
11
|
+
|
12
|
+
task test: ['cucumber']
|
13
|
+
|
14
|
+
task default: :test
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Require core library
|
2
|
+
require 'middleman-core'
|
3
|
+
|
4
|
+
# Extension namespace
|
5
|
+
module MiddlemanCacheDo
|
6
|
+
class Extension < ::Middleman::Extension
|
7
|
+
option :client, nil, 'Caching client for stopping to many external requests'
|
8
|
+
option :expiration, 10_800, 'Cache will expire after x. Defualt: 3 hours'
|
9
|
+
|
10
|
+
def initialize(app, options_hash={}, &block)
|
11
|
+
# Call super to build options from the options_hash
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
expose_to_application :cache
|
16
|
+
def cache(key, expiration: nil, &block)
|
17
|
+
expiration ||= options.expiration
|
18
|
+
return block if options.client.nil?
|
19
|
+
|
20
|
+
options.client.fetch(key, expiration, &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
helpers do
|
24
|
+
def cache(key, expiration: nil, &block)
|
25
|
+
content = app.cache(key, expiration: expiration) do
|
26
|
+
capture_html(&block)
|
27
|
+
end
|
28
|
+
|
29
|
+
concat_content content
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'middleman-cache-do'
|
6
|
+
s.version = '0.1.0'
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ['Mike Rogers']
|
9
|
+
s.email = ['me@mikerogers.io']
|
10
|
+
s.homepage = 'https://github.com/MikeRogers0/Middleman-Cache-Do'
|
11
|
+
s.summary = %q{Cache fragments of code to memcache}
|
12
|
+
s.description = %q{Adds a cache method to helpers and templates which helps cache blocks of expensive code}
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
|
20
|
+
# The version of middleman-core your extension depends on
|
21
|
+
s.add_runtime_dependency 'middleman-core', '~> 4.2', '>= 4.2.1'
|
22
|
+
|
23
|
+
# Additional dependencies
|
24
|
+
s.add_runtime_dependency 'dalli', '~> 2.7', '>= 2.7.6'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-cache-do
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Rogers
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: middleman-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 4.2.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4.2'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 4.2.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: dalli
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.7'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 2.7.6
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '2.7'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.7.6
|
53
|
+
description: Adds a cache method to helpers and templates which helps cache blocks
|
54
|
+
of expensive code
|
55
|
+
email:
|
56
|
+
- me@mikerogers.io
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- ".gitignore"
|
62
|
+
- Gemfile
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- features/support/env.rb
|
66
|
+
- lib/middleman-cache-do.rb
|
67
|
+
- lib/middleman-cache-do/extension.rb
|
68
|
+
- middleman-cache-do.gemspec
|
69
|
+
homepage: https://github.com/MikeRogers0/Middleman-Cache-Do
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.6.11
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Cache fragments of code to memcache
|
93
|
+
test_files:
|
94
|
+
- features/support/env.rb
|