wangeditor_rails 0.1.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: 06cc74c13d8db55716e2d656feccbecdc39c331f
4
+ data.tar.gz: 284df17541a238a99ca1c0d1e0dc6a31406b68c2
5
+ SHA512:
6
+ metadata.gz: 2c80f94aad64ef543fe1fe00ff9b78f1a10d30e47531508ef6a309167b667c8c7682320db10e935e45b5c127ea4c616f7040dc0a7684558075951e13d1d4be63
7
+ data.tar.gz: e721de9b2aceb85a9dc93c5fd762a89363a9ba5ba7fa4e5dd470a3c7e1f0acdc0aecc3b73f1e0c50b840a1adbc9225bafb119ea9b82361e4746f299685578b45
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Tian Ting
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,51 @@
1
+ # wangeditor_rails
2
+ >wangEditor —— 轻量级 web 富文本编辑器,配置方便,使用简单。支持 IE10+ 浏览器。
3
+
4
+
5
+ ## Features
6
+ * 提供[wangeditor](https://github.com/wangfupeng1988/wangEditor)(3.0.10)Rails集成
7
+ * 支持SimpleForm
8
+
9
+ ## Install
10
+ 1. Add to Gemfile then run 'bundle'
11
+ ```
12
+ gem 'wangeditor_rails'
13
+ ```
14
+
15
+ 2. Run install generator
16
+ ```
17
+ rails generate wangeditor_rails:install
18
+ ```
19
+
20
+ 3. Add below line to your application.js
21
+ ```
22
+ //= require wangEditor
23
+ ```
24
+
25
+ ## Usage:
26
+ ```
27
+ <%= form_for @post do |f| %>
28
+ <%= f.text_field :title %>
29
+ <%= f.wangeditor :body %>
30
+ <%= f.submit %>
31
+ <% end %>
32
+ ```
33
+
34
+ ### with SimpleForm
35
+ ```
36
+ <%= simple_form_for @post do |f| %>
37
+ <%= f.input :title %>
38
+ <%= f.input :body, as: :wangeditor %>
39
+ <%= f.button :submit %>
40
+ <% end %>
41
+ ```
42
+
43
+ ## Todo
44
+ - [ ] 七牛上传图片
45
+
46
+ # Thanks
47
+ * [rails_wangeditor](https://github.com/a598799539/rails_wangeditor)
48
+ * [ckeditor](https://github.com/galetahub/ckeditor)
49
+
50
+ ## License
51
+ MIT License.
data/Rakefile ADDED
@@ -0,0 +1,33 @@
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 = 'WangeditorRails'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+
33
+ task default: :test
@@ -0,0 +1,12 @@
1
+ module Wangeditor
2
+ class InstallGenerator < Rails::Generators::Base
3
+ JAVASCRIPTS_FILE = "app/assets/javascripts/wangEditor.js"
4
+
5
+ source_root File.expand_path("../../../../../", __FILE__)
6
+
7
+ def copy_javascripts
8
+ copy_file 'node_modules/wangeditor/release/wangEditor.js', JAVASCRIPTS_FILE
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :wangeditor_rails do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,18 @@
1
+ require "wangeditor_rails"
2
+ require "rails"
3
+
4
+ module WangeditorRails
5
+ class Engine < Rails::Engine
6
+
7
+ initializer "wangeditor_rails.helper_and_builder" do
8
+ ActiveSupport.on_load :action_view do
9
+ ActionView::Base.send(:include, WangeditorRails::Helper)
10
+ ActionView::Helpers::FormBuilder.send(:include, WangeditorRails::Builder)
11
+ end
12
+ end
13
+
14
+ initializer "wangeditor_rails.simple_form" do
15
+ require "wangeditor_rails/simple_form" if Object.const_defined?("SimpleForm")
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,41 @@
1
+ module WangeditorRails
2
+ module Helper
3
+ def wangeditor(name, method, options = {})
4
+ content = options[:object][method]
5
+ id = options[:id] || "#{name}_#{method}"
6
+ name = "#{name}[#{method}]"
7
+ #puts options
8
+
9
+ output_buffer = ActiveSupport::SafeBuffer.new
10
+ output_buffer << hidden_area(id, content, name)
11
+ output_buffer << display_area(id, content)
12
+ output_buffer << javascript_tag(create_scripts(id))
13
+ end
14
+
15
+ def hidden_area(id, content, name)
16
+ content_tag :div, text_area_tag(id, content, name: name), style: 'display: none;'
17
+ end
18
+
19
+ def display_area(id, content)
20
+ unless content.nil?
21
+ content = sanitize content
22
+ end
23
+ content_tag(:div, content, id: "#{id}_editor")
24
+ end
25
+
26
+ def create_scripts(id)
27
+ "var E = window.wangEditor
28
+ var editor = new E('##{id}_editor')
29
+ editor.customConfig.onchange = function (content) {
30
+ document.getElementById('#{id}').value = content
31
+ }
32
+ editor.create()"
33
+ end
34
+ end
35
+
36
+ module Builder
37
+ def wangeditor(method, options = {})
38
+ @template.send("wangeditor", @object_name, method, objectify_options(options))
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,11 @@
1
+ module WangeditorRails
2
+ module SimpleForm
3
+ class WangeditorInput < ::SimpleForm::Inputs::Base
4
+ def input(wrapper_options)
5
+ @builder.wangeditor(attribute_name, input_html_options)
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
+ ::SimpleForm::FormBuilder.map_type :wangeditor, :to => WangeditorRails::SimpleForm::WangeditorInput
@@ -0,0 +1,3 @@
1
+ module WangeditorRails
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'wangeditor_rails/engine'
2
+ require 'wangeditor_rails/helper'
3
+
4
+ module WangeditorRails
5
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wangeditor_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tian Ting
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simple_form
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Add wangEditor V3 edition, and costumize input components for form &
56
+ SimpleForm.
57
+ email:
58
+ - imtinge@163.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - MIT-LICENSE
64
+ - README.md
65
+ - Rakefile
66
+ - lib/generators/wangeditor/install/install_generator.rb
67
+ - lib/tasks/wangeditor_rails_tasks.rake
68
+ - lib/wangeditor_rails.rb
69
+ - lib/wangeditor_rails/engine.rb
70
+ - lib/wangeditor_rails/helper.rb
71
+ - lib/wangeditor_rails/simple_form.rb
72
+ - lib/wangeditor_rails/version.rb
73
+ homepage: https://github.com/imtinge/wangeditor_rails
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.6.11
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: wangEditor for Rails.
97
+ test_files: []