m2fm-automatic-embed 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aaf87e4c1a4c933967340bdc50e26ae32870c421
4
- data.tar.gz: 7c691c2bc155c4998b79ff901867d32ad4d5a2e2
3
+ metadata.gz: 6cbb12b3b9f135f055eea4e0e71885aee15a0eee
4
+ data.tar.gz: 57a5fccf339221992a1a7b19a0c93f3c69d9f495
5
5
  SHA512:
6
- metadata.gz: e432c799da46aea2c9e753647d0420ff19a9913abd40149af34f9aac7c0dc775466f3467b7cb8822626305a6e7880578d481af7f386e2bbdada2c5c8f81a6961
7
- data.tar.gz: 47744656485bed1600d4cf5f3e1953bade0dc23accd7a150b82d3f23f279d83610901a722bd4d97c62ea4f37ce2ec3b7f98bb9f041c8c5eb52ab9fcc0deff9a0
6
+ metadata.gz: 09cf9b98a8ab8c614ef38500573aafde4ad085fa91e139840cb02f7740f37e559738953bbe8723bb2621ef602d6c8bff8718ec7e363eb734a8a4132ddc4a1e63
7
+ data.tar.gz: 685f7de7543f775743520123c5b33d1788c4b501c90b053af83cbb749ddffbfce1673fbffc44a2e676cb7e642cc009447da7345c9b1c1ca5e9d7834321e1ca2d
data/README.md CHANGED
@@ -19,19 +19,24 @@ And then execute:
19
19
  In your Mail2FrontMatter YAML configuration enable the plugin by adding it to your preprocessors:
20
20
 
21
21
  ```yaml
22
- protocol: imap
23
- receiver: yourblogemail@yourdomain.com
24
- senders: yourpersonal@yourdomain.com
25
-
26
22
  preprocessors:
27
23
  - key: 'automatic-embed'
24
+ ```
25
+
26
+ You can provide a whitelist or blacklist for filters as well as providing filters options. Filter options are documented at the auto_html project.
28
27
 
29
- mailman:
30
- server: imap.gmail.com
31
- port: 993
32
- ssl: true
33
- username: yourblogemail@yourdomain.com
34
- password: yourpassword
28
+ ```yaml
29
+ preprocessors:
30
+ - key: 'automatic-embed'
31
+ options:
32
+ white_list:
33
+ - youtube
34
+ - soundcloud
35
+ - vimeo
36
+ filters:
37
+ youtube:
38
+ autoplay: true
39
+ other_attribute: other_value
35
40
  ```
36
41
 
37
42
  ## Usage
@@ -0,0 +1,25 @@
1
+ keys_demo:
2
+ white_list:
3
+ - youtube
4
+ - soundcloud
5
+ - vimeo
6
+
7
+ white_list_demo:
8
+ white_list:
9
+ - youtube
10
+ - soundcloud
11
+ - vimeo
12
+
13
+ black_list_demo:
14
+ black_list:
15
+ - vimeo
16
+
17
+ options_demo:
18
+ white_list:
19
+ - youtube
20
+ - soundcloud
21
+ - vimeo
22
+ filters:
23
+ youtube:
24
+ autoplay: true
25
+
@@ -8,18 +8,23 @@ module Mail2FrontMatter
8
8
 
9
9
  @all_filters = [:youtube, :soundcloud, :link, :ted, :twitter, :vimeo, :google_map, :gist, :flickr]
10
10
 
11
- def self.run(metadata, body)
12
- # I *could* introspect on auto_html here but I haven't vetted them all yet
11
+ def self.register(options = {})
12
+ super
13
13
 
14
+ # I *could* introspect on auto_html here but I haven't vetted them all yet
14
15
  if @options[:white_list]
15
- filters = @options[:white_list]
16
+ @filters = @options[:white_list].map(&:to_sym)
16
17
  elsif @options[:black_list]
17
- filters = @all_filters - @options[:black_list]
18
+ @filters = @all_filters - @options[:black_list].map(&:to_sym)
18
19
  else
19
- filters = @all_filters
20
+ @filters = @all_filters
20
21
  end
21
22
 
22
- body = auto_html(body, { filters: filters, options: @options[:filters] }) {
23
+ end
24
+
25
+ def self.run(metadata, body)
26
+
27
+ body = auto_html(body, { filters: @filters, options: @options[:filters] }) {
23
28
  # use options passed to us...
24
29
  @options[:filters].each do |filter|
25
30
  options_for_filter = @options[:options] ? (@options[:options][filter.to_sym] || {}) : {}
@@ -4,12 +4,12 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'm2fm-automatic-embed'
7
- spec.version = '0.0.1'
7
+ spec.version = '0.0.2'
8
8
  spec.authors = ['Kunal Shah']
9
9
  spec.email = ['me@kunalashah.com']
10
10
  spec.summary = %q{mail2frontmatter plugin to transform links into embed code automatically}
11
11
  spec.description = spec.summary
12
- spec.homepage = 'https://github.com/whistlerbrk/m2fm-automatic-embed'
12
+ spec.homepage = 'https://github.com/whistlerbrk/m2fm-automatic-embeds'
13
13
  spec.license = 'MIT'
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0")
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ['lib']
19
19
 
20
- spec.add_dependency 'mail2frontmatter', '>= 0.0.4'
20
+ spec.add_dependency 'mail2frontmatter', '>= 0.0.5'
21
21
  spec.add_dependency 'auto_html-whistlerbrk', '2.0.0.pre'
22
22
 
23
23
  spec.add_development_dependency 'byebug'
@@ -12,6 +12,10 @@ describe Mail2FrontMatter::Parser, "parsing" do
12
12
  let(:control) {
13
13
  Mail::Message.new(File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', 'no-links.eml')))
14
14
  }
15
+ let(:config) {
16
+ test_config = File.join(File.dirname(__FILE__), '..', 'fixtures', 'config.yml')
17
+ config = YAML.load_file(test_config).deep_symbolize_keys!
18
+ }
15
19
 
16
20
  it "should identify and transform youtube link" do
17
21
  Mail2FrontMatter::AutomaticEmbed.register
@@ -23,4 +27,42 @@ describe Mail2FrontMatter::Parser, "parsing" do
23
27
 
24
28
  end
25
29
 
30
+ it "should store filters internally as symbols" do
31
+ Mail2FrontMatter::AutomaticEmbed.register(config[:keys_demo])
32
+ keys = Mail2FrontMatter::AutomaticEmbed.instance_variable_get :@filters
33
+
34
+ keys.all?{|k|k.is_a?(Symbol)}.should eq(true)
35
+ end
36
+
37
+ it "should allow a white list" do
38
+ Mail2FrontMatter::AutomaticEmbed.register(config[:white_list_demo])
39
+ keys = Mail2FrontMatter::AutomaticEmbed.instance_variable_get :@filters
40
+
41
+ white_list = [:youtube, :soundcloud, :vimeo]
42
+ keys.sort.should eq(white_list.sort)
43
+ end
44
+
45
+ it "should allow a black list" do
46
+ Mail2FrontMatter::AutomaticEmbed.register(config[:black_list_demo])
47
+ keys = Mail2FrontMatter::AutomaticEmbed.instance_variable_get :@filters
48
+ all_keys = Mail2FrontMatter::AutomaticEmbed.instance_variable_get :@all_filters
49
+
50
+ black_list = [:vimeo]
51
+ keys.sort.should eq((all_keys - black_list).sort)
52
+ end
53
+
54
+ it "should allow the forwarding of options to an auto_html filter" do
55
+ Mail2FrontMatter::AutomaticEmbed.register(config[:options_demo])
56
+
57
+ metadata = {
58
+ subject: "Interstellar"
59
+ }
60
+ body = "I think B Colony made the wormhole. https://www.youtube.com/watch?v=jo5m5GXF9Ec"
61
+
62
+ AutoHtml::Builder.any_instance.should_receive(:youtube).with({autoplay: true})
63
+
64
+ # run it
65
+ Mail2FrontMatter::AutomaticEmbed.run(metadata, body)
66
+ end
67
+
26
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: m2fm-automatic-embed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kunal Shah
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.4
19
+ version: 0.0.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.4
26
+ version: 0.0.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: auto_html-whistlerbrk
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -106,6 +106,7 @@ files:
106
106
  - LICENSE.txt
107
107
  - README.md
108
108
  - Rakefile
109
+ - fixtures/config.yml
109
110
  - fixtures/no-links.eml
110
111
  - fixtures/soundcloud-link.eml
111
112
  - fixtures/youtube-link.eml
@@ -113,7 +114,7 @@ files:
113
114
  - m2fm-automatic-embeds.gemspec
114
115
  - spec/automatic_embed_spec.rb
115
116
  - spec/spec_helper.rb
116
- homepage: https://github.com/whistlerbrk/m2fm-automatic-embed
117
+ homepage: https://github.com/whistlerbrk/m2fm-automatic-embeds
117
118
  licenses:
118
119
  - MIT
119
120
  metadata: {}