middleman-cta 0.0.1
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 +58 -0
- data/Rakefile +4 -0
- data/features/support/env.rb +4 -0
- data/lib/cta/extension.rb +46 -0
- data/lib/cta/instance.rb +11 -0
- data/lib/cta/redcarpet/cta_renderer.rb +17 -0
- data/lib/middleman-cta.rb +9 -0
- data/middleman-cta.gemspec +24 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 43aacba735c49bff1a1ea2c8bd11fed95dd1687b
|
4
|
+
data.tar.gz: 17fbd341da86f1cfcb872fda91d97120bc984e40
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8bcc4b6a4ce83b9c63922a5eaad40a001cae5782498f82ef37c5271c74566cbe6c571797572bc69b1e182df6f18a5e735ebd39e14f4c6d7999a296faec01fe68
|
7
|
+
data.tar.gz: 0f79ae47d426e781a73951c6d276c4308dc28c174a2398c7a9639b5b9ff37b42570e56b56c35092d1834a2a93566b39f775619f003991e1a272b5a5db370c525
|
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-cta.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,58 @@
|
|
1
|
+
# middleman-cta
|
2
|
+
|
3
|
+
Provides an easy way to define CTAs in your project using a data file and defined structure.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add the gem to your Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'middleman-cta'
|
11
|
+
```
|
12
|
+
|
13
|
+
Then run bundle.
|
14
|
+
|
15
|
+
```
|
16
|
+
$> bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
In your `data/cta.yml` (or JSON):
|
22
|
+
|
23
|
+
```yaml
|
24
|
+
-
|
25
|
+
id: great-cta
|
26
|
+
image: name-of-file-in-cta-image-dir.jpg
|
27
|
+
url: "http://absolute.url"
|
28
|
+
```
|
29
|
+
|
30
|
+
## Configuration
|
31
|
+
You can configure the name of the data file, as well as the directory in which the images are stored.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
activate :cta do |cta|
|
35
|
+
cta.cta_directory = 'cta_images'
|
36
|
+
cta.cta_data = 'call_to_actions'
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
## Rendering
|
41
|
+
|
42
|
+
We support two template engines by default, ERB and Markdown. For Markdown support, we currently only support Redcarpet as the markdown engine.
|
43
|
+
|
44
|
+
|
45
|
+
### ERB
|
46
|
+
You have access to a helper method to use in ERB:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
<h2>Signup Now</h2>
|
50
|
+
<%= cta('unique-cta-id') %>
|
51
|
+
```
|
52
|
+
|
53
|
+
### Markdown
|
54
|
+
|
55
|
+
```markdown
|
56
|
+
## Signup Now
|
57
|
+
[cta:unique-cta-id]
|
58
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module CTA
|
2
|
+
class Extension < ::Middleman::Extension
|
3
|
+
option :cta_directory, 'cta', 'Directory containing your CTA images'
|
4
|
+
option :cta_data, 'cta', 'Details of each CTA in YML or JSON format'
|
5
|
+
|
6
|
+
def initialize(app, options_hash={}, &block)
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def after_configuration
|
11
|
+
app.logger.info("== CTA: #{ options.cta_data } is not a valid data key") unless app.data.key?(options.cta_data)
|
12
|
+
|
13
|
+
if app.config[:markdown_engine] == :redcarpet
|
14
|
+
require 'middleman-core/renderers/redcarpet'
|
15
|
+
Middleman::Renderers::MiddlemanRedcarpetHTML.send(:include, CTA::Redcarpet::CTARenderer)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def cta_datasource
|
20
|
+
app.data[options.cta_data]
|
21
|
+
end
|
22
|
+
|
23
|
+
def find_cta(id)
|
24
|
+
attributes = cta_datasource.find { |cta| cta[:id] == id }
|
25
|
+
raise "Unable to locate CTA[#{ id }]" if attributes.blank?
|
26
|
+
|
27
|
+
Instance.new(attributes)
|
28
|
+
end
|
29
|
+
|
30
|
+
helpers do
|
31
|
+
def cta_controller
|
32
|
+
app.extensions[:cta]
|
33
|
+
end
|
34
|
+
|
35
|
+
def cta(id, options={})
|
36
|
+
result = cta_controller.find_cta(id)
|
37
|
+
|
38
|
+
options[:class] ||= 'cta-image'
|
39
|
+
|
40
|
+
link_to result.url, class: 'cta-link' do
|
41
|
+
image_tag(File.join(cta_controller.options.cta_directory, result.image), options)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/cta/instance.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module CTA
|
2
|
+
module Redcarpet
|
3
|
+
module CTARenderer
|
4
|
+
TAG_REGEX = %r{\[cta:([^\]]+)\]}.freeze
|
5
|
+
|
6
|
+
def preprocess(full_document)
|
7
|
+
full_document.gsub! TAG_REGEX do |text|
|
8
|
+
match_data = text.match(TAG_REGEX)
|
9
|
+
|
10
|
+
scope.cta(match_data[1])
|
11
|
+
end
|
12
|
+
|
13
|
+
full_document
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "middleman-cta"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Matt Millsaps-Brewer"]
|
9
|
+
s.email = ["matt@madebylotus.com"]
|
10
|
+
s.homepage = "http://www.madebylotus.com"
|
11
|
+
s.summary = %q{Provides a consistent Call-To-Action helper}
|
12
|
+
s.description = %q{Easily insert CTA campaigns into your post, including markdown}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
# The version of middleman-core your extension depends on
|
20
|
+
s.add_runtime_dependency("middleman-core", [">= 4.0.0"])
|
21
|
+
|
22
|
+
# Additional dependencies
|
23
|
+
# s.add_runtime_dependency("gem-name", "gem-version")
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-cta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Millsaps-Brewer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-10 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.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
description: Easily insert CTA campaigns into your post, including markdown
|
28
|
+
email:
|
29
|
+
- matt@madebylotus.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- Gemfile
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- features/support/env.rb
|
39
|
+
- lib/cta/extension.rb
|
40
|
+
- lib/cta/instance.rb
|
41
|
+
- lib/cta/redcarpet/cta_renderer.rb
|
42
|
+
- lib/middleman-cta.rb
|
43
|
+
- middleman-cta.gemspec
|
44
|
+
homepage: http://www.madebylotus.com
|
45
|
+
licenses: []
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.5.2
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Provides a consistent Call-To-Action helper
|
67
|
+
test_files:
|
68
|
+
- features/support/env.rb
|