m2fm-automatic-embed 0.0.2 → 0.0.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: 6cbb12b3b9f135f055eea4e0e71885aee15a0eee
4
- data.tar.gz: 57a5fccf339221992a1a7b19a0c93f3c69d9f495
3
+ metadata.gz: 219a91072b33c7b16a9e23942ec4a1ed98df9ab9
4
+ data.tar.gz: 6764263f0ede2b801b5a23b631ea20ee84c06a92
5
5
  SHA512:
6
- metadata.gz: 09cf9b98a8ab8c614ef38500573aafde4ad085fa91e139840cb02f7740f37e559738953bbe8723bb2621ef602d6c8bff8718ec7e363eb734a8a4132ddc4a1e63
7
- data.tar.gz: 685f7de7543f775743520123c5b33d1788c4b501c90b053af83cbb749ddffbfce1673fbffc44a2e676cb7e642cc009447da7345c9b1c1ca5e9d7834321e1ca2d
6
+ metadata.gz: 17ebe2443b31efef7ad16b0d38199b3b0ac558bf6138253260ed31991c2d4a0e22e38b2fdc3ac7e5e91175fa5da48af2b4c9688bcdd691ffa606240bb437140f
7
+ data.tar.gz: 77b546fea5e1ae9920c0c9fde1cd416f0caa4b3e3e0cf3b55408b602cc36313b715aa077e95023c320f93d3746cd58d21aaaa718c94a55db3791b8a8cfa05b0b
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.2.0
5
+ script: bundle exec rake
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+
3
+ task default: 'spec'
2
4
 
3
5
  begin
4
6
  require 'rspec/core/rake_task'
@@ -0,0 +1,64 @@
1
+
2
+ Delivered-To: stream@kunalashah.com
3
+ Received: by 10.216.42.73 with SMTP id i51csp1200401web;
4
+ Mon, 12 Jan 2015 19:39:33 -0800 (PST)
5
+ X-Received: by 10.236.41.202 with SMTP id h50mr21052293yhb.140.1421120372875;
6
+ Mon, 12 Jan 2015 19:39:32 -0800 (PST)
7
+ Return-Path: <me@kunalashah.com>
8
+ Received: from mail-yh0-x232.google.com (mail-yh0-x232.google.com. [2607:f8b0:4002:c01::232])
9
+ by mx.google.com with ESMTPS id 79si10236396ykt.36.2015.01.12.19.39.32
10
+ for <stream@kunalashah.com>
11
+ (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
12
+ Mon, 12 Jan 2015 19:39:32 -0800 (PST)
13
+ Received-SPF: none (google.com: me@kunalashah.com does not designate permitted sender hosts) client-ip=2607:f8b0:4002:c01::232;
14
+ Authentication-Results: mx.google.com;
15
+ spf=none (google.com: me@kunalashah.com does not designate permitted sender hosts) smtp.mail=me@kunalashah.com;
16
+ dkim=pass header.i=@kunalashah.com
17
+ Received: by mail-yh0-f50.google.com with SMTP id b6so356245yha.9
18
+ for <stream@kunalashah.com>; Mon, 12 Jan 2015 19:39:31 -0800 (PST)
19
+ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
20
+ d=kunalashah.com; s=google;
21
+ h=mime-version:date:message-id:subject:from:to:content-type;
22
+ bh=xvqejrLOBkvtZ/LV00B3w07XE6B1WPIeFwV0y5FOk48=;
23
+ b=Y310Cno+tXMfIFuHEFvEGd/U+K8EuUQQ+TUFCvla9JZ2m4Agh9Oog5PAETy4RAUXCw
24
+ OSgzTTYgEpVneeWNu/uXwTucwrTHzSEW2MeLLr/beQsEWLKeW1pg7IcO8o16WrI76nd1
25
+ xGqh4v/7YVHNK/Lyrrm0/7ANFVrdWu5b37t58=
26
+ X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
27
+ d=1e100.net; s=20130820;
28
+ h=x-gm-message-state:mime-version:date:message-id:subject:from:to
29
+ :content-type;
30
+ bh=xvqejrLOBkvtZ/LV00B3w07XE6B1WPIeFwV0y5FOk48=;
31
+ b=LMSU/hDJIcMdBAId5WcNCGsT6zMUwCSBZXkHry3Ez19XT3tsHF/1V9nthO39yLzJTc
32
+ lKIIU6TVDOnRtj/6SSsSLLxOFjXu+hiNZsJNR32AzjzBwTZBV4YKFdlemn4tTDQG0Wpb
33
+ DDjUvzvNHOTT9h8wRQVZIrng1liJXO8Z20msNwdgsS1dB5EK4jCleU21l6KI10eenTHu
34
+ gbqwOqV2teAZ3gu3J6mR6BkyiRDc5qZuhSasdT+HRzgCRszbv49eaXPBz/Kax4aadhFU
35
+ zOLWEswjgpC+Rxj5i4WGvf7hIRyAf/9oLVZQW1DSavnOG6frEESyiAU7VJ457XTZw0uK
36
+ 4H4Q==
37
+ X-Gm-Message-State: ALoCoQnXibjhC9yUZfwNU1j0v/wXuMTj5PBzoZXIMnGz+pWYPziFyExdgJVpO1fjHvGE/gcr3R9/
38
+ MIME-Version: 1.0
39
+ X-Received: by 10.170.49.6 with SMTP id 6mr28189061ykr.118.1421120371787; Mon,
40
+ 12 Jan 2015 19:39:31 -0800 (PST)
41
+ Received: by 10.170.205.16 with HTTP; Mon, 12 Jan 2015 19:39:31 -0800 (PST)
42
+ X-Originating-IP: [66.108.230.254]
43
+ Date: Mon, 12 Jan 2015 22:39:31 -0500
44
+ Message-ID: <CAN-VoWm1nRXKLZk-g368U05SE7_Z9aHV9abL+PEbf-kn=0HDFw@mail.gmail.com>
45
+ Subject: Lover, Lover, Lover
46
+ From: Kunal Shah <me@kunalashah.com>
47
+ To: "stream@kunalashah.com" <stream@kunalashah.com>
48
+ Content-Type: multipart/alternative; boundary=001a11394e8ef1a379050c805e70
49
+
50
+ --001a11394e8ef1a379050c805e70
51
+ Content-Type: text/plain; charset=UTF-8
52
+
53
+ https://www.youtube.com/watch?v=oVURkMTDr3E
54
+
55
+ Leonard Cohen
56
+
57
+ --001a11394e8ef1a379050c805e70
58
+ Content-Type: text/html; charset=UTF-8
59
+
60
+ <div dir="ltr"><a href="https://www.youtube.com/watch?v=oVURkMTDr3E">https://www.youtube.com/watch?v=oVURkMTDr3E</a><br>
61
+ <div><br></div><div>Leonard Cohen</div></div>
62
+
63
+ --001a11394e8ef1a379050c805e70--
64
+
@@ -4,6 +4,8 @@ require 'byebug'
4
4
 
5
5
  module Mail2FrontMatter
6
6
  class AutomaticEmbed < PreProcessor
7
+ require 'nokogiri'
8
+
7
9
  extend AutoHtml
8
10
 
9
11
  @all_filters = [:youtube, :soundcloud, :link, :ted, :twitter, :vimeo, :google_map, :gist, :flickr]
@@ -23,6 +25,7 @@ module Mail2FrontMatter
23
25
  end
24
26
 
25
27
  def self.run(metadata, body)
28
+ body = unwrap_links(body)
26
29
 
27
30
  body = auto_html(body, { filters: @filters, options: @options[:filters] }) {
28
31
  # use options passed to us...
@@ -37,5 +40,20 @@ module Mail2FrontMatter
37
40
 
38
41
  return metadata, body
39
42
  end
43
+
44
+ def self.unwrap_links(body)
45
+ body = Nokogiri::HTML::DocumentFragment.parse(body)
46
+
47
+ body.elements.css("a").each do |element|
48
+ href = element.attributes["href"].value
49
+
50
+ if href == element.inner_html
51
+ element.replace(href)
52
+ end
53
+ end
54
+
55
+ body
56
+ end
57
+
40
58
  end
41
59
  end
@@ -4,7 +4,7 @@ $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.2'
7
+ spec.version = '0.0.3'
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}
@@ -1,32 +1,12 @@
1
1
  require 'spec_helper'
2
2
  require 'byebug'
3
3
 
4
- describe Mail2FrontMatter::Parser, "parsing" do
5
-
6
- let(:soundcloud) {
7
- Mail::Message.new(File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', 'soundcloud-link.eml')))
8
- }
9
- let(:youtube) {
10
- Mail::Message.new(File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', 'youtube-link.eml')))
11
- }
12
- let(:control) {
13
- Mail::Message.new(File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', 'no-links.eml')))
14
- }
4
+ describe Mail2FrontMatter::AutomaticEmbed, "configuration" do
15
5
  let(:config) {
16
6
  test_config = File.join(File.dirname(__FILE__), '..', 'fixtures', 'config.yml')
17
7
  config = YAML.load_file(test_config).deep_symbolize_keys!
18
8
  }
19
9
 
20
- it "should identify and transform youtube link" do
21
- Mail2FrontMatter::AutomaticEmbed.register
22
-
23
- parser = Mail2FrontMatter::Parser.new(youtube)
24
- metadata, body = Mail2FrontMatter::PreProcessor.process(parser.metadata, parser.body)
25
-
26
- body.should match(/embed/)
27
-
28
- end
29
-
30
10
  it "should store filters internally as symbols" do
31
11
  Mail2FrontMatter::AutomaticEmbed.register(config[:keys_demo])
32
12
  keys = Mail2FrontMatter::AutomaticEmbed.instance_variable_get :@filters
@@ -64,5 +44,41 @@ describe Mail2FrontMatter::Parser, "parsing" do
64
44
  # run it
65
45
  Mail2FrontMatter::AutomaticEmbed.run(metadata, body)
66
46
  end
47
+ end
48
+
49
+ describe Mail2FrontMatter::AutomaticEmbed, "behaviour" do
50
+
51
+ let(:soundcloud) {
52
+ Mail::Message.new(File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', 'soundcloud-link.eml')))
53
+ }
54
+ let(:youtube) {
55
+ Mail::Message.new(File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', 'youtube-link.eml')))
56
+ }
57
+ let(:wrapped) {
58
+ Mail::Message.new(File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', 'wrapped-links.eml')))
59
+ }
60
+ let(:control) {
61
+ Mail::Message.new(File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', 'no-links.eml')))
62
+ }
63
+
64
+ it "should identify and transform youtube link" do
65
+ Mail2FrontMatter::AutomaticEmbed.register
66
+
67
+ parser = Mail2FrontMatter::Parser.new(youtube)
68
+ metadata, body = Mail2FrontMatter::PreProcessor.process(parser.metadata, parser.body)
69
+
70
+ body.should match(/embed/)
71
+
72
+ end
73
+
74
+ it "should unwrap links without specific names before using filters" do
75
+ Mail2FrontMatter::AutomaticEmbed.register
76
+ parser = Mail2FrontMatter::Parser.new(wrapped)
77
+
78
+ metadata, body = Mail2FrontMatter::AutomaticEmbed.run(parser.metadata, parser.body)
79
+
80
+ body.should_not match(/href/)
81
+
82
+ end
67
83
 
68
84
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: m2fm-automatic-embed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kunal Shah
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-15 00:00:00.000000000 Z
11
+ date: 2015-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail2frontmatter
@@ -102,6 +102,7 @@ extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
104
  - ".gitignore"
105
+ - ".travis.yml"
105
106
  - Gemfile
106
107
  - LICENSE.txt
107
108
  - README.md
@@ -109,6 +110,7 @@ files:
109
110
  - fixtures/config.yml
110
111
  - fixtures/no-links.eml
111
112
  - fixtures/soundcloud-link.eml
113
+ - fixtures/wrapped-links.eml
112
114
  - fixtures/youtube-link.eml
113
115
  - lib/mail2frontmatter/automatic-embeds.rb
114
116
  - m2fm-automatic-embeds.gemspec