markdown_media 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4c41aae15dd55204681c7f3e1643552328690730
4
+ data.tar.gz: dac479107bd7538a54278d7ff88176622395080f
5
+ SHA512:
6
+ metadata.gz: 6458da5a6a86516e79a04bb73ff47ce8ca29c61f93687593bcd19d55bf013d2cd6871653a8ebd18fbcca22b0ae67548ad824162bb5548099ef62590bd805623e
7
+ data.tar.gz: eaad1b978d151e8467c07efd7cbda7272984d934d080fbcaffabce34672ceeaa792e5fef0b56dbbb2d5bb8e2515042228a582801ccc04ffd592dfaef16ef913f
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .DS_Store
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.0
5
+ - 2.3.0
6
+ - 2.4.0
7
+ before_install: gem install bundler -v 1.14.5
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at veganstraightedge@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in markdown_media.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,36 @@
1
+ # Creative Commons Legal Code
2
+
3
+ ## CC0 1.0 Universal
4
+
5
+ http://creativecommons.org/publicdomain/zero/1.0
6
+
7
+ Official translations of this legal tool are available> CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER.
8
+
9
+ ### _Statement of Purpose_
10
+
11
+ The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").
12
+
13
+ Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.
14
+
15
+ For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.
16
+
17
+ **1. Copyright and Related Rights.** A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:
18
+
19
+ 1. the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
20
+ 2. moral rights retained by the original author(s) and/or performer(s);
21
+ 3. publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
22
+ 4. rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
23
+ 5. rights protecting the extraction, dissemination, use and reuse of data in a Work;
24
+ 6. database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
25
+ 7. other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
26
+
27
+ **2. Waiver.** To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.
28
+
29
+ **3. Public License Fallback.** Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.
30
+
31
+ **4. Limitations and Disclaimers.**
32
+
33
+ 1. No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
34
+ 2. Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
35
+ 3. Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
36
+ 4. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.
data/README.md ADDED
@@ -0,0 +1,246 @@
1
+ # Markdown Media
2
+
3
+ [![Build Status](https://travis-ci.org/veganstraightedge/markdown_media.svg?branch=master)](https://travis-ci.org/veganstraightedge/markdown_media)
4
+ [![Code Climate](https://codeclimate.com/github/veganstraightedge/markdown_media/badges/gpa.svg)](https://codeclimate.com/github/veganstraightedge/markdown_media)
5
+ ![Version 1.0.0](https://img.shields.io/badge/VERSION-1.0.0-green.svg)
6
+
7
+ This syntax uses doubles square brackets on each side of a URL and optional options.
8
+ It expands into the current preferred embed code for that site's media or raw media.
9
+ Supported media types: YouTube, Vimeo, Instagram, Twitter, images, videos, audios.
10
+
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem "markdown_media"
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ ```
23
+ bundle
24
+ ```
25
+
26
+ Or install it yourself as:
27
+
28
+ ```
29
+ gem install markdown_media
30
+ ```
31
+
32
+
33
+ ## Usage
34
+
35
+ ### As a Writer
36
+
37
+ This a syntax that can sit on top of Markdown (or any templating format, except MediaWiki which already uses the double square bracket syntax). The purpose is to simplify adding images (with or without caption and optionally linked), videos, tweets, audio, etc for writers in a CMS. The HTML that we want for a video is different from an image. But as a writer, it's conceptually the same, "here's a piece of media and its caption, stick it in the page right here".
38
+
39
+ So, the media embed syntax makes it so you don't have to think about the differences between YouTube, Vimeo, Twitter and an image. Here's how it works.
40
+
41
+ There are six pieces. Some are required. Some are optional. It must always be on one line. But for explanation here, I'll put them on separate lines, then tie it all together.
42
+
43
+ ```
44
+ [[
45
+ media URL
46
+ caption
47
+ link URL (for images only)
48
+ HTML id
49
+ ]]
50
+ ```
51
+
52
+ Here's what they all mean.
53
+
54
+ - **Required**. Always put a blank line above the media embed
55
+ - **Required**. Always start the media embed with two left square brackets (no space between them).
56
+ - **Required**. Always add an absolute URL to the media. (More on supported URLs below)
57
+ - **Optional**. You can add a caption to images, videos, audios. Not for tweets though. The caption is processed as Markdown. So, you can use links, bold, and italics within the caption.
58
+ - **Optional**. You can add a URL that will be used to link the image. This can only be used for images, not video, audio, or tweets.
59
+ - **Optional**. If you need the media to have a certain id on the generated HTML (so that you can link to it), you can add id:desired-id-with-no-spaces as the last item in the media embed.
60
+ - **Required**. Always end the media embed with two right square brackets (no space between them).
61
+ - **Required**. Always put a blank line below the media embed
62
+
63
+ ### As a Developer
64
+
65
+ ```
66
+ MarkdownMedia.parse("[[https://example.com/photo.png]]")
67
+ ```
68
+
69
+ In Rails, you might also need to add `.html_safe` to avoid escaping.
70
+
71
+ ```
72
+ MarkdownMedia.parse("[[https://example.com/photo.png]]").html_safe
73
+ ```
74
+
75
+ ### Examples
76
+
77
+ #### Images
78
+
79
+ A simple image.
80
+
81
+ ```
82
+ [[https://example.com/image.png]]
83
+ ```
84
+
85
+ An image with a caption.
86
+
87
+ ```
88
+ [[https://example.com/image.png Look at me, I'm a caption!]]
89
+ ```
90
+
91
+ An image with Markdown in the caption.
92
+
93
+ ```
94
+ [[https://example.com/image.png _Look at me_, I'm a **caption**!]]
95
+ ```
96
+
97
+ An image linked to a URL (requires a caption present).
98
+
99
+ ```
100
+ [[https://example.com/image.png Some caption https://example.com/some/path]]
101
+ ```
102
+
103
+ An image linked to a path (requires a caption present).
104
+
105
+ ```
106
+ [[https://example.com/image.png Some caption /books/work]]
107
+ ```
108
+
109
+ #### Videos
110
+
111
+ A simple video.
112
+
113
+ ```
114
+ [[https://example.com/video.mp4]]
115
+ ```
116
+
117
+ A video with a caption.
118
+
119
+ ```
120
+ [[https://example.com/video.mp4 Even videos can have captions. Yay!]]
121
+ ```
122
+
123
+ A video from Vimeo.
124
+
125
+ ```
126
+ [[https://vimeo.com/2696386]]
127
+ ```
128
+
129
+ A video from Vimeo with caption.
130
+
131
+ ```
132
+ [[https://vimeo.com/2696386 History of the Internet]]
133
+ ```
134
+
135
+ A video from YouTube.
136
+
137
+ ```
138
+ [[https://www.youtube.com/watch?v=YX40hbAHx3s]]
139
+ ```
140
+
141
+ A video from YouTube with caption.
142
+
143
+ ```
144
+ [[https://www.youtube.com/watch?v=YX40hbAHx3s P vs. NP and the Computational Complexity Zoo]]
145
+ ```
146
+
147
+ YouTube's short URL format also works.
148
+
149
+ ```
150
+ [[https://youtu.be/YX40hbAHx3s]]
151
+ ```
152
+
153
+ A Daily Motion video.
154
+
155
+ ```
156
+ [[http://www.dailymotion.com/video/x5gwr1v_anarchists-in-rojava-announce-irpgf_news]]
157
+ ```
158
+
159
+ #### Audio
160
+
161
+ A simple audio.
162
+
163
+ ```
164
+ [[https://example.com/sound.mp3]]
165
+ ```
166
+
167
+ A simple audio with caption.
168
+
169
+ ```
170
+ [[https://example.com/sound.aac Sounds can have captions.]]
171
+ ```
172
+
173
+ #### Links
174
+
175
+ Any URL in a [[]] block that is unrecognized, just gets rendered into a linked URL.
176
+
177
+ ```
178
+ [[https://veganstraightedge.com/cancer]] gets turned into <a href="https://veganstraightedge.com/cancer">https://veganstraightedge.com</a>.
179
+ ```
180
+
181
+ If you try to embed some piece of media and it renders to a URL that means that that kind of URL isn't supported yet. But don't distress, new sites are pretty easy to add. So, raise a flag in Slack or GitHub Issues.
182
+
183
+ ### Supported Media URLs
184
+
185
+ Here are the currently supported URLs and media types.
186
+
187
+ #### Videos
188
+
189
+ - https://example.com/video.mp4
190
+ - https://example.com/video.avi
191
+ - https://example.com/video.mov
192
+ - https://example.com/video.ogv
193
+ - https://example.com/video.webm
194
+ - https://example.com/video.m4v
195
+ - https://example.com/video.3gp
196
+ - https://example.com/video.m3u8
197
+ - https://vimeo.com/1234
198
+ - https://www.youtube.com/watch?v=video-id
199
+ - https://youtu.be/video-id
200
+ - http://www.dailymotion.com/video/video-id_video-slug
201
+
202
+ #### Audios
203
+
204
+ - https://example.com/audio.mp3
205
+ - https://example.com/audio.aac
206
+ - https://example.com/audio.wav
207
+ - https://example.com/audio.ogg
208
+ - https://example.com/audio.oga
209
+ - https://example.com/audio.m4a
210
+
211
+ #### Images
212
+
213
+ - https://example.com/image.png
214
+ - https://example.com/image.jpeg
215
+ - https://example.com/image.jpg
216
+ - https://example.com/image.gif
217
+ - https://example.com/image.svg
218
+
219
+ #### Tweets
220
+
221
+ - https://twitter.com/veganstraightedge/status/854782420591165440
222
+
223
+
224
+ ## Development
225
+
226
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
227
+
228
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
229
+
230
+
231
+ ## Contributing
232
+
233
+ Bug reports and pull requests are welcome on GitHub at https://github.com/veganstraightedge/markdown_media. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
234
+
235
+
236
+ ## License
237
+
238
+ **PUBLIC DOMAIN**
239
+
240
+ Your heart is as free as the air you breathe. <br>
241
+ The ground you stand on is liberated territory.
242
+
243
+ In legal text, *Markdown Media* is dedicated to the public domain
244
+ using Creative Commons -- CC0 1.0 Universal.
245
+
246
+ [http://creativecommons.org/publicdomain/zero/1.0](http://creativecommons.org/publicdomain/zero/1.0 "Creative Commons &mdash; CC0 1.0 Universal")
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "markdown_media"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module MarkdownMedia
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,119 @@
1
+ require "markdown_media/version"
2
+ require "open-uri"
3
+ require "erb"
4
+ require "kramdown"
5
+
6
+ module MarkdownMedia
7
+ EMBED_REGEX = /\[\[\s*(http[^\]\s]+(?:\s.+)?)\s*\]\]/
8
+
9
+ class << self
10
+ def parse(text)
11
+ output = text.gsub(EMBED_REGEX) do
12
+ embed_tag = $1
13
+
14
+ unless embed_tag.to_s.empty?
15
+ embed_tag_pieces = embed_tag.split(" ")
16
+
17
+ url = embed_tag_pieces.shift
18
+ id = remove_id(embed_tag_pieces)
19
+ link = if embed_tag_pieces.to_s.empty?
20
+ embed_tag_pieces.pop if url_or_path?(embed_tag_pieces.last)
21
+ end
22
+
23
+ caption = embed_tag_pieces.join(" ")
24
+
25
+ expanded_embed(url, caption: caption, link: link, id: id)
26
+ end
27
+ end
28
+
29
+ output
30
+ end
31
+
32
+ def url_or_path?(string)
33
+ string =~ /^(http|\/)\S+/ ? true : false
34
+ end
35
+
36
+ def remove_id(pieces)
37
+ return if pieces.to_s.empty?
38
+
39
+ id_string = pieces.detect { |piece| piece =~ /id:\S+/ }
40
+
41
+ if id_string
42
+ id = id_string.split(":").last
43
+ pieces.delete(id_string)
44
+
45
+ id
46
+ end
47
+ end
48
+
49
+ def expanded_embed(url, caption: nil, link: nil, id: nil)
50
+ url = URI.parse(url)
51
+
52
+ case url.host
53
+ when /youtube.com/
54
+ slug = "youtube"
55
+ embed_id = nil
56
+
57
+ url.query.split("&").each do |key_value_pair|
58
+ argument, value = key_value_pair.split("=")
59
+ if argument == "v"
60
+ embed_id = value
61
+ end
62
+ end
63
+
64
+ when "youtu.be"
65
+ slug = "youtube"
66
+ embed_id = url.path.split("/").map{ |path_piece| path_piece unless path_piece.to_s.empty? }.compact.first
67
+
68
+ when /dailymotion.com/
69
+ slug = "dailymotion"
70
+ embed_id = url.path.split("/video/").map{ |path_piece| path_piece unless path_piece.to_s.empty? }.compact.first.split("_").first
71
+
72
+ when "vimeo.com"
73
+ slug = "vimeo"
74
+ embed_id = url.path.split("/").map{ |path_piece| path_piece unless path_piece.to_s.empty? }.compact.first
75
+
76
+ when "twitter.com"
77
+ slug = "twitter"
78
+
79
+ else
80
+ slug = case url.path
81
+
82
+ when /\.mp3|\.aac|\.wav|\.ogg|\.oga|\.m4a/
83
+ "audio"
84
+ when /\.mp4|\.avi|\.mov|\.ogv|\.webm|\.m4v|\.3gp|\.m3u8/
85
+ "video"
86
+ when /\.png|\.jpeg|\.jpg|\.gif|\.svg/
87
+ "image"
88
+ else
89
+ "link"
90
+ end
91
+ end
92
+
93
+ render_erb slug, { embed_id: embed_id || url.to_s, caption: caption, link: link, id: id }
94
+ end
95
+
96
+ def render_erb(template_slug, locals)
97
+ template_path = "/templates/#{template_slug}.erb"
98
+ template = File.read(File.expand_path File.dirname(__FILE__) + template_path)
99
+
100
+ embed_id = locals[:embed_id]
101
+ caption = locals[:caption]
102
+ link = locals[:link]
103
+ id = locals[:id]
104
+
105
+ erb = ERB.new(template)
106
+ erb.result(binding)
107
+ end
108
+
109
+ def render_markdown(text)
110
+ ::Kramdown::Document.new(
111
+ text,
112
+ input: :kramdown,
113
+ remove_block_html_tags: false,
114
+ transliterated_header_ids: true
115
+ ).to_html
116
+ end
117
+
118
+ end
119
+ end
@@ -0,0 +1,9 @@
1
+ <figure id="<%= id %>">
2
+ <audio controls>
3
+ <source src="<%= embed_id %>" />
4
+ </audio>
5
+
6
+ <% unless caption.to_s.empty? %>
7
+ <figcaption class="caption audio-caption"><%= MarkdownMedia.render_markdown caption %></figcaption>
8
+ <% end %>
9
+ </figure>
@@ -0,0 +1,10 @@
1
+ <figure class="video-container" id="<%= id %>">
2
+ <iframe frameborder="0" src="//www.dailymotion.com/embed/video/<%= embed_id %>" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
3
+
4
+ <% unless caption.to_s.empty? %>
5
+ <figcaption class="caption video-caption video-caption-vimeo">
6
+ <%= MarkdownMedia.render_markdown caption %>
7
+ </figcaption>
8
+ <% end %>
9
+ </figure>
10
+
@@ -0,0 +1,25 @@
1
+ <% if caption.to_s.empty? %>
2
+
3
+ <figure id="<%= id %>">
4
+ <% if link.to_s.empty? %>
5
+ <img src="<%= embed_id %>" />
6
+ <% else %>
7
+ <a href="<%= link %>"><img src=<%= embed_id %> /></a>
8
+ <% end %>
9
+ </figure>
10
+
11
+ <% else %>
12
+
13
+ <figure id="<%= id %>">
14
+ <% if link.to_s.empty? %>
15
+ <img src="<%= embed_id %>" />
16
+ <% else %>
17
+ <a href="<%= link %>">
18
+ <img src="<%= embed_id %>" />
19
+ </a>
20
+ <% end %>
21
+
22
+ <figcaption><%= MarkdownMedia.render_markdown caption %></figcaption>
23
+ </figure>
24
+
25
+ <% end %>
@@ -0,0 +1 @@
1
+ <a href="<%= embed_id.to_s %>" id="<%= id %>"><%= caption.to_s.empty? ? embed_id.to_s.sub(/^https*:\/\//, "").sub(/\/$/, "") : caption %></a>
@@ -0,0 +1,4 @@
1
+ <blockquote class="twitter-tweet" data-lang="en" id="<%= id %>">
2
+ <a href="<%= embed_id.to_s %>"><%= embed_id.to_s %></a>
3
+ </blockquote>
4
+ <script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
@@ -0,0 +1,11 @@
1
+ <figure class="video-container" id="<%= id %>">
2
+ <video controls>
3
+ <source src="<%= embed_id %>" />
4
+ </video>
5
+
6
+ <% unless caption.to_s.empty? %>
7
+ <figcaption class="caption video-caption">
8
+ <%= MarkdownMedia.render_markdown caption %>
9
+ </figcaption>
10
+ <% end %>
11
+ </figure>
@@ -0,0 +1,9 @@
1
+ <figure class="video-container" id="<%= id %>">
2
+ <iframe src="https://player.vimeo.com/video/<%= embed_id %>?title=0&amp;byline=0&amp;portrait=0" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
3
+
4
+ <% unless caption.to_s.empty? %>
5
+ <figcaption class="caption video-caption video-caption-vimeo">
6
+ <%= MarkdownMedia.render_markdown caption %>
7
+ </figcaption>
8
+ <% end %>
9
+ </figure>
@@ -0,0 +1,9 @@
1
+ <figure class="video-container" id="<%= id %>">
2
+ <iframe src="https://www.youtube.com/embed/<%= embed_id %>" frameborder="0" allowfullscreen></iframe>
3
+
4
+ <% unless caption.to_s.empty? %>
5
+ <figcaption class="caption video-caption video-caption-youtube">
6
+ <%= MarkdownMedia.render_markdown caption %>
7
+ </figcaption>
8
+ <% end %>
9
+ </figure>
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "markdown_media/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "markdown_media"
8
+ spec.version = MarkdownMedia::VERSION
9
+ spec.authors = ["Shane Becker"]
10
+ spec.email = ["veganstraightedge@gmail.com"]
11
+
12
+ spec.summary = %q{A [[ URL ]] syntax to embed media into views.}
13
+ spec.description = %q{
14
+ This syntax uses doubles square brackets on each side of a URL and optional options.
15
+ It expands into the current preferred embed code for that site's media or raw media.
16
+ Supported media types: YouTube, Vimeo, Instagram, Twitter, images, videos, audios.
17
+ }
18
+ spec.homepage = "https://github.com/veganstraightedge/markdown_media"
19
+ spec.license = "CC0"
20
+
21
+ spec.required_ruby_version = ">= 2.2"
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
24
+ f.match(%r{^(test|spec|features)/})
25
+ end
26
+
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.14"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+
35
+ spec.add_runtime_dependency "kramdown"
36
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markdown_media
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Shane Becker
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: kramdown
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: "\n This syntax uses doubles square brackets on each side of a URL
70
+ and optional options.\n It expands into the current preferred embed code for
71
+ that site's media or raw media.\n Supported media types: YouTube, Vimeo, Instagram,
72
+ Twitter, images, videos, audios.\n "
73
+ email:
74
+ - veganstraightedge@gmail.com
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - ".travis.yml"
82
+ - CODE_OF_CONDUCT.md
83
+ - Gemfile
84
+ - LICENSE.md
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/setup
89
+ - lib/markdown_media.rb
90
+ - lib/markdown_media/version.rb
91
+ - lib/templates/audio.erb
92
+ - lib/templates/dailymotion.erb
93
+ - lib/templates/image.erb
94
+ - lib/templates/link.erb
95
+ - lib/templates/twitter.erb
96
+ - lib/templates/video.erb
97
+ - lib/templates/vimeo.erb
98
+ - lib/templates/youtube.erb
99
+ - markdown_media.gemspec
100
+ homepage: https://github.com/veganstraightedge/markdown_media
101
+ licenses:
102
+ - CC0
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '2.2'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.6.8
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: A [[ URL ]] syntax to embed media into views.
124
+ test_files: []