Skip to content

Commit

Permalink
add embed functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
patwalls committed Dec 28, 2018
1 parent c5096c0 commit e030a71
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ gem "paperclip", "~> 6.0.0"

gem 'aws-sdk', '~> 3'

gem 'rack-cors', :require => 'rack/cors'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ GEM
public_suffix (3.0.3)
puma (3.12.0)
rack (2.0.5)
rack-cors (1.0.2)
rack-protection (2.0.4)
rack
rack-test (1.1.0)
Expand Down Expand Up @@ -955,6 +956,7 @@ DEPENDENCIES
paperclip (~> 6.0.0)
pg
puma (~> 3.11)
rack-cors
rails (~> 5.2.0)
rest-client
sass-rails (~> 5.0)
Expand Down
21 changes: 21 additions & 0 deletions app/views/i/posts/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,24 @@
%time.lighter{ datetime: @post.published }= @post.published&.strftime("%B #{@post.published.day.ordinalize}, %Y")
%h1= @post.title
= raw @parsed.html_safe

:javascript
$(".article a").each(function() {
var node = this;

if (this.text === "embed:tweet") {
$.ajax({
url: `https://publish.twitter.com/oembed?url=${node.href}`,
type: "GET",
dataType: "jsonp",
success: function (response) {
var nodeToReplace = $(node)
nodeToReplace.parent().append($(response.html))
nodeToReplace.remove()
},
error: function (xhr, status) {
console.log("error");
}
});
}
});
7 changes: 7 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ class Application < Rails::Application
# -- all .rb files in that directory are automatically loaded after loading
# the framework and any gems in your application.

config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*', headers: :any, methods: [:get, :post, :options]
end
end

Raven.configure do |config|
config.dsn = 'https://3286d54592144330be6af85fd527f76b:[email protected]/1286413'
end
Expand Down

0 comments on commit e030a71

Please sign in to comment.