middleman-vcard 0.9.2 → 0.9.3
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/Gemfile.lock +1 -1
- data/README.md +58 -2
- data/lib/middleman-vcard/extension.rb +75 -9
- data/lib/middleman-vcard/generator.rb +1 -1
- data/lib/middleman-vcard/version.rb +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: 2700232cd047ae2fe262f314fca0a0aaaeb23f97
|
4
|
+
data.tar.gz: 723f3e18df4b22c709180e6b7fb58cebe6e3fd9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ef6a29081308a68e27a5b8a8ae7864106c4d5d7109b79510bf01fe4905851217aa29ce112671eb0e5fe4001d76353258f9a78ca8b4f72d4f4a60311f0bb4de9
|
7
|
+
data.tar.gz: 1ab1de88797271265f37843514e628b916e0928641e406541dce3b560f365a70ceb77e7b43d194c2380b8621e1fd53e2275b6df58565476600f82994702a8566
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,25 +1,81 @@
|
|
1
1
|
# Middleman VCard
|
2
2
|
|
3
|
+

|
4
|
+
|
5
|
+
## Project informations
|
6
|
+
|
3
7
|
* [Homepage](https://rubygems.org/gems/middleman-vcard)
|
4
8
|
* [Documentation](http://rubydoc.info/gems/middleman-vcard/frames)
|
5
9
|
* [Email](mailto:molari.alessandro@gmail.com)
|
6
10
|
|
7
11
|
## Description
|
8
12
|
|
9
|
-
Middleman extension to generate
|
13
|
+
A Middleman extension to generate VCards and provide useful helpers to work
|
14
|
+
with.
|
10
15
|
|
11
16
|
## Usage
|
12
17
|
|
13
18
|
Include the `middleman-vcard` gem in your Gemfile:
|
19
|
+
|
14
20
|
```Ruby
|
15
21
|
gem 'middleman-vcard'
|
16
22
|
```
|
17
23
|
|
18
24
|
Add the following code to your `config.rb` file:
|
25
|
+
|
19
26
|
```Ruby
|
20
|
-
|
27
|
+
require "middleman-vcard"
|
28
|
+
activate :vcard,
|
29
|
+
name: data.site.vcard.name,
|
30
|
+
emails: [{
|
31
|
+
email: data.site.vcard.email,
|
32
|
+
preferred: true,
|
33
|
+
location: "work"
|
34
|
+
}],
|
35
|
+
phones: [{
|
36
|
+
number: data.site.vcard.phone,
|
37
|
+
preferred: true,
|
38
|
+
location: "work",
|
39
|
+
capability: ["voice", "video", "msg"]
|
40
|
+
}],
|
41
|
+
addresses: [{
|
42
|
+
preferred: true,
|
43
|
+
location: "work",
|
44
|
+
postalcode: data.site.vcard.postalcode.to_s,
|
45
|
+
locality: data.site.vcard.city,
|
46
|
+
region: data.site.vcard.province,
|
47
|
+
country: data.site.vcard.country
|
48
|
+
}],
|
49
|
+
photo: {
|
50
|
+
path: File.join(root, config.source, config.images_dir, "logo-vcard.jpg"),
|
51
|
+
type: "jpeg"
|
52
|
+
}
|
21
53
|
```
|
22
54
|
|
55
|
+
Of course you can organize your data as you want and choose what to include
|
56
|
+
in your data files or directly in your config file.
|
57
|
+
|
58
|
+
Also, *you can pass multiple phones, addresses, emails*.
|
59
|
+
|
60
|
+
Now the VCard file will be automatically generated :D
|
61
|
+
|
62
|
+
### Helpers:
|
63
|
+
|
64
|
+
Usually you need to include your VCard in HTML, so there are some helpers
|
65
|
+
already defined:
|
66
|
+
|
67
|
+
#### `vcard_link`
|
68
|
+
|
69
|
+
*Generate a link tag that points to the VCard*.
|
70
|
+
|
71
|
+
Details [here](./lib/middleman-vcard/extension.rb#L91).
|
72
|
+
|
73
|
+
#### `vcard_path`
|
74
|
+
|
75
|
+
*Build the path that points to the VCard file*.
|
76
|
+
|
77
|
+
Details [here](./lib/middleman-vcard/extension.rb#L72).
|
78
|
+
|
23
79
|
## Contributors
|
24
80
|
|
25
81
|
Many thanks to Luca Molari (LMolr)!!
|
@@ -1,31 +1,97 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
|
1
4
|
module Middleman
|
2
5
|
module VCard
|
3
6
|
##
|
4
|
-
# A Middleman extension to generate VCards
|
7
|
+
# A Middleman extension to generate VCards and provide useful helpers to
|
8
|
+
# work with.
|
5
9
|
#
|
6
10
|
class VCardExtension < Middleman::Extension
|
7
11
|
|
8
|
-
option :name, nil, "The VCard name"
|
12
|
+
option :name, nil, "The VCard name", required: true
|
9
13
|
option :emails, [], "The VCard emails"
|
10
14
|
option :phones, [], "The VCard telephones"
|
11
15
|
option :addresses, [], "The VCard addresses"
|
12
16
|
option :photo, nil, "The VCard photo"
|
13
17
|
|
14
|
-
option :
|
18
|
+
option :dst_path, nil, "The destination path for the generated VCard"
|
15
19
|
|
16
20
|
def initialize(app, options_hash={}, &block)
|
17
21
|
super
|
18
22
|
|
19
|
-
@
|
20
|
-
|
23
|
+
@name = options_hash[:name]
|
24
|
+
@emails = options_hash[:emails]
|
25
|
+
@phones = options_hash[:phones]
|
26
|
+
@addresses = options_hash[:addresses]
|
27
|
+
@photo = options_hash[:photo]
|
28
|
+
|
29
|
+
@dst_path = options_hash[:dst_path]
|
30
|
+
|
31
|
+
source_dir_path = Pathname.new(app.root).join(app.config.source)
|
32
|
+
|
33
|
+
if @dst_path
|
34
|
+
unless @dst_path.start_with?(source_dir_path.to_s)
|
35
|
+
error("Invalid `dst_path`. It's not inside the source folder.")
|
36
|
+
end
|
37
|
+
@vcard_dir_path = Pathname.new(File.dirname(@dst_path))
|
38
|
+
@vcard_file_name = File.basename(@dst_path)
|
39
|
+
else
|
40
|
+
@vcard_dir_path = source_dir_path
|
41
|
+
@vcard_file_name = "#{@name}.vcf"
|
42
|
+
end
|
43
|
+
|
21
44
|
@vcard_generator = Middleman::VCard::Generator.new(
|
22
|
-
|
23
|
-
|
24
|
-
|
45
|
+
@name, @emails, @phones, @addresses, @photo, logger)
|
46
|
+
|
47
|
+
# Define some config used later
|
48
|
+
#
|
49
|
+
# NOTE: We want to be consistent with Middleman conventions, so
|
50
|
+
# `vcard_dir_path` is a `String` because all Middleman paths are
|
51
|
+
# `String`s.
|
52
|
+
app.config.define_setting :vcard_name, @name
|
53
|
+
app.config.define_setting :vcard_file_name, @vcard_file_name
|
54
|
+
app.config.define_setting :vcard_dir_path, @vcard_dir_path.to_s
|
25
55
|
end
|
26
56
|
|
27
57
|
def after_configuration
|
28
|
-
@vcard_generator.generate(@
|
58
|
+
@vcard_generator.generate(@vcard_dir_path.join(@vcard_file_name))
|
59
|
+
end
|
60
|
+
|
61
|
+
helpers do
|
62
|
+
|
63
|
+
##
|
64
|
+
# Build the path that points to the VCard file.
|
65
|
+
#
|
66
|
+
# @note The generated path is meant to be used in `href`s or similar
|
67
|
+
# (is relative to the source or build directory). It's not meant
|
68
|
+
# to be directly used for filesystem access.
|
69
|
+
#
|
70
|
+
# @return The path for the VCard file.
|
71
|
+
#
|
72
|
+
def vcard_path
|
73
|
+
# Find the VCard prefix path, which is relative to the source
|
74
|
+
# directory because that's the root path that will be served and built
|
75
|
+
# by Middleman.
|
76
|
+
prefix = Pathname.new(config.vcard_dir_path).relative_path_from(
|
77
|
+
Pathname.new(root).join(config.source))
|
78
|
+
|
79
|
+
"#{prefix}/#{config.vcard_file_name}"
|
80
|
+
end
|
81
|
+
|
82
|
+
##
|
83
|
+
# Generate a link tag that points to the VCard.
|
84
|
+
#
|
85
|
+
# @param title [String|nil] The link title.
|
86
|
+
# If `nil`, the VCard name will be used.
|
87
|
+
# @param kwargs [Hash] The keyword arguments to be passed into `link_to`
|
88
|
+
#
|
89
|
+
# @return [String] The generated HTML link tag.
|
90
|
+
#
|
91
|
+
def vcard_link(title=nil, **kwargs)
|
92
|
+
link_to(title || config.vcard_name, vcard_path, kwargs)
|
93
|
+
end
|
94
|
+
|
29
95
|
end
|
30
96
|
|
31
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-vcard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Molari
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman-core
|