bootsy_full_html 2.2.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.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +159 -0
  4. data/Rakefile +35 -0
  5. data/app/assets/images/bootsy/gallery-loader.gif +0 -0
  6. data/app/assets/images/bootsy/upload-loader.gif +0 -0
  7. data/app/assets/javascripts/bootsy.js +11 -0
  8. data/app/assets/javascripts/bootsy/area.js +89 -0
  9. data/app/assets/javascripts/bootsy/editor_options.js +47 -0
  10. data/app/assets/javascripts/bootsy/image_template.js +11 -0
  11. data/app/assets/javascripts/bootsy/init.js +38 -0
  12. data/app/assets/javascripts/bootsy/locales/en.js +54 -0
  13. data/app/assets/javascripts/bootsy/locales/pt-BR.js +54 -0
  14. data/app/assets/javascripts/bootsy/modal.js +192 -0
  15. data/app/assets/javascripts/bootsy/vendor/bootstrap-wysihtml5.js +530 -0
  16. data/app/assets/javascripts/bootsy/vendor/bootstrap.file-input.js +122 -0
  17. data/app/assets/javascripts/bootsy/vendor/polyfill.js +29 -0
  18. data/app/assets/javascripts/bootsy/vendor/wysihtml5.js +9565 -0
  19. data/app/assets/stylesheets/bootsy.css +337 -0
  20. data/app/controllers/bootsy/application_controller.rb +7 -0
  21. data/app/controllers/bootsy/images_controller.rb +96 -0
  22. data/app/helpers/bootsy/application_helper.rb +13 -0
  23. data/app/uploaders/bootsy/image_uploader.rb +39 -0
  24. data/app/views/bootsy/images/_image.html.erb +43 -0
  25. data/app/views/bootsy/images/_modal.html.erb +29 -0
  26. data/app/views/bootsy/images/_new.html.erb +17 -0
  27. data/config/locales/bootsy.en.yml +30 -0
  28. data/config/locales/bootsy.pt-BR.yml +30 -0
  29. data/config/routes.rb +11 -0
  30. data/db/migrate/20120624171333_create_bootsy_images.rb +9 -0
  31. data/db/migrate/20120628124845_create_bootsy_image_galleries.rb +8 -0
  32. data/lib/bootsy.rb +68 -0
  33. data/lib/bootsy/activerecord/image.rb +12 -0
  34. data/lib/bootsy/activerecord/image_gallery.rb +23 -0
  35. data/lib/bootsy/container.rb +52 -0
  36. data/lib/bootsy/core_ext.rb +4 -0
  37. data/lib/bootsy/engine.rb +34 -0
  38. data/lib/bootsy/form_builder.rb +18 -0
  39. data/lib/bootsy/form_helper.rb +114 -0
  40. data/lib/bootsy/simple_form/bootsy_input.rb +24 -0
  41. data/lib/bootsy/version.rb +4 -0
  42. data/lib/generators/bootsy/USAGE +12 -0
  43. data/lib/generators/bootsy/install_generator.rb +53 -0
  44. data/lib/generators/bootsy/templates/bootsy.rb +69 -0
  45. data/lib/tasks/bootsy_tasks.rake +4 -0
  46. metadata +130 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d54008bf7ba2ab2c7a7e1cd76cdcaaea4ec0a1b5
4
+ data.tar.gz: 8e1c822f62dba69e01c989a44f1eb8c2aec0a8b9
5
+ SHA512:
6
+ metadata.gz: d0919221ed31dc38b2464e16c8568d08a36ed4ad380d83b4b58688c257f2afca280164607b4f88dcbf5ba14b2db2cf92cbb32f6626ee50abe8d190c011f6b972
7
+ data.tar.gz: 89fc44025f80e59ba20e5413aaf3aacf1218ddffc264f2a745a93b14276db8551fb4227cc540fc1b307229e95ceac08a7c244340f01404909270a12a202a660d
@@ -0,0 +1,20 @@
1
+ Copyright 2012-2015 Volmer Soares
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.
@@ -0,0 +1,159 @@
1
+ # Bootsy
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/bootsy.png)](http://badge.fury.io/rb/bootsy)
4
+ [![Build Status](https://secure.travis-ci.org/volmer/bootsy.png?branch=master)](http://travis-ci.org/volmer/bootsy)
5
+ [![Dependency Status](https://gemnasium.com/volmer/bootsy.png)](https://gemnasium.com/volmer/bootsy)
6
+ [![Code Climate](https://codeclimate.com/github/volmer/bootsy.png)](https://codeclimate.com/github/volmer/bootsy)
7
+ [![Coverage Status](https://coveralls.io/repos/volmer/bootsy/badge.png?branch=master)](https://coveralls.io/r/volmer/bootsy)
8
+
9
+ *Bootsy* is a WYSIWYG editor for Rails based on
10
+ [Bootstrap-wysihtml5](https://github.com/jhollingworth/bootstrap-wysihtml5) with image uploads using
11
+ [CarrierWave](https://github.com/carrierwaveuploader/carrierwave).
12
+
13
+ ### Live demo
14
+
15
+ * [bootsy-demo.herokuapp.com](http://bootsy-demo.herokuapp.com/)
16
+ [![image](https://f.cloud.github.com/assets/301187/1365250/e1b7ba80-3854-11e3-9bfe-8bd1e090aca8.png)](http://bootsy-demo.herokuapp.com/)
17
+
18
+
19
+ ## Requirements
20
+
21
+ * ImageMagick or GraphicsMagick (for MiniMagick);
22
+ * Rails `4`;
23
+ * [Bootstrap `3`](http://getbootstrap.com/) fully installed in your app.
24
+
25
+
26
+ ## Installation
27
+
28
+ 1. Add Bootsy to your Gemfile:
29
+ ```ruby
30
+ gem 'bootsy'
31
+ ```
32
+
33
+ 2. Run the bundle command to install it:
34
+ ```console
35
+ bundle install
36
+ ```
37
+
38
+ 3. Run the install generator:
39
+ ```console
40
+ bundle exec rails generate bootsy:install
41
+ ```
42
+ It will include the javascripts and stylesheets in the assets pipeline,
43
+ create the `bootsy.rb` initializer and add a copy of the english translations.
44
+
45
+ **Note:** If your project uses SASS or LESS and `application.css` does not exist,
46
+ you will be required to require bootsy manually using `*= require bootsy` or if you prefer
47
+ to import assets yourself `@import "bootsy";`
48
+
49
+ 4. Add and run migrations:
50
+ ```console
51
+ bundle exec rake bootsy:install:migrations
52
+ bundle exec rake db:migrate
53
+ ```
54
+
55
+
56
+ ## Usage
57
+
58
+ Just call `bootsy_area` in your `FormBuilder` instances, the
59
+ same way you'd call `textarea`. Example:
60
+ ```erb
61
+ <%= form_for(@post) do |f| %>
62
+ <%= f.label :title %>
63
+ <%= f.text_field :title %>
64
+
65
+ <%= f.label :content %>
66
+ <%= f.bootsy_area :content %>
67
+
68
+ <%= f.submit %>
69
+ <% end %>
70
+ ```
71
+
72
+ Bootsy will group the uploaded images as galleries and associate them to one of
73
+ your models. For instance, if you have a `Post` model and you want to use `bootsy_area`
74
+ with it, you must include the `Bootsy::Container` module:
75
+ ```ruby
76
+ class Post < ActiveRecord::Base
77
+ include Bootsy::Container
78
+ end
79
+ ```
80
+
81
+ Don't forget to ensure the association between your model objects with Bootsy
82
+ image galleries. For `strong_parameters`, you must whitelist the `bootsy_image_gallery_id` parameter
83
+ in your controller:
84
+ ```ruby
85
+ private
86
+
87
+ def post_params
88
+ params.require(:post).permit(:title, :content, :bootsy_image_gallery_id)
89
+ end
90
+ ```
91
+
92
+
93
+ ## Bootsy with [Simple Form](https://github.com/plataformatec/simple_form) builders
94
+
95
+ You can use `bootsy` as an input type in `SimpleForm::FormBuilder` instances. Example:
96
+ ```erb
97
+ <%= simple_form_for @post do |f| %>
98
+ <%= f.input :title %>
99
+
100
+ <%= f.input :content, as: :bootsy %>
101
+
102
+ <%= f.button :submit %>
103
+ <% end %>
104
+ ```
105
+
106
+
107
+ ## Editor options
108
+
109
+ You can customize Bootsy through a hash of `editor_options`:
110
+
111
+
112
+ ### Enable/disable features
113
+
114
+ You can enable and disable features as you like. For instance, if you don't want link and color features:
115
+ ```erb
116
+ <%= f.bootsy_area :my_attribute, editor_options: { link: false, color: false } %>
117
+ ```
118
+ Available options are: `:blockquote`, `:font_styles`, `:emphasis`, `:lists`, `:html`, `:link`, `:image` and `:color`.
119
+
120
+
121
+ ### Alert of unsaved changes
122
+
123
+ By default Bootsy alerts the user about unsaved changes if the page is closed or reloaded. You can disable
124
+ this feature with:
125
+ ```erb
126
+ <%= f.bootsy_area :my_attribute, editor_options: { alert_unsaved: false } %>
127
+ ```
128
+
129
+ ## Uploads
130
+
131
+ If you don't want to have image uploads, just call `bootsy_area` in a form builder not
132
+ associated to a `Bootsy::Container` model. This way users will still be able to insert
133
+ images in the text area using an external image URL.
134
+
135
+
136
+ ## Configuration
137
+
138
+ You can set the default editor options, image sizes available (small, medium,
139
+ large and/or its original), dimensions and more. Take a look at Bootsy's initalizer
140
+ file `/config/initializers/bootsy.rb` in your app and feel free to uncomment and change
141
+ the options as you like.
142
+
143
+
144
+ ## I18n
145
+
146
+ Bootsy defines some I18n keys. English translations are added by default to your
147
+ `config/locales` directory as `bootsy.en.yml`. You can use it as a template
148
+ to translate Bootsy to your language.
149
+ [Here are some examples](https://github.com/volmer/bootsy/tree/master/config/locales).
150
+
151
+ You also need to translate Bootsy on the JavaScript side. Just follow
152
+ [this example](https://github.com/volmer/bootsy/blob/master/app/assets/javascripts/bootsy/locales/en.js).
153
+ Bootsy will try to guess the locale based on the `lang` attribute of the page's `<html>` tag.
154
+ You can set the locale directly by setting a `data-bootsy-locale` attribute on your `<textarea>`.
155
+
156
+
157
+ ## License
158
+
159
+ MIT License. Copyright 2012-2015 Volmer Soares
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Bootsy'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
25
+ require 'rspec/core/rake_task'
26
+ require 'coveralls/rake/task'
27
+ require 'rubocop/rake_task'
28
+
29
+ RuboCop::RakeTask.new(:rubocop) do |task|
30
+ task.patterns = ['app/**/*.rb', 'lib/**/*.rb']
31
+ end
32
+ Coveralls::RakeTask.new
33
+ RSpec::Core::RakeTask.new(:spec)
34
+
35
+ task default: [:rubocop, :spec, 'coveralls:push']
@@ -0,0 +1,11 @@
1
+ //= require jquery.remotipart
2
+ //= require bootsy/vendor/polyfill
3
+ //= require bootsy/vendor/wysihtml5
4
+ //= require bootsy/vendor/bootstrap-wysihtml5
5
+ //= require bootsy/vendor/bootstrap.file-input
6
+ //= require bootsy/area
7
+ //= require bootsy/editor_options
8
+ //= require bootsy/image_template
9
+ //= require bootsy/init
10
+ //= require bootsy/locales/en
11
+ //= require bootsy/modal
@@ -0,0 +1,89 @@
1
+ /* global Bootsy */
2
+
3
+ window.Bootsy = window.Bootsy || {};
4
+
5
+ Bootsy.Area = function($el) {
6
+ var self = this;
7
+
8
+ this.$el = $el;
9
+ this.unsavedChanges = false;
10
+ this.locale = $el.data('bootsy-locale') || $('html').attr('lang');
11
+ if (!$.fn.wysihtml5.locale.hasOwnProperty(this.locale)) this.locale = 'en';
12
+
13
+ this.options = {
14
+ locale: this.locale,
15
+ alertUnsavedChanges: $el.data('bootsy-alert-unsaved'),
16
+ uploader: $el.data('bootsy-uploader'),
17
+ color: $el.data('bootsy-color'),
18
+ emphasis: $el.data('bootsy-emphasis'),
19
+ 'font-styles': $el.data('bootsy-font-styles'),
20
+ html: $el.data('bootsy-html'),
21
+ image: $el.data('bootsy-image'),
22
+ link: $el.data('bootsy-link'),
23
+ lists: $el.data('bootsy-lists'),
24
+ events: {
25
+ change: function() {
26
+ self.unsavedChanges = true;
27
+ }
28
+ }
29
+ };
30
+ };
31
+
32
+ // Alert for unsaved changes
33
+ Bootsy.Area.prototype.unsavedChangesAlert = function () {
34
+ if (this.unsavedChanges) {
35
+ return $.fn.wysihtml5.locale[this.locale].bootsy.alertUnsaved;
36
+ }
37
+ };
38
+
39
+ // Clear everything
40
+ Bootsy.Area.prototype.clear = function () {
41
+ this.editor.clear();
42
+ this.setImageGalleryId('');
43
+ this.modal.$el.data('gallery-loaded', false);
44
+ };
45
+
46
+ Bootsy.Area.prototype.setImageGalleryId = function(id) {
47
+ this.$el.data('gallery-id', id);
48
+ this.$el.siblings('.bootsy_image_gallery_id').val(id);
49
+ };
50
+
51
+ // Init components
52
+ Bootsy.Area.prototype.init = function() {
53
+ if (!this.$el.data('bootsy-initialized')) {
54
+ if ((this.options.image === true) && (this.options.uploader === true)) {
55
+ this.modal = new Bootsy.Modal(this);
56
+ this.options.image = false;
57
+ this.options.customCommand = true;
58
+ this.options.customCommandCallback = this.modal.show.bind(this.modal);
59
+ this.options.customTemplates = { customCommand: Bootsy.imageTemplate };
60
+ }
61
+
62
+ this.editor = this.$el.wysihtml5($.extend(true, {}, Bootsy.options, this.options)).data('wysihtml5').editor;
63
+
64
+ // Mechanism for unsaved changes alert
65
+ if (this.options.alertUnsavedChanges !== false) {
66
+ window.onbeforeunload = this.unsavedChangesAlert.bind(this);
67
+ }
68
+
69
+ this.$el.closest('form').submit(function() {
70
+ this.unsavedChanges = false;
71
+
72
+ return true;
73
+ }.bind(this));
74
+
75
+ this.$el.data('bootsy-initialized', true);
76
+ }
77
+ };
78
+
79
+ // Insert image in the text
80
+ Bootsy.Area.prototype.insertImage = function(image) {
81
+ this.editor.currentView.element.focus();
82
+
83
+ if (this.caretBookmark) {
84
+ this.editor.composer.selection.setBookmark(this.caretBookmark);
85
+ this.caretBookmark = null;
86
+ }
87
+
88
+ this.editor.composer.commands.exec('insertImage', image);
89
+ };
@@ -0,0 +1,47 @@
1
+ window.Bootsy = window.Bootsy || {};
2
+
3
+ var pageStylesheets = [];
4
+ $('link[rel="stylesheet"]').each(function () {
5
+ pageStylesheets.push($(this).attr('href'));
6
+ });
7
+
8
+ window.Bootsy.options = {};
9
+
10
+ $.extend(true, window.Bootsy.options, $.fn.wysihtml5.defaultOptions, {
11
+ parserRules: {
12
+ classes: {
13
+ "wysiwyg-float-left": 1,
14
+ "wysiwyg-float-right": 1,
15
+ "wysiwyg-float-inline": 1
16
+ },
17
+ tags: {
18
+ "cite": {
19
+ "check_attributes": {
20
+ "title": "alt"
21
+ }
22
+ },
23
+ "img": {
24
+ "check_attributes": {
25
+ "src": "src"
26
+ },
27
+ "add_class": {
28
+ "align": "align_img"
29
+ }
30
+ },
31
+ // this allows youtube embed codes
32
+ "iframe": {
33
+ set_attributes: {
34
+ "frameborder": "0",
35
+ "allowfullscreen": "1"
36
+ },
37
+ check_attributes: {
38
+ "width": "numbers",
39
+ "height": "numbers",
40
+ "src": "href"
41
+ }
42
+ }
43
+ }
44
+ },
45
+ color: true,
46
+ stylesheets: pageStylesheets
47
+ });
@@ -0,0 +1,11 @@
1
+ window.Bootsy = window.Bootsy || {};
2
+
3
+ window.Bootsy.imageTemplate = function(locale, options) {
4
+ var size = (options && options.size) ? ' btn-' + options.size : '';
5
+
6
+ return '<li>' +
7
+ '<a class="btn btn-default ' + size + '" data-wysihtml5-command="customCommand" title="' + locale.image.insert + '" tabindex="-1">' +
8
+ '<span class="glyphicon glyphicon-picture"></span>' +
9
+ '</a>' +
10
+ '</li>';
11
+ };
@@ -0,0 +1,38 @@
1
+ /* global Bootsy */
2
+ window.Bootsy = window.Bootsy || {};
3
+
4
+ // Public: Intialize Bootsy editors in all visible `textarea`
5
+ // elements that has the `bootsy_text_area` class.
6
+ Bootsy.init = function() {
7
+ if (!Bootsy.areas) {
8
+ Bootsy.areas = {};
9
+ }
10
+
11
+ $('textarea.bootsy_text_area').each(function(index) {
12
+ if (!$(this).data('bootsy-initialized')) {
13
+ var area = new Bootsy.Area($(this));
14
+ var areaIdx = $(this).attr('id') || index;
15
+
16
+ /* There's always people who let elements share ids */
17
+ if(Bootsy.areas[areaIdx] !== undefined) {
18
+ areaIdx = $(this).attr('id') + index;
19
+ }
20
+
21
+ area.init();
22
+
23
+ Bootsy.areas[areaIdx] = area;
24
+ }
25
+ });
26
+ };
27
+
28
+ /* Initialize Bootsy on document load */
29
+ $(function() {
30
+ $(window).load(function() {
31
+ Bootsy.init();
32
+
33
+ /* Reload Bootsy on page load when using Turbolinks. */
34
+ if (window.Turbolinks) {
35
+ $(document).on('page:load', Bootsy.init);
36
+ }
37
+ });
38
+ });
@@ -0,0 +1,54 @@
1
+ /**
2
+ * English translations for bootstrap-wysihtml5 and Bootsy
3
+ */
4
+ (function($){
5
+ $.fn.wysihtml5.locale['en'] = {
6
+ font_styles: {
7
+ normal: 'Normal text',
8
+ h1: 'Heading 1',
9
+ h2: 'Heading 2',
10
+ h3: 'Heading 3'
11
+ },
12
+ emphasis: {
13
+ bold: 'Bold',
14
+ italic: 'Italic',
15
+ underline: 'Underline',
16
+ small: 'Small'
17
+ },
18
+ lists: {
19
+ unordered: 'Unordered list',
20
+ ordered: 'Ordered list',
21
+ outdent: 'Outdent',
22
+ indent: 'Indent'
23
+ },
24
+ link: {
25
+ insert: 'Insert link',
26
+ cancel: 'Cancel',
27
+ target: 'Open link in new window'
28
+ },
29
+ image: {
30
+ insert: 'Insert image',
31
+ cancel: 'Cancel'
32
+ },
33
+ html: {
34
+ edit: 'Edit HTML'
35
+ },
36
+ colours: {
37
+ black: 'Black',
38
+ silver: 'Silver',
39
+ gray: 'Grey',
40
+ maroon: 'Maroon',
41
+ red: 'Red',
42
+ purple: 'Purple',
43
+ green: 'Green',
44
+ olive: 'Olive',
45
+ navy: 'Navy',
46
+ blue: 'Blue',
47
+ orange: 'Orange'
48
+ },
49
+ bootsy: {
50
+ alertUnsaved: 'You have unsaved changes.',
51
+ error: 'Something went wrong. Please try again later.'
52
+ }
53
+ };
54
+ }(jQuery));