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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: accb51fb50ad5aba7e07a47c5d562fc25473208d
4
- data.tar.gz: 8de40cf605f39d8f0f5b83b6998415dcacfb9244
3
+ metadata.gz: 2700232cd047ae2fe262f314fca0a0aaaeb23f97
4
+ data.tar.gz: 723f3e18df4b22c709180e6b7fb58cebe6e3fd9f
5
5
  SHA512:
6
- metadata.gz: fe38cfd1a0ded059578e32e09c8dd1db7c6af0e6a4525042af8927fc3a8f1195a179116b2d9d888ce19aec31ab8750fc49581cc8d43354829fcbd820bb82a614
7
- data.tar.gz: d969dc8c89f724cf5a859b47460f73190945fee6d1946216781fdc359d827bc49fe4d47cfb51eda608c00fa89a6e0fb4e71056061aab7e85b7fb7915bf433f02
6
+ metadata.gz: 9ef6a29081308a68e27a5b8a8ae7864106c4d5d7109b79510bf01fe4905851217aa29ce112671eb0e5fe4001d76353258f9a78ca8b4f72d4f4a60311f0bb4de9
7
+ data.tar.gz: 1ab1de88797271265f37843514e628b916e0928641e406541dce3b560f365a70ceb77e7b43d194c2380b8621e1fd53e2275b6df58565476600f82994702a8566
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- middleman-vcard (0.9.2)
4
+ middleman-vcard (0.9.3)
5
5
  contracts
6
6
  middleman-core (>= 3.3.10)
7
7
  vpim
data/README.md CHANGED
@@ -1,25 +1,81 @@
1
1
  # Middleman VCard
2
2
 
3
+ ![Status](http://img.shields.io/badge/status-OK-green.svg)
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 a VCard during the `build` phase.
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
- activate :vcard
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" # TODO: It should be required.
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 :destination_path, nil, "Destination path for the generated VCard"
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
- @destination_path = options_hash[:destination_path] ||
20
- File.join(app.root, app.config.source, "#{options_hash[:name]}.vcf")
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
- options_hash[:name], options_hash[:emails],
23
- options_hash[:phones], options_hash[:addresses],
24
- options_hash[:photo], logger)
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(@destination_path)
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
@@ -118,7 +118,7 @@ module Middleman
118
118
 
119
119
  def error(msg)
120
120
  @logger.error(format_msg(msg))
121
- # TODO: Raise error.
121
+ fail("Middleman VCard generator failed")
122
122
  end
123
123
 
124
124
  def info(msg)
@@ -3,7 +3,7 @@ module Middleman
3
3
 
4
4
  VERSION_MAJOR = 0
5
5
  VERSION_MINOR = 9
6
- VERSION_PATCH = 2
6
+ VERSION_PATCH = 3
7
7
 
8
8
  VERSION = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}"
9
9
 
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.2
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-24 00:00:00.000000000 Z
11
+ date: 2015-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core