embeditor-rails 0.0.1

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.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Southern California Public Radio
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,188 @@
1
+ # Embeditor
2
+
3
+ Embeditor is a set of client-side adapters for various embed codes.
4
+ It aims to keep your article bodies clean while still allowing you
5
+ to have rich embeds within them.
6
+
7
+ ## Installation
8
+
9
+ It's a Rails engine. Add it to your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'embeditor'
13
+ ```
14
+
15
+
16
+ ## Dependencies
17
+
18
+ Currently, [`underscore.js`](http://underscorejs.org/) is a required dependency.
19
+ I hope to remove this dependency eventually.
20
+
21
+
22
+ ## Usage
23
+
24
+ **Note** Currently Embeditor (the JS library) exists only in this Rails plugin.
25
+ Eventually it will be extracted to a pure-JS library and this gem will be a
26
+ simple wrapper around it.
27
+
28
+ First, add `embeditor` to your `application.js` manifest file:
29
+
30
+ ```javascript
31
+ //= require embeditor
32
+ ```
33
+
34
+ Next, initialize `Embeditor.Base` on any page where you want the swapping to
35
+ occur, and call its `swap()` function to perform the swapping:
36
+
37
+ ```html
38
+ <script type="text/javascript">
39
+ embeditor = new Embeditor.Base()
40
+ embeditor.swap()
41
+ </script>
42
+ ```
43
+
44
+ Embeditor works by replacing `A` tags (eg. `<a href="...">Embed</a>`) with the
45
+ appropriate embed. There are several adapters included with this engine:
46
+
47
+ * **Embedly** - Covers several services, such as SoundCloud, Spotify,
48
+ Facebook, Scribd, among others. Unfortunately, Embedly doesn't work perfectly
49
+ all the time.
50
+ * **Cover It Live**
51
+ * **Document Cloud**
52
+ * **KPCC's Fire Tracker**
53
+ * **Rebel Mouse**
54
+
55
+ None of these are included automatically. To install just the ones you need,
56
+ add them to your `application.js` :
57
+
58
+ ```javascript
59
+ //= include embeditor/adapters/embedly
60
+ //= include embeditor/adapters/cover_it_live
61
+ ```
62
+
63
+ Or you can add all of them at once:
64
+
65
+ ```javascript
66
+ //= require embeditor/adapters
67
+ ```
68
+
69
+ You can also selectively require templates:
70
+
71
+ ```javascript
72
+ //= require embeditor/templates/cover_it_live
73
+ ```
74
+
75
+ ... or require them all at once:
76
+
77
+ ```javascript
78
+ //= require embeditor/templates
79
+ ```
80
+
81
+ ### Configuration
82
+
83
+ Embeditor offers a system of configuration precedence.
84
+ The order of precedence is:
85
+
86
+ 1. `data-attributes` on the placeholder link itself.
87
+ 2. Adapter-specific configuration in the `Embeditor.Base` object.
88
+ 3. Global configuration on `Embeditor.Base`
89
+ 4. Adapter-specific defaults.
90
+
91
+ #### data-attributes
92
+
93
+ You may add a `data-attribute` to any placeholder link, which will be used
94
+ in the query or embed code. This method of specifying configuration takes
95
+ precedence over any other configuration. The names of the data-attributes
96
+ get passed directly to the query or embed code (depending on the adapter).
97
+ Only the data-attributes which have to do with the embed will be passed through;
98
+ attributes like `data-service` won't be used.
99
+
100
+ In the following example, the `maxheight` property will be sent to the oembed
101
+ endpoint:
102
+
103
+ ```html
104
+ <a href="http://projects.scpr.org/firetracker/oembed?url=http://projects.scpr.org/firetracker/rim-fire/" data-maxheight="450" class="embed-placeholder" data-service="firetracker">Rim Fire</a>
105
+ ```
106
+
107
+ #### Adapter-specific configuration
108
+
109
+ When initializing the global `Embeditor.Base` object, you may specify
110
+ configuration for individual adapters.
111
+
112
+ The `plugin` object is for configuring the adapter.
113
+
114
+ The `query` object is for configuring the query parameters, or in the case of
115
+ an adapter which doesn't use a query, it's for configuring the embed properties.
116
+
117
+ For the most part, everything will be pretty consistent.
118
+
119
+ ```javascript
120
+ new Embeditor.Base({
121
+ Embedly: {
122
+ query: {
123
+ maxheight: 450
124
+ },
125
+ plugin: {
126
+ key: '12345'
127
+ }
128
+ },
129
+ FireTracker: {
130
+ query: {
131
+ maxheight: 350
132
+ }
133
+ },
134
+ CoverItLive: {
135
+ query: {
136
+ maxheight: 500
137
+ }
138
+ }
139
+ })
140
+ ```
141
+
142
+ #### Global configuration
143
+
144
+ You may also specify global configuration in `Embeditor.Base`, which will be
145
+ used for all adapters:
146
+
147
+ ```javascript
148
+ new Embeditor.Base({
149
+ maxheight: 450,
150
+ maxwidth: 200
151
+ })
152
+ ```
153
+
154
+ #### Adapter-specific defaults
155
+
156
+ Finally, if you're writing an adapter, you should specify a `QueryDefaults`
157
+ object on the adapter, which will be used as a fallback for that adapter's
158
+ parameters:
159
+
160
+ ```coffeescript
161
+ class Embeditor.Adapters.Twitter extends Embeditor.Adapter
162
+ @QueryDefaults =
163
+ maxheight: 500
164
+
165
+ # ...
166
+ ```
167
+
168
+
169
+ ### Embedly
170
+
171
+ Embedly requires a key. You can provide it while initializing `Embeditor.Base`:
172
+
173
+ ```javascript
174
+ new Embeditor.Base({
175
+ Embedly: {
176
+ plugin: {
177
+ key: '12345'
178
+ }
179
+ }
180
+ })
181
+ ```
182
+
183
+
184
+ ## Extending
185
+
186
+ You can/should add your own adapters! It's easy, I promise. If you add one
187
+ which you think could be useful to a lot of people, please submit a PR and
188
+ share the wealth!
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Embeditor'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
@@ -0,0 +1,2 @@
1
+ //= require embeditor/embeditor
2
+ //= require embeditor/adapter
@@ -0,0 +1,38 @@
1
+ # Your Adapter should define:
2
+ # * QueryDefaults - an object of defaults to send as query parameters
3
+
4
+ class Embeditor.Adapter
5
+ @TemplatePath = "embeditor/templates/"
6
+
7
+ constructor: (@element, options={}) ->
8
+ @href = @element.attr('href')
9
+
10
+
11
+ swap: ->
12
+ return
13
+
14
+
15
+ _extractData: ->
16
+ adapter = @constructor.name
17
+ dataOptions = {}
18
+
19
+ for key,val of @element.data()
20
+ # Make sure we care about this attribute
21
+ if Embeditor.Adapters[adapter].QueryDefaults?[key]
22
+ dataOptions[key] = val
23
+
24
+ dataOptions
25
+
26
+
27
+ # We're combining a few things (in order of precedence):
28
+ # 1. The `data-attributes` of the placeholder,
29
+ # 2. The adapter-specific options specified at Embeditor
30
+ # initialization,
31
+ # 3. The global options specified at Embeditor initialization,
32
+ # 4. This adapter's default options (fallback options).
33
+ _buildParams: (dataOptions, options) ->
34
+ adapter = @constructor.name
35
+
36
+ _.defaults(dataOptions,
37
+ options[adapter]?['query'], options['query']
38
+ Embeditor.Adapters[adapter].QueryDefaults)
@@ -0,0 +1 @@
1
+ //= require_tree ./adapters
@@ -0,0 +1,24 @@
1
+ class Embeditor.Adapters.CoverItLive extends Embeditor.Adapter
2
+ @Template = JST[Embeditor.Adapter.TemplatePath + 'cover_it_live']
3
+
4
+ @QueryDefaults =
5
+ maxheight : 550
6
+ maxwidth : 620
7
+
8
+ @Matcher = new RegExp "/altcast_code=([^/]+)/", "gi"
9
+
10
+
11
+ constructor: (@element, options={}) ->
12
+ @dataOptions = @_extractData()
13
+ @queryParams = @_buildParams(@dataOptions, options)
14
+
15
+ super
16
+
17
+
18
+ swap: ->
19
+ event_id = CoverItLive.Matcher.exec(@href)[1]
20
+
21
+ @element.after CoverItLive.Template
22
+ maxheight : @queryParams.maxheight,
23
+ maxwidth : @queryParams.maxwidth,
24
+ event_id : @event_id
@@ -0,0 +1 @@
1
+ class Embeditor.Adapters.DocumentCloud extends Embeditor.Adapter
@@ -0,0 +1,35 @@
1
+ # This doesn't inherit from Adapters.Oembed because the Embedly plugin
2
+ # handles most of that stuff on its own.
3
+ class Embeditor.Adapters.Embedly extends Embeditor.Adapter
4
+ # This object should hold any keys that we want to
5
+ # send to the API. Any key not in this object will
6
+ # be ignored as a data attribute.
7
+ @QueryDefaults =
8
+ maxheight : 450
9
+
10
+ @PluginDefaults =
11
+ method : "after"
12
+ className : Embeditor.DefaultOptions.wrapperClass
13
+ endpoint : 'oembed'
14
+ # Key must be specified
15
+
16
+
17
+ constructor: (@element, options={}) ->
18
+ pluginOpts = options['Embedly']?['plugin'] or {}
19
+ @pluginOptions = _.defaults(pluginOpts, Embedly.PluginDefaults)
20
+
21
+ super
22
+
23
+
24
+ swap: ->
25
+ params = @_buildEmbedlyParams()
26
+ @element.embedly(params)
27
+
28
+
29
+ _buildEmbedlyParams: ->
30
+ if @embedlyParams
31
+ return @embedlyParams
32
+
33
+ @embedlyParams = _.extend(
34
+ @pluginOptions,
35
+ query : @queryParams)
@@ -0,0 +1,7 @@
1
+ class Embeditor.Adapters.FireTracker extends Embeditor.Adapters.Oembed
2
+ @Path = "http://projects.scpr.org/firetracker/oembed"
3
+
4
+ @QueryDefaults =
5
+ maxwidth : 510
6
+ maxheight : 374
7
+ format : 'json'
@@ -0,0 +1,17 @@
1
+ class Embeditor.Adapters.Oembed extends Embeditor.Adapter
2
+ # Override this. Oembed endpoint.
3
+ @Path = null
4
+
5
+ constructor: (@element, options={}) ->
6
+ @dataOptions = @_extractData()
7
+ @queryParams = @_buildParams(@dataOptions, options)
8
+
9
+ super
10
+
11
+
12
+ swap: ->
13
+ $.getJSON(
14
+ Embeditor.Adapters[@constructor.name].Path,
15
+ _.extend({url: @href}, @queryParams),
16
+ (data, textStatus, jqXHR) => @element.after(data.html)
17
+ )
@@ -0,0 +1,7 @@
1
+ class Embeditor.Adapters.Polldaddy extends Embeditor.Adapters.Oembed
2
+ @Path = "http://polldaddy.com/oembed"
3
+
4
+ @QueryDefaults =
5
+ maxwidth : 510
6
+ maxheight : 374
7
+ format : 'json'
@@ -0,0 +1 @@
1
+ class Embeditor.Adapters.RebelMouse extends Embeditor.Adapter
@@ -0,0 +1,70 @@
1
+ window.Embeditor = {
2
+ Adapters : {}
3
+
4
+ DefaultAdapters :
5
+ 'youtube' : 'Embedly'
6
+ 'vimeo' : 'Embedly'
7
+ # 'brightcove' : 'Embedly'
8
+ 'ustream' : 'Embedly'
9
+ 'vine' : 'Embedly'
10
+ # 'googlemaps' : 'Embedly'
11
+ 'scribd' : 'Embedly'
12
+ # 'documentcloud' : 'DocumentCloud'
13
+ 'polldaddy' : 'Polldaddy'
14
+ 'facebook' : 'Embedly'
15
+ # 'storify' : 'Embedly'
16
+ 'coveritlive' : 'CoverItLive'
17
+ # 'rebelmouse' : 'RebelMouse'
18
+ 'firetracker' : 'FireTracker'
19
+ # 'twitter' : 'Embedly'
20
+ 'instagram' : 'Embedly'
21
+ 'soundcloud' : 'Embedly'
22
+ 'spotify' : 'Embedly'
23
+ 'other' : 'Embedly'
24
+
25
+ DefaultOptions :
26
+ defaultAdapter : 'Embedly' # Adapter that gets used when the service isn't recognized
27
+ defaultService : 'other' # Service that gets used when the `data-service` attribute is missing
28
+ placeholderClass : "embed-placeholder" # The class that the embed placeholders have
29
+ wrapperClass : "embed-wrapper" # The class the embed's wrapper should be given
30
+ }
31
+
32
+
33
+ class Embeditor.Base
34
+ constructor: (options={}, adapters={}) ->
35
+ @options = _.defaults(options, Embeditor.DefaultOptions)
36
+ @adapters = _.defaults(adapters, Embeditor.DefaultAdapters)
37
+
38
+ @placeholders = []
39
+ @links = $(@_classify @options.placeholderClass)
40
+
41
+ @findEmbeds()
42
+
43
+
44
+ swap: ->
45
+ placeholder.swap() for placeholder in @placeholders
46
+
47
+
48
+ findEmbeds: ->
49
+ for link in @links
50
+ link = $(link)
51
+
52
+ # If "service" is blank in the CKEditor dialog, then it will
53
+ # omit that data-attribute from the tag, and therefore
54
+ # be undefined. In this scenario, we want to use the default
55
+ # service as a fallback.
56
+ #
57
+ # If "service" is present but has no match in the Adapters object,
58
+ # then we want to use the default handler as a fallback.
59
+ service = link.data('service') || @options.defaultService
60
+ adapterName = @adapters[service] || @options.defaultAdapter
61
+ adapter = Embeditor.Adapters[adapterName]
62
+
63
+ return if not adapter
64
+
65
+ placeholder = new adapter(link, @options)
66
+ @placeholders.push(placeholder)
67
+
68
+
69
+ _classify: (str) ->
70
+ "." + str
@@ -0,0 +1 @@
1
+ //= require_tree ./templates
@@ -0,0 +1,4 @@
1
+ <div id='cil-root-<%=@event_id%>' class='cil-root'>
2
+ <span class='cil-config-data' title='{"altcastCode":"<%=@event_id%>","server":"www.coveritlive.com","geometry":{"width":<%=@maxwidth%>,"height":<%=@maxheight%>},"configuration":{"newEntryLocation":"bottom","pinsGrowSize":"on","titlePage":"on","skinOverride":"2"}}'>&nbsp;</span>
3
+ </div>
4
+ <script type='text/javascript'>window.cilAsyncInit = function() {cilEmbedManager.init()};(function() {var e = document.createElement('script');e.async = true;var domain = (document.location.protocol == 'http:') ? '//cdnsl.coveritlive.com' : '//cdnslssl.coveritlive.com';e.src = document.location.protocol + domain + '/vw.js?v=' + Math.floor(Math.random()*10000000);e.id = 'cilScript-<%=@event_id%>';document.getElementById('cil-root-<%=@event_id%>').appendChild(e);}());</script>
@@ -0,0 +1,8 @@
1
+ require 'embeditor-rails/version'
2
+
3
+ module Embeditor
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Embeditor
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embeditor-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bryan Ricker
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: eco
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.0.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: sqlite3
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Embeditor is a set of client-side adapters for various embed codes. It
63
+ aims to keep your article bodies clean while still allowing you to have rich embeds
64
+ within them. This is a Rails plugin for that library.
65
+ email:
66
+ - bricker@kpcc.org
67
+ executables: []
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - app/assets/javascripts/embeditor/adapter.js.coffee
72
+ - app/assets/javascripts/embeditor/adapters/cover_it_live.js.coffee
73
+ - app/assets/javascripts/embeditor/adapters/document_cloud.js.coffee
74
+ - app/assets/javascripts/embeditor/adapters/embedly.js.coffee
75
+ - app/assets/javascripts/embeditor/adapters/fire_tracker.js.coffee
76
+ - app/assets/javascripts/embeditor/adapters/oembed.js.coffee
77
+ - app/assets/javascripts/embeditor/adapters/polldaddy.js.coffee
78
+ - app/assets/javascripts/embeditor/adapters/rebel_mouse.js.coffee
79
+ - app/assets/javascripts/embeditor/adapters.js
80
+ - app/assets/javascripts/embeditor/embeditor.js.coffee
81
+ - app/assets/javascripts/embeditor/templates/cover_it_live.jst.eco
82
+ - app/assets/javascripts/embeditor/templates.js
83
+ - app/assets/javascripts/embeditor.js
84
+ - lib/embeditor-rails/version.rb
85
+ - lib/embeditor-rails.rb
86
+ - MIT-LICENSE
87
+ - Rakefile
88
+ - README.md
89
+ homepage: https://github.com/SCPR/embeditor-rails
90
+ licenses: []
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 1.8.25
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: Embeditor plugin for Rails.
113
+ test_files: []