markdown_media 1.4.1 → 1.5.0

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
  SHA256:
3
- metadata.gz: ee7675d6eedf2b85caf8d19d019146537850c81849226a140a3657bd9a01153e
4
- data.tar.gz: 1698bf31d6f72b52c91b4d52282b5411eeab673d9adf55a068896f6944b33cad
3
+ metadata.gz: 28522f52f3bc0e47973dc525eb6010f9a9c2ac9014221d475c6dc1b563e2811f
4
+ data.tar.gz: 4eb451f801e81e089d01d87dffac196d58773e13c40a6d01e9c245ec9327e80f
5
5
  SHA512:
6
- metadata.gz: e61f516f97f94789df00f463099f29829bf171aaca41663706dbfb70693f3ed11936e39dbfa3a81c3dc0227e4a6a39feb6802617706bc7f8ae3101beff51e74e
7
- data.tar.gz: c8811cf2218c7be4b0715bde37d6f4fbc3a3386120b701e51cf2967d3ad0b71ec96a92e0a39d6f034843acd7cea860a7d7a54841ddd2dbc8bdd9fdd196d35f7c
6
+ metadata.gz: 171b43f7ec618ca14ed15fe76a586f5325cd15f396e55617831d832b00a1ddede281919b92cc23686f4fa8408d5fc0b1b005d177522038217f50a3100ded285f
7
+ data.tar.gz: 4c4a1b4a256e16588d7eac0ebe91a4b702e3aefc1f1d93183d36b5afd3af152cadf05ae8d8fd2c9cc88ce098b291fbe1018ad293715fcbdd9242c09aff1bd5ee
@@ -7,7 +7,7 @@ module MarkdownMedia
7
7
  EMBED_REGEX = /\[\[\s*(http[^\]\s]+(?:\s.+)?)\s*\]\]/
8
8
 
9
9
  class << self
10
- def parse(text)
10
+ def parse(text, include_media: true)
11
11
  output = text.gsub(EMBED_REGEX) do
12
12
  embed_tag = $1
13
13
 
@@ -25,7 +25,13 @@ module MarkdownMedia
25
25
 
26
26
  caption = embed_tag_pieces.join(" ")
27
27
 
28
- expanded_embed(url, caption: caption, link: link, id: id, type: type, klass: klass)
28
+ expanded_embed(url,
29
+ caption: caption,
30
+ link: link,
31
+ id: id,
32
+ type: type,
33
+ klass: klass,
34
+ include_media: include_media)
29
35
  end
30
36
  end
31
37
 
@@ -75,9 +81,28 @@ module MarkdownMedia
75
81
  end
76
82
  end
77
83
 
78
- def expanded_embed(url, caption: nil, link: nil, id: nil, type: nil, klass: nil)
84
+ def expanded_embed(url, caption: nil, link: nil, id: nil, type: nil, klass: nil, include_media: true)
79
85
  url = URI.parse(url)
80
86
 
87
+ options = extract_options(url: url, include_media: include_media)
88
+ slug = options[:slug]
89
+ embed_id = options[:embed_id]
90
+ type ||= options[:type]
91
+
92
+ render_erb slug, {
93
+ embed_id: embed_id || url.to_s,
94
+ caption: caption,
95
+ link: link,
96
+ id: id,
97
+ type: type,
98
+ klass: klass
99
+ }
100
+ end
101
+
102
+ # TODO: there’s got to be a better way, refactor to classes
103
+ def extract_options url:, include_media: true
104
+ type = nil
105
+
81
106
  case url.host
82
107
  when /youtube.com/
83
108
  slug = "youtube"
@@ -114,20 +139,22 @@ module MarkdownMedia
114
139
  embed_id = url.path.split("/").last.split('-').last
115
140
 
116
141
  else
117
- slug = case url.path
118
-
119
- when /\.mp3|\.aac|\.wav|\.ogg|\.oga|\.m4a/
120
- "audio"
121
- when /\.mp4|\.avi|\.mov|\.ogv|\.webm|\.m4v|\.3gp|\.m3u8/
122
- "video"
123
- when /\.png|\.jpeg|\.jpg|\.gif|\.svg/
124
- "image"
125
- else
126
- "link"
127
- end
142
+ slug =
143
+ case url.path
144
+ when /\.mp3|\.aac|\.wav|\.ogg|\.oga|\.m4a/
145
+ "audio"
146
+ when /\.mp4|\.avi|\.mov|\.ogv|\.webm|\.m4v|\.3gp|\.m3u8/
147
+ "video"
148
+ when /\.png|\.jpeg|\.jpg|\.gif|\.svg/
149
+ "image"
150
+ else
151
+ "link"
152
+ end
128
153
  end
129
154
 
130
- render_erb slug, { embed_id: embed_id || url.to_s, caption: caption, link: link, id: id, type: type, klass: klass }
155
+ slug = 'link' if include_media == false
156
+
157
+ { slug: slug, embed_id: embed_id, type: type }
131
158
  end
132
159
 
133
160
  def render_erb(template_slug, locals)
@@ -1,3 +1,3 @@
1
1
  module MarkdownMedia
2
- VERSION = "1.4.1"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -1 +1,3 @@
1
- <a href="<%= embed_id.to_s %>" id="<%= id %>" class="<%= klass %>"><%= caption.to_s.empty? ? embed_id.to_s.sub(/^https*:\/\//, "").sub(/\/$/, "") : caption %></a>
1
+ <a href="<%= embed_id.to_s %>" id="<%= id %>" class="<%= klass %>">
2
+ <%= caption.to_s.empty? ? embed_id.to_s.sub(/^https*:\/\//, "").sub(/\/$/, "") : caption %>
3
+ </a>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown_media
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Becker
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-28 00:00:00.000000000 Z
11
+ date: 2018-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler