Class: Middleman::VCard::VCardExtension
- Inherits:
-
Extension
- Object
- Extension
- Middleman::VCard::VCardExtension
- Defined in:
- lib/middleman-vcard/extension.rb
Overview
A Middleman extension to generate VCards and provide useful helpers to work with.
Instance Method Summary collapse
-
#after_configuration ⇒ Object
After Middleman has been configured (i.e. build, console, server, etc..) generate the VCard.
-
#initialize(app, options = {}, &block) ⇒ VCardExtension
constructor
Create the VCardExtension.
Constructor Details
#initialize(app, options = {}, &block) ⇒ VCardExtension
Create the VCardExtension.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/middleman-vcard/extension.rb', line 23 def initialize(app, ={}, &block) super source_dir_path = Pathname.new(app.root).join(app.config.source) if [:dst_path] unless [:dst_path].start_with?(source_dir_path.to_s) error("Invalid `dst_path`. It's not inside the source folder.") end @vcard_dir_path = Pathname.new(File.dirname([:dst_path])) @vcard_file_name = File.basename([:dst_path]) else @vcard_dir_path = source_dir_path @vcard_file_name = "#{[:name]}.vcf" end # Define some config used later # # NOTE: We want to be consistent with Middleman conventions, so # `vcard_dir_path` is a `String` because all Middleman paths are # `String`s. app.config.define_setting :vcard_name, [:name] app.config.define_setting :vcard_file_name, @vcard_file_name app.config.define_setting :vcard_dir_path, @vcard_dir_path.to_s end |
Instance Method Details
#after_configuration ⇒ Object
After Middleman has been configured (i.e. build, console, server, etc..) generate the VCard.
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/middleman-vcard/extension.rb', line 53 def after_configuration vcard_generator = Middleman::VCard::Generator.new( [:name], emails: [:emails], phones: [:phones], addresses: [:addresses], photo: [:photo], logger: logger) vcard_generator.generate(@vcard_dir_path.join(@vcard_file_name).to_s) end |