Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sov-87 committed Apr 18, 2017
1 parent 4d9b289 commit 34de266
Show file tree
Hide file tree
Showing 58 changed files with 1,434 additions and 41 deletions.
53 changes: 12 additions & 41 deletions .gitignore
@@ -1,42 +1,13 @@
*.rbc
capybara-*.html
.rspec
/log
/tmp
/db/*.sqlite3
/db/*.sqlite3-journal
/public/system
/coverage/
/spec/tmp
**.orig
rerun.txt
pickle-email-*.html

# TODO Comment out these rules if you are OK with secrets being uploaded to the repo
config/initializers/secret_token.rb
config/secrets.yml

# dotenv
# TODO Comment out this rule if environment variables can be committed
!.gitkeep
.DS_Store
*.log
*.pid
.env

## Environment normalization:
/.bundle
/vendor/bundle

# these should all be checked in to normalize the environment:
# Gemfile.lock, .ruby-version, .ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc

# if using bower-rails ignore default bower_components path bower.json files
/vendor/assets/bower_components
*.bowerrc
bower.json

# Ignore pow environment settings
.powenv

# Ignore Byebug command history file.
.byebug_history
.bundle/
log/*.log
spec/test_app/db/*.sqlite3
spec/test_app/db/*.sqlite3-journal
spec/test_app/log/*.log
spec/test_app/tmp/*
spec/test_app/.sass-cache
spec/test_app/public/*
10 changes: 10 additions & 0 deletions Gemfile
@@ -0,0 +1,10 @@
source "https://rubygems.org"

# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec

# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.
141 changes: 141 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,141 @@
PATH
remote: .
specs:
grid-editor-integration (0.0.11)

GEM
remote: https://rubygems.org/
specs:
actionmailer (4.2.6)
actionpack (= 4.2.6)
actionview (= 4.2.6)
activejob (= 4.2.6)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.6)
actionview (= 4.2.6)
activesupport (= 4.2.6)
rack (~> 1.6)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (4.2.6)
activesupport (= 4.2.6)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
activejob (4.2.6)
activesupport (= 4.2.6)
globalid (>= 0.3.0)
activemodel (4.2.6)
activesupport (= 4.2.6)
builder (~> 3.1)
activerecord (4.2.6)
activemodel (= 4.2.6)
activesupport (= 4.2.6)
arel (~> 6.0)
activesupport (4.2.6)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.3)
aws-sdk-v1 (1.66.0)
json (~> 1.4)
nokogiri (>= 1.4.4)
builder (3.2.2)
concurrent-ruby (1.0.2)
diff-lcs (1.3)
erubis (2.7.0)
globalid (0.3.6)
activesupport (>= 4.1.0)
i18n (0.7.0)
json (1.8.3)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.4)
mime-types (>= 1.16, < 4)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.9.0)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
pkg-config (1.1.7)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.6)
actionmailer (= 4.2.6)
actionpack (= 4.2.6)
actionview (= 4.2.6)
activejob (= 4.2.6)
activemodel (= 4.2.6)
activerecord (= 4.2.6)
activesupport (= 4.2.6)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.6)
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.7)
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (4.2.6)
actionpack (= 4.2.6)
activesupport (= 4.2.6)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (11.2.2)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-rails (3.5.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
sprockets (3.6.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.0.4)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (0.19.1)
thread_safe (0.3.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)

PLATFORMS
ruby

DEPENDENCIES
aws-sdk-v1
grid-editor-integration!
rails
rspec
rspec-rails

BUNDLED WITH
1.14.3
20 changes: 20 additions & 0 deletions MIT-LICENSE
@@ -0,0 +1,20 @@
Copyright 2016 YOURNAME

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 changes: 27 additions & 0 deletions README.md
@@ -0,0 +1,27 @@
Grid Editor Integration
=======================
Этот проект позволяет интегрировать в приложения на основе RubyOnRails [SetkaEditor](http://ru.setka.io/editor/) - удобный плагин для оформления статей.

Gem предоставляет возможность [скачивания и обновления плагина](app/controllers/grid/editor_integration/config_controller.rb), [создания сниппетов](app/controllers/grid/editor_integration/snippets_controller.rb).

Поскольку плагин может храниться не только в локальной файловой системе, мы реализовали [хранилища](lib/grid/editor_integration/storages/abstract.rb) - [файловое](lib/grid/editor_integration/storages/file.rb) и [S3](lib/grid/editor_integration/storages/s3.rb). Также при необходимости можно реализовать свой класс хранилища и использовать его.

Также рекомендуем ознакомиться с [примером приложения, использующим интеграцию](spec/test_app)

Установка
---------
Добавьте в Gemfile строку
```gem 'grid-editor-integration', git: 'ssh://git@grid-editor-integration.git'```
Либо установите gem вручную.

Настройка
---------
Необходимо задать параметры
```
Grid::EditorIntegration.token
Grid::EditorIntegration.storage
```

По-умолчанию будет использоваться [файловое](lib/grid/editor_integration/storages/file.rb) хранилище. Все параметры и их значения по-умолчанию можно посмотреть [здесь](lib/grid/editor_integration.rb)

This uses MIT-LICENSE
34 changes: 34 additions & 0 deletions Rakefile
@@ -0,0 +1,34 @@
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end

require 'rdoc/task'

RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'UniversalApi'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end

APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'



Bundler::GemHelper.install_tasks

require 'rake/testtask'

Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end


task default: :test
27 changes: 27 additions & 0 deletions app/controllers/concerns/grid/editor_integration/check_token.rb
@@ -0,0 +1,27 @@
require 'active_support/concern'

module Grid
module EditorIntegration
module CheckToken
extend ActiveSupport::Concern

included do
before_action :check_token
rescue_from Grid::EditorIntegration::Errors::InvalidToken,
with: :unauthorized
end

protected

def check_token
if params["token"] != Grid::EditorIntegration.token
raise Grid::EditorIntegration::Errors::InvalidToken
end
end

def unauthorized
render nothing: true, status: 403
end
end
end
end
26 changes: 26 additions & 0 deletions app/controllers/concerns/grid/editor_integration/editor_config.rb
@@ -0,0 +1,26 @@
require 'active_support/concern'

module Grid
module EditorIntegration
module EditorConfig
extend ActiveSupport::Concern

included do
rescue_from Grid::EditorIntegration::Errors::InvalidConfig,
with: :bad_request
end

def update
raise Grid::EditorIntegration::Errors::InvalidConfig unless params["data"]
Grid::EditorIntegration::Utils.download_editor(params["data"])

render nothing: true
end

protected
def bad_request
render nothing: true, status: 422
end
end
end
end
@@ -0,0 +1,7 @@
module Grid
module EditorIntegration
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
end
end
end
9 changes: 9 additions & 0 deletions app/controllers/grid/editor_integration/config_controller.rb
@@ -0,0 +1,9 @@
module Grid
module EditorIntegration
class ConfigController < ApplicationController
include Grid::EditorIntegration::ApplicationHelper
include Grid::EditorIntegration::EditorConfig
include Grid::EditorIntegration::CheckToken
end
end
end
28 changes: 28 additions & 0 deletions app/controllers/grid/editor_integration/snippets_controller.rb
@@ -0,0 +1,28 @@
module Grid
module EditorIntegration
class SnippetsController < ApplicationController
include Grid::EditorIntegration::ApplicationHelper

def create
snippet_url = URI(Grid::EditorIntegration.snippet_url)
req_body = {
token: Grid::EditorIntegration.token,
theme_id: params[:themeId],
snippet: {
name: params[:name],
code: params[:code]
}
}

req = Net::HTTP::Post.new(snippet_url, 'Content-Type' => 'application/json')
req.body = req_body.to_json
res = Net::HTTP.start(
snippet_url.hostname,
snippet_url.port,
use_ssl: snippet_url.scheme == 'https') { |http| http.request(req) }

render text: res.body
end
end
end
end

0 comments on commit 34de266

Please sign in to comment.