rails_simplemde_editor 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.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/app/assets/javascripts/rails_simplemde.js +4 -0
- data/app/assets/stylesheets/rails_simplemde.css +3 -0
- data/app/controllers/simplemde/assets_controller.rb +13 -0
- data/app/uploaders/simplemde/asset_uploader.rb +47 -0
- data/app/uploaders/simplemde/image_uploader.rb +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/routes.rb +5 -0
- data/lib/generators/rails_simplemde_editor/install/USAGE +8 -0
- data/lib/generators/rails_simplemde_editor/install/install_generator.rb +26 -0
- data/lib/generators/rails_simplemde_editor/install/templates/application.css +16 -0
- data/lib/generators/rails_simplemde_editor/install/templates/application.js +17 -0
- data/lib/generators/rails_simplemde_editor/install/templates/load_simplemde.coffee +15 -0
- data/lib/generators/rails_simplemde_editor/migration/USAGE +10 -0
- data/lib/generators/rails_simplemde_editor/migration/migration_generator.rb +33 -0
- data/lib/generators/rails_simplemde_editor/migration/templates/migration/migration.rb +16 -0
- data/lib/generators/rails_simplemde_editor/migration/templates/models/active_record/simplemde/asset.rb +15 -0
- data/lib/generators/rails_simplemde_editor/migration/templates/models/active_record/simplemde/image.rb +3 -0
- data/lib/rails_simplemde_editor/active_record.rb +14 -0
- data/lib/rails_simplemde_editor/engine.rb +5 -0
- data/lib/rails_simplemde_editor/version.rb +3 -0
- data/lib/rails_simplemde_editor.rb +7 -0
- data/rails_simplemde_editor.gemspec +41 -0
- data/vendor/assets/javascripts/simplemde/codemirror.inline-attachment.js +91 -0
- data/vendor/assets/javascripts/simplemde/codemirror.min.js +9 -0
- data/vendor/assets/javascripts/simplemde/inline-attachment.min.js +2 -0
- data/vendor/assets/javascripts/simplemde/simplemde.min.js +15 -0
- data/vendor/assets/stylesheets/simplemde/simplemde.min.css +7 -0
- metadata +164 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: edd2efb0f3475aac63637053b2d36da84e2c84a4d77596d8fc9501a7384b9411
|
|
4
|
+
data.tar.gz: 6d3f5fa196e9565cd6bf89359099038a614e8f2980e1c8d978a94694b3d97b39
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: cf4c09ee645ac3012c2c538d3443399e62a6b45fa26a003dbf0285ab888d141567c557878e6af012591dd35d9945371d8ae6302ce9ad3f732b4a275d9a34cf64
|
|
7
|
+
data.tar.gz: 9c4985d5eb118ef5801d93dafc85dd7c2fc2307489519c6911950238315e89a6744f4fe78d3972a1d4486b5c66d7a422ab6b7fad11f4acd377e79a2ff63c9554
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -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 njzhaoguobin@126.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,11 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
|
4
|
+
|
|
5
|
+
gem 'rails'
|
|
6
|
+
gem 'jquery-rails'
|
|
7
|
+
gem 'carrierwave'
|
|
8
|
+
gem 'mini_magick'
|
|
9
|
+
|
|
10
|
+
# Specify your gem's dependencies in rails_simplemde_editor.gemspec
|
|
11
|
+
gemspec
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 zhao
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# RailsSimplemdeEditor
|
|
2
|
+
|
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rails_simplemde_editor`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
+
|
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'rails_simplemde_editor'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install rails_simplemde_editor
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
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.
|
|
30
|
+
|
|
31
|
+
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).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rails_simplemde_editor. 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.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
40
|
+
|
|
41
|
+
## Code of Conduct
|
|
42
|
+
|
|
43
|
+
Everyone interacting in the RailsSimplemdeEditor project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rails_simplemde_editor/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class Simplemde::AssetsController < ApplicationController
|
|
2
|
+
def create
|
|
3
|
+
unless params[:file].blank?
|
|
4
|
+
@asset = Simplemde::Image.new(asset: params[:file], asset_type: :image) # TODO file
|
|
5
|
+
if params[:owner_id].present? && params[:owner_type].present?
|
|
6
|
+
@asset.owner_id = params[:owner_id]
|
|
7
|
+
@asset.owner_type = params[:owner_type]
|
|
8
|
+
end
|
|
9
|
+
@asset.save
|
|
10
|
+
return render json: {filename: @asset.asset.url}
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
class Simplemde::AssetUploader < CarrierWave::Uploader::Base
|
|
2
|
+
# Include RMagick or MiniMagick support:
|
|
3
|
+
# include CarrierWave::RMagick
|
|
4
|
+
include CarrierWave::MiniMagick
|
|
5
|
+
|
|
6
|
+
# Choose what kind of storage to use for this uploader:
|
|
7
|
+
storage :file
|
|
8
|
+
# storage :fog
|
|
9
|
+
|
|
10
|
+
# Override the directory where uploaded files will be stored.
|
|
11
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
|
12
|
+
def store_dir
|
|
13
|
+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
|
17
|
+
# def default_url(*args)
|
|
18
|
+
# # For Rails 3.1+ asset pipeline compatibility:
|
|
19
|
+
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
|
20
|
+
#
|
|
21
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
|
22
|
+
# end
|
|
23
|
+
|
|
24
|
+
# Process files as they are uploaded:
|
|
25
|
+
# process scale: [200, 300]
|
|
26
|
+
#
|
|
27
|
+
# def scale(width, height)
|
|
28
|
+
# # do something
|
|
29
|
+
# end
|
|
30
|
+
|
|
31
|
+
# Create different versions of your uploaded files:
|
|
32
|
+
# version :thumb do
|
|
33
|
+
# process resize_to_fit: [50, 50]
|
|
34
|
+
# end
|
|
35
|
+
|
|
36
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
|
37
|
+
# For images you might use something like this:
|
|
38
|
+
# def extension_whitelist
|
|
39
|
+
# %w(jpg jpeg gif png)
|
|
40
|
+
# end
|
|
41
|
+
|
|
42
|
+
# Override the filename of the uploaded files:
|
|
43
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
|
44
|
+
# def filename
|
|
45
|
+
# "something.jpg" if original_filename
|
|
46
|
+
# end
|
|
47
|
+
end
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "rails_simplemde_editor"
|
|
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
data/config/routes.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module RailsSimplemdeEditor
|
|
2
|
+
class InstallGenerator < Rails::Generators::Base
|
|
3
|
+
source_root File.expand_path('templates', __dir__)
|
|
4
|
+
desc "Install simplemde editor for your application."
|
|
5
|
+
|
|
6
|
+
def insert_or_copy_js_files
|
|
7
|
+
if File.exist?('app/assets/javascripts/application.js')
|
|
8
|
+
insert_into_file "app/assets/javascripts/application.js", "//= require jquery\n//= require rails_simplemde\n", before: "//= require_tree ."
|
|
9
|
+
else
|
|
10
|
+
copy_file "application.js", "app/assets/javascripts/application.js"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def insert_or_copy_css_files
|
|
15
|
+
if File.exist?('app/assets/stylesheets/application.css')
|
|
16
|
+
insert_into_file "app/assets/stylesheets/application.css", " *= require rails_simplemde\n", before: " *= require_tree ."
|
|
17
|
+
else
|
|
18
|
+
copy_file "application.css", "app/assets/stylesheets/application.css"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def copy_load_simplemde_coffeescript
|
|
23
|
+
template "load_simplemde.coffee", "app/assets/javascripts/load_simplemde.coffee"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
|
|
6
|
+
* vendor/assets/stylesheets directory can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
|
11
|
+
* It is generally better to create a new file per style scope.
|
|
12
|
+
*
|
|
13
|
+
*= require rails_simplemde
|
|
14
|
+
*= require_tree .
|
|
15
|
+
*= require_self
|
|
16
|
+
*/
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
2
|
+
// listed below.
|
|
3
|
+
//
|
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
|
|
5
|
+
// vendor/assets/javascripts directory can be referenced here using a relative path.
|
|
6
|
+
//
|
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
|
9
|
+
//
|
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
|
11
|
+
// about supported directives.
|
|
12
|
+
//
|
|
13
|
+
//= require rails-ujs
|
|
14
|
+
//= require turbolinks
|
|
15
|
+
//= require jquery
|
|
16
|
+
//= require rails_simplemde
|
|
17
|
+
//= require_tree .
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
$(document).on 'turbolinks:load', ->
|
|
2
|
+
inlineAttachmentConfig =
|
|
3
|
+
uploadUrl: '/simplemde/upload.json',
|
|
4
|
+
extraHeaders:
|
|
5
|
+
'X-CSRF-Token': $('meta[name=csrf-token]').attr("content")
|
|
6
|
+
|
|
7
|
+
$('.rails_simplemde').each ->
|
|
8
|
+
simplemde = new SimpleMDE({ element: this, forceSync: true })
|
|
9
|
+
configs =
|
|
10
|
+
extraParams:
|
|
11
|
+
owner_type: $(this).data('ownerType') || '',
|
|
12
|
+
owner_id: $(this).data('ownerId') || ''
|
|
13
|
+
|
|
14
|
+
configs = Object.assign(configs, inlineAttachmentConfig)
|
|
15
|
+
inlineAttachment.editors.codemirror4.attach(simplemde.codemirror, configs)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
Copy model, migration and uploader to your application.
|
|
3
|
+
|
|
4
|
+
Example:
|
|
5
|
+
rails generate rails_simplemde_editor:migration
|
|
6
|
+
|
|
7
|
+
This will create:
|
|
8
|
+
app/models/simplemde/asset.rb
|
|
9
|
+
app/models/simplemde/image.rb
|
|
10
|
+
db/migrate/xxxxxxxxx_create_simplemde_assets.rb
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module RailsSimplemdeEditor
|
|
2
|
+
class MigrationGenerator < Rails::Generators::Base
|
|
3
|
+
include Rails::Generators::Migration
|
|
4
|
+
source_root File.expand_path('templates', __dir__)
|
|
5
|
+
desc "Copy model and migration to your application."
|
|
6
|
+
class_option :orm, type: :string, aliases: "-o", default: "active_record", desc: "ORM options: active_record" # TODO mongoid
|
|
7
|
+
|
|
8
|
+
def copy_files
|
|
9
|
+
orm = options[:orm].to_s
|
|
10
|
+
orm = "active_record" unless %w{active_record}.include?(orm) # TODO mongoid
|
|
11
|
+
%w(asset image).each do |file| # TODO file, video?, music?
|
|
12
|
+
copy_model(orm, file)
|
|
13
|
+
end
|
|
14
|
+
if orm == "active_record"
|
|
15
|
+
migration_template "migration/migration.rb", "db/migrate/create_simplemde_assets.rb"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.next_migration_number(dirname)
|
|
20
|
+
if ActiveRecord::Base.timestamped_migrations
|
|
21
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
|
22
|
+
else
|
|
23
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def copy_model(orm, name)
|
|
30
|
+
template "models/#{orm}/simplemde/#{name}.rb", "app/models/simplemde/#{name}.rb"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class CreateSimplemdeAssets < ActiveRecord::Migration[5.0]
|
|
2
|
+
def change
|
|
3
|
+
create_table :simplemde_assets do |t|
|
|
4
|
+
t.string :asset
|
|
5
|
+
t.integer :file_size
|
|
6
|
+
t.string :file_type
|
|
7
|
+
t.integer :owner_id
|
|
8
|
+
t.string :owner_type
|
|
9
|
+
t.string :asset_type
|
|
10
|
+
|
|
11
|
+
t.timestamps
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class Simplemde::Asset < ApplicationRecord
|
|
2
|
+
self.table_name = 'simplemde_assets'
|
|
3
|
+
mount_uploader :asset, Simplemde::AssetUploader
|
|
4
|
+
validates :asset, presence: true
|
|
5
|
+
before_save :update_asset_attributes
|
|
6
|
+
|
|
7
|
+
private
|
|
8
|
+
|
|
9
|
+
def update_asset_attributes
|
|
10
|
+
if asset.present? && asset_changed?
|
|
11
|
+
self.file_size = asset.file.size
|
|
12
|
+
self.file_type = asset.file.content_type
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
if defined?(ActiveRecord)
|
|
2
|
+
ActiveRecord::Base.class_eval do
|
|
3
|
+
def self.has_many_simplemde_assets(*args)
|
|
4
|
+
options = args.extract_options!
|
|
5
|
+
asset_name = args[0] ? args[0].to_s : 'assets'
|
|
6
|
+
has_many asset_name.to_sym, class_name: 'Simplemde::Asset', as: :owner, dependent: options[:dependent]
|
|
7
|
+
|
|
8
|
+
Simplemde::Asset.class_eval do
|
|
9
|
+
belongs_to :owner, polymorphic: true, optional: true
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "rails_simplemde_editor/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "rails_simplemde_editor"
|
|
8
|
+
spec.version = RailsSimplemdeEditor::VERSION
|
|
9
|
+
spec.authors = ["zhao"]
|
|
10
|
+
spec.email = ["njzhaoguobin@126.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{SimpleMDE markdown editor for rails.}
|
|
13
|
+
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
|
14
|
+
spec.homepage = "https://github.com/zhaoguobin/rails_simplemde_editor"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
19
|
+
# if spec.respond_to?(:metadata)
|
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
|
21
|
+
# else
|
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
|
23
|
+
# "public gem pushes."
|
|
24
|
+
# end
|
|
25
|
+
|
|
26
|
+
# Specify which files should be added to the gem when it is released.
|
|
27
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
28
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
29
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
30
|
+
end
|
|
31
|
+
spec.bindir = "exe"
|
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
33
|
+
spec.require_paths = ["lib"]
|
|
34
|
+
|
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
38
|
+
spec.add_dependency "jquery-rails", "~> 4.0"
|
|
39
|
+
spec.add_dependency "carrierwave", "~> 1.0"
|
|
40
|
+
spec.add_dependency "mini_magick", "~> 4.0"
|
|
41
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/*jslint newcap: true */
|
|
2
|
+
/*global inlineAttachment: false */
|
|
3
|
+
/**
|
|
4
|
+
* CodeMirror version for inlineAttachment
|
|
5
|
+
*
|
|
6
|
+
* Call inlineAttachment.attach(editor) to attach to a codemirror instance
|
|
7
|
+
*/
|
|
8
|
+
(function() {
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
var codeMirrorEditor = function(instance) {
|
|
12
|
+
|
|
13
|
+
if (!instance.getWrapperElement) {
|
|
14
|
+
throw "Invalid CodeMirror object given";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
this.codeMirror = instance;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
codeMirrorEditor.prototype.getValue = function() {
|
|
21
|
+
return this.codeMirror.getValue();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
codeMirrorEditor.prototype.insertValue = function(val) {
|
|
25
|
+
this.codeMirror.replaceSelection(val);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
codeMirrorEditor.prototype.setValue = function(val) {
|
|
29
|
+
var cursor = this.codeMirror.getCursor();
|
|
30
|
+
this.codeMirror.setValue(val);
|
|
31
|
+
this.codeMirror.setCursor(cursor);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Attach InlineAttachment to CodeMirror
|
|
36
|
+
*
|
|
37
|
+
* @param {CodeMirror} codeMirror
|
|
38
|
+
*/
|
|
39
|
+
codeMirrorEditor.attach = function(codeMirror, options) {
|
|
40
|
+
|
|
41
|
+
options = options || {};
|
|
42
|
+
|
|
43
|
+
var editor = new codeMirrorEditor(codeMirror),
|
|
44
|
+
inlineattach = new inlineAttachment(options, editor),
|
|
45
|
+
el = codeMirror.getWrapperElement();
|
|
46
|
+
|
|
47
|
+
el.addEventListener('paste', function(e) {
|
|
48
|
+
inlineattach.onPaste(e);
|
|
49
|
+
}, false);
|
|
50
|
+
|
|
51
|
+
codeMirror.setOption('onDragEvent', function(data, e) {
|
|
52
|
+
if (e.type === "drop") {
|
|
53
|
+
e.stopPropagation();
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
return inlineattach.onDrop(e);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
inlineAttachment.editors.codemirror3 = codeMirrorEditor;
|
|
61
|
+
|
|
62
|
+
var codeMirrorEditor4 = function(instance) {
|
|
63
|
+
codeMirrorEditor.call(this, instance);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
codeMirrorEditor4.attach = function(codeMirror, options) {
|
|
67
|
+
|
|
68
|
+
options = options || {};
|
|
69
|
+
|
|
70
|
+
var editor = new codeMirrorEditor(codeMirror),
|
|
71
|
+
inlineattach = new inlineAttachment(options, editor),
|
|
72
|
+
el = codeMirror.getWrapperElement();
|
|
73
|
+
|
|
74
|
+
el.addEventListener('paste', function(e) {
|
|
75
|
+
inlineattach.onPaste(e);
|
|
76
|
+
}, false);
|
|
77
|
+
|
|
78
|
+
codeMirror.on('drop', function(data, e) {
|
|
79
|
+
if (inlineattach.onDrop(e)) {
|
|
80
|
+
e.stopPropagation();
|
|
81
|
+
e.preventDefault();
|
|
82
|
+
return true;
|
|
83
|
+
} else {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
inlineAttachment.editors.codemirror4 = codeMirrorEditor4;
|
|
90
|
+
|
|
91
|
+
})();
|