vapid 0.1.0
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 +10 -0
- data/.gitmodules +6 -0
- data/.rspec +2 -0
- data/.rubocop.yml +133 -0
- data/.travis.yml +5 -0
- data/Gemfile +10 -0
- data/README.md +37 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/vapid +7 -0
- data/lib/vapid.rb +24 -0
- data/lib/vapid/assets/javascripts/vapid/admin.coffee +2 -0
- data/lib/vapid/assets/stylesheets/vapid/admin.scss +72 -0
- data/lib/vapid/builder.rb +70 -0
- data/lib/vapid/cli.rb +96 -0
- data/lib/vapid/controllers/admin_controller.rb +282 -0
- data/lib/vapid/controllers/project_controller.rb +41 -0
- data/lib/vapid/db/migrate/20170202182310_create_groups.rb +12 -0
- data/lib/vapid/db/migrate/20170202183017_create_records.rb +11 -0
- data/lib/vapid/db/migrate/20170202185150_create_users.rb +11 -0
- data/lib/vapid/directive.rb +168 -0
- data/lib/vapid/directives.rb +30 -0
- data/lib/vapid/directives/audio.rb +27 -0
- data/lib/vapid/directives/group.rb +71 -0
- data/lib/vapid/directives/hide.rb +11 -0
- data/lib/vapid/directives/href.rb +11 -0
- data/lib/vapid/directives/image.rb +14 -0
- data/lib/vapid/directives/richtext.rb +15 -0
- data/lib/vapid/directives/show.rb +11 -0
- data/lib/vapid/directives/text.rb +24 -0
- data/lib/vapid/directives/video.rb +28 -0
- data/lib/vapid/generator_template/.gitignore +21 -0
- data/lib/vapid/generator_template/Gemfile.tt +13 -0
- data/lib/vapid/generator_template/README.md +0 -0
- data/lib/vapid/generator_template/assets/favicon.ico +0 -0
- data/lib/vapid/generator_template/assets/images/.keep +0 -0
- data/lib/vapid/generator_template/assets/javascripts/.keep +0 -0
- data/lib/vapid/generator_template/assets/stylesheets/.keep +0 -0
- data/lib/vapid/generator_template/assets/stylesheets/application.css +120 -0
- data/lib/vapid/generator_template/config.ru +3 -0
- data/lib/vapid/generator_template/config/database.yml +12 -0
- data/lib/vapid/generator_template/config/settings.yml.tt +11 -0
- data/lib/vapid/generator_template/templates/index.html.erb +25 -0
- data/lib/vapid/generator_template/templates/layouts/default.html.erb +22 -0
- data/lib/vapid/models.rb +18 -0
- data/lib/vapid/models/group.rb +36 -0
- data/lib/vapid/models/record.rb +30 -0
- data/lib/vapid/models/user.rb +16 -0
- data/lib/vapid/server.rb +93 -0
- data/lib/vapid/settings.rb +13 -0
- data/lib/vapid/template.rb +79 -0
- data/lib/vapid/template/node.rb +91 -0
- data/lib/vapid/template/parser.rb +50 -0
- data/lib/vapid/vendor/semantic-ui/.versions +4 -0
- data/lib/vapid/vendor/semantic-ui/LICENSE +22 -0
- data/lib/vapid/vendor/semantic-ui/README.md +7 -0
- data/lib/vapid/vendor/semantic-ui/components/accordion.css +252 -0
- data/lib/vapid/vendor/semantic-ui/components/accordion.js +610 -0
- data/lib/vapid/vendor/semantic-ui/components/accordion.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/accordion.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/ad.css +275 -0
- data/lib/vapid/vendor/semantic-ui/components/ad.min.css +10 -0
- data/lib/vapid/vendor/semantic-ui/components/api.js +1167 -0
- data/lib/vapid/vendor/semantic-ui/components/api.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/breadcrumb.css +124 -0
- data/lib/vapid/vendor/semantic-ui/components/breadcrumb.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/button.css +3450 -0
- data/lib/vapid/vendor/semantic-ui/components/button.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/card.css +964 -0
- data/lib/vapid/vendor/semantic-ui/components/card.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/checkbox.css +625 -0
- data/lib/vapid/vendor/semantic-ui/components/checkbox.js +831 -0
- data/lib/vapid/vendor/semantic-ui/components/checkbox.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/checkbox.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/colorize.js +274 -0
- data/lib/vapid/vendor/semantic-ui/components/colorize.min.js +11 -0
- data/lib/vapid/vendor/semantic-ui/components/comment.css +270 -0
- data/lib/vapid/vendor/semantic-ui/components/comment.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/container.css +147 -0
- data/lib/vapid/vendor/semantic-ui/components/container.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/dimmer.css +200 -0
- data/lib/vapid/vendor/semantic-ui/components/dimmer.js +708 -0
- data/lib/vapid/vendor/semantic-ui/components/dimmer.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/dimmer.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/divider.css +260 -0
- data/lib/vapid/vendor/semantic-ui/components/divider.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/dropdown.css +1442 -0
- data/lib/vapid/vendor/semantic-ui/components/dropdown.js +3767 -0
- data/lib/vapid/vendor/semantic-ui/components/dropdown.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/dropdown.min.js +11 -0
- data/lib/vapid/vendor/semantic-ui/components/embed.css +166 -0
- data/lib/vapid/vendor/semantic-ui/components/embed.js +696 -0
- data/lib/vapid/vendor/semantic-ui/components/embed.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/embed.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/feed.css +296 -0
- data/lib/vapid/vendor/semantic-ui/components/feed.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/flag.css +1031 -0
- data/lib/vapid/vendor/semantic-ui/components/flag.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/form.css +1067 -0
- data/lib/vapid/vendor/semantic-ui/components/form.js +1603 -0
- data/lib/vapid/vendor/semantic-ui/components/form.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/form.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/grid.css +2002 -0
- data/lib/vapid/vendor/semantic-ui/components/grid.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/header.css +721 -0
- data/lib/vapid/vendor/semantic-ui/components/header.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/icon.css +3292 -0
- data/lib/vapid/vendor/semantic-ui/components/icon.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/image.css +306 -0
- data/lib/vapid/vendor/semantic-ui/components/image.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/input.css +510 -0
- data/lib/vapid/vendor/semantic-ui/components/input.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/item.css +486 -0
- data/lib/vapid/vendor/semantic-ui/components/item.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/label.css +1307 -0
- data/lib/vapid/vendor/semantic-ui/components/label.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/list.css +951 -0
- data/lib/vapid/vendor/semantic-ui/components/list.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/loader.css +347 -0
- data/lib/vapid/vendor/semantic-ui/components/loader.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/menu.css +2002 -0
- data/lib/vapid/vendor/semantic-ui/components/menu.min.css +1 -0
- data/lib/vapid/vendor/semantic-ui/components/message.css +477 -0
- data/lib/vapid/vendor/semantic-ui/components/message.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/modal.css +502 -0
- data/lib/vapid/vendor/semantic-ui/components/modal.js +913 -0
- data/lib/vapid/vendor/semantic-ui/components/modal.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/modal.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/nag.css +147 -0
- data/lib/vapid/vendor/semantic-ui/components/nag.js +507 -0
- data/lib/vapid/vendor/semantic-ui/components/nag.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/nag.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/popup.css +733 -0
- data/lib/vapid/vendor/semantic-ui/components/popup.js +1475 -0
- data/lib/vapid/vendor/semantic-ui/components/popup.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/popup.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/progress.css +516 -0
- data/lib/vapid/vendor/semantic-ui/components/progress.js +931 -0
- data/lib/vapid/vendor/semantic-ui/components/progress.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/progress.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/rail.css +152 -0
- data/lib/vapid/vendor/semantic-ui/components/rail.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/rating.css +263 -0
- data/lib/vapid/vendor/semantic-ui/components/rating.js +508 -0
- data/lib/vapid/vendor/semantic-ui/components/rating.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/rating.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/reset.css +424 -0
- data/lib/vapid/vendor/semantic-ui/components/reset.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/reveal.css +284 -0
- data/lib/vapid/vendor/semantic-ui/components/reveal.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/search.css +408 -0
- data/lib/vapid/vendor/semantic-ui/components/search.js +1442 -0
- data/lib/vapid/vendor/semantic-ui/components/search.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/search.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/segment.css +798 -0
- data/lib/vapid/vendor/semantic-ui/components/segment.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/shape.css +157 -0
- data/lib/vapid/vendor/semantic-ui/components/shape.js +921 -0
- data/lib/vapid/vendor/semantic-ui/components/shape.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/shape.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/sidebar.css +634 -0
- data/lib/vapid/vendor/semantic-ui/components/sidebar.js +1036 -0
- data/lib/vapid/vendor/semantic-ui/components/sidebar.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/sidebar.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/site.css +160 -0
- data/lib/vapid/vendor/semantic-ui/components/site.js +487 -0
- data/lib/vapid/vendor/semantic-ui/components/site.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/site.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/state.js +708 -0
- data/lib/vapid/vendor/semantic-ui/components/state.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/statistic.css +569 -0
- data/lib/vapid/vendor/semantic-ui/components/statistic.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/step.css +623 -0
- data/lib/vapid/vendor/semantic-ui/components/step.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/sticky.css +78 -0
- data/lib/vapid/vendor/semantic-ui/components/sticky.js +942 -0
- data/lib/vapid/vendor/semantic-ui/components/sticky.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/sticky.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/tab.css +91 -0
- data/lib/vapid/vendor/semantic-ui/components/tab.js +952 -0
- data/lib/vapid/vendor/semantic-ui/components/tab.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/tab.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/table.css +1108 -0
- data/lib/vapid/vendor/semantic-ui/components/table.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/transition.css +1964 -0
- data/lib/vapid/vendor/semantic-ui/components/transition.js +1095 -0
- data/lib/vapid/vendor/semantic-ui/components/transition.min.css +9 -0
- data/lib/vapid/vendor/semantic-ui/components/transition.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/video.css +125 -0
- data/lib/vapid/vendor/semantic-ui/components/video.js +532 -0
- data/lib/vapid/vendor/semantic-ui/components/video.min.css +10 -0
- data/lib/vapid/vendor/semantic-ui/components/video.min.js +11 -0
- data/lib/vapid/vendor/semantic-ui/components/visibility.js +1288 -0
- data/lib/vapid/vendor/semantic-ui/components/visibility.min.js +10 -0
- data/lib/vapid/vendor/semantic-ui/components/visit.js +517 -0
- data/lib/vapid/vendor/semantic-ui/components/visit.min.js +11 -0
- data/lib/vapid/vendor/semantic-ui/package.js +34 -0
- data/lib/vapid/vendor/semantic-ui/package.json +20 -0
- data/lib/vapid/vendor/semantic-ui/semantic.css +36844 -0
- data/lib/vapid/vendor/semantic-ui/semantic.js +22617 -0
- data/lib/vapid/vendor/semantic-ui/semantic.min.css +364 -0
- data/lib/vapid/vendor/semantic-ui/semantic.min.js +19 -0
- data/lib/vapid/vendor/semantic-ui/themes/default/assets/fonts/icons.eot +0 -0
- data/lib/vapid/vendor/semantic-ui/themes/default/assets/fonts/icons.otf +0 -0
- data/lib/vapid/vendor/semantic-ui/themes/default/assets/fonts/icons.svg +2671 -0
- data/lib/vapid/vendor/semantic-ui/themes/default/assets/fonts/icons.ttf +0 -0
- data/lib/vapid/vendor/semantic-ui/themes/default/assets/fonts/icons.woff +0 -0
- data/lib/vapid/vendor/semantic-ui/themes/default/assets/fonts/icons.woff2 +0 -0
- data/lib/vapid/vendor/semantic-ui/themes/default/assets/images/flags.png +0 -0
- data/lib/vapid/vendor/trix/.blade.yml +45 -0
- data/lib/vapid/vendor/trix/.github/ISSUE_TEMPLATE.md +13 -0
- data/lib/vapid/vendor/trix/.gitignore +3 -0
- data/lib/vapid/vendor/trix/.ruby-version +1 -0
- data/lib/vapid/vendor/trix/.travis.yml +6 -0
- data/lib/vapid/vendor/trix/CONDUCT.md +79 -0
- data/lib/vapid/vendor/trix/Gemfile +17 -0
- data/lib/vapid/vendor/trix/Gemfile.lock +152 -0
- data/lib/vapid/vendor/trix/LICENSE +20 -0
- data/lib/vapid/vendor/trix/README.md +382 -0
- data/lib/vapid/vendor/trix/assets/index.html +55 -0
- data/lib/vapid/vendor/trix/assets/trix-core.coffee +2 -0
- data/lib/vapid/vendor/trix/assets/trix.coffee +3 -0
- data/lib/vapid/vendor/trix/assets/trix.scss +5 -0
- data/lib/vapid/vendor/trix/assets/trix/banner/index.coffee.erb +3 -0
- data/lib/vapid/vendor/trix/assets/trix/banner/index.scss.erb +3 -0
- data/lib/vapid/vendor/trix/assets/trix/banner/index.txt.erb +3 -0
- data/lib/vapid/vendor/trix/assets/trix/images/README.md +6 -0
- data/lib/vapid/vendor/trix/assets/trix/images/attach.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/bold.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/bullets.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/code.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/heading_1.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/italic.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/link.svg +6 -0
- data/lib/vapid/vendor/trix/assets/trix/images/nesting_level_decrease.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/nesting_level_increase.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/numbers.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/quote.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/redo.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/remove.svg +4 -0
- data/lib/vapid/vendor/trix/assets/trix/images/strike.svg +6 -0
- data/lib/vapid/vendor/trix/assets/trix/images/trash.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/images/undo.svg +5 -0
- data/lib/vapid/vendor/trix/assets/trix/stylesheets/attachments.scss +112 -0
- data/lib/vapid/vendor/trix/assets/trix/stylesheets/content.scss +88 -0
- data/lib/vapid/vendor/trix/assets/trix/stylesheets/editor.scss +8 -0
- data/lib/vapid/vendor/trix/assets/trix/stylesheets/icons.scss +14 -0
- data/lib/vapid/vendor/trix/assets/trix/stylesheets/media-queries.scss +7 -0
- data/lib/vapid/vendor/trix/assets/trix/stylesheets/toolbar.scss +194 -0
- data/lib/vapid/vendor/trix/bin/blade +16 -0
- data/lib/vapid/vendor/trix/bin/ci +21 -0
- data/lib/vapid/vendor/trix/bin/rackup +16 -0
- data/lib/vapid/vendor/trix/bin/rake +16 -0
- data/lib/vapid/vendor/trix/bin/release +139 -0
- data/lib/vapid/vendor/trix/bin/setup +69 -0
- data/lib/vapid/vendor/trix/bin/update-status-image +100 -0
- data/lib/vapid/vendor/trix/bower.json +34 -0
- data/lib/vapid/vendor/trix/config.ru +32 -0
- data/lib/vapid/vendor/trix/dist/trix-core.js +11 -0
- data/lib/vapid/vendor/trix/dist/trix.css +286 -0
- data/lib/vapid/vendor/trix/dist/trix.js +20 -0
- data/lib/vapid/vendor/trix/package.json +29 -0
- data/lib/vapid/vendor/trix/polyfills/polyfills.coffee +3 -0
- data/lib/vapid/vendor/trix/polyfills/set.coffee +24 -0
- data/lib/vapid/vendor/trix/polyfills/vendor/CustomElements.js +1029 -0
- data/lib/vapid/vendor/trix/polyfills/vendor/README.md +2 -0
- data/lib/vapid/vendor/trix/polyfills/vendor/promise.js +228 -0
- data/lib/vapid/vendor/trix/src/trix/VERSION +1 -0
- data/lib/vapid/vendor/trix/src/trix/config/block_attributes.coffee +37 -0
- data/lib/vapid/vendor/trix/src/trix/config/css.coffee +12 -0
- data/lib/vapid/vendor/trix/src/trix/config/file_size_formatting.coffee +22 -0
- data/lib/vapid/vendor/trix/src/trix/config/index.coffee +9 -0
- data/lib/vapid/vendor/trix/src/trix/config/lang.coffee +26 -0
- data/lib/vapid/vendor/trix/src/trix/config/selection_elements.coffee +26 -0
- data/lib/vapid/vendor/trix/src/trix/config/serialization.coffee +63 -0
- data/lib/vapid/vendor/trix/src/trix/config/text_attributes.coffee +25 -0
- data/lib/vapid/vendor/trix/src/trix/config/toolbar.coffee +41 -0
- data/lib/vapid/vendor/trix/src/trix/config/undo_interval.coffee +7 -0
- data/lib/vapid/vendor/trix/src/trix/controllers/attachment_editor_controller.coffee +104 -0
- data/lib/vapid/vendor/trix/src/trix/controllers/composition_controller.coffee +117 -0
- data/lib/vapid/vendor/trix/src/trix/controllers/controller.coffee +3 -0
- data/lib/vapid/vendor/trix/src/trix/controllers/editor_controller.coffee +369 -0
- data/lib/vapid/vendor/trix/src/trix/controllers/input/composition_input.coffee +57 -0
- data/lib/vapid/vendor/trix/src/trix/controllers/input_controller.coffee +473 -0
- data/lib/vapid/vendor/trix/src/trix/controllers/toolbar_controller.coffee +173 -0
- data/lib/vapid/vendor/trix/src/trix/core/basic_object.coffee +44 -0
- data/lib/vapid/vendor/trix/src/trix/core/collections/element_store.coffee +21 -0
- data/lib/vapid/vendor/trix/src/trix/core/collections/hash.coffee +98 -0
- data/lib/vapid/vendor/trix/src/trix/core/collections/index.coffee +4 -0
- data/lib/vapid/vendor/trix/src/trix/core/collections/object_group.coffee +37 -0
- data/lib/vapid/vendor/trix/src/trix/core/collections/object_map.coffee +10 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/arrays.coffee +34 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/config.coffee +23 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/custom_elements.coffee +45 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/dom.coffee +185 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/extend.coffee +4 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/functions.coffee +3 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/global.coffee +23 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/index.coffee +10 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/objects.coffee +11 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/ranges.coffee +33 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/selection.coffee +25 -0
- data/lib/vapid/vendor/trix/src/trix/core/helpers/strings.coffee +46 -0
- data/lib/vapid/vendor/trix/src/trix/core/index.coffee +4 -0
- data/lib/vapid/vendor/trix/src/trix/core/object.coffee +33 -0
- data/lib/vapid/vendor/trix/src/trix/core/utilities/index.coffee +2 -0
- data/lib/vapid/vendor/trix/src/trix/core/utilities/operation.coffee +37 -0
- data/lib/vapid/vendor/trix/src/trix/core/utilities/utf16_string.coffee +93 -0
- data/lib/vapid/vendor/trix/src/trix/elements/trix_editor_element.coffee +166 -0
- data/lib/vapid/vendor/trix/src/trix/elements/trix_toolbar_element.coffee +28 -0
- data/lib/vapid/vendor/trix/src/trix/index.coffee.erb +14 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/control_element.coffee +60 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/debugger.coffee +104 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/element.coffee +86 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/index.coffee +17 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/polyfills/vendor/details-element-polyfill.js +5 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/templates/debug.jst.eco +17 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/templates/document.jst.eco +33 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/templates/performance.jst.eco +10 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/templates/render.jst.eco +1 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/templates/selection.jst.eco +5 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/templates/undo.jst.eco +13 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/view.coffee +58 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/views/debug_view.coffee +33 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/views/document_view.coffee +12 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/views/performance_view.coffee +51 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/views/render_view.coffee +21 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/views/selection_view.coffee +33 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/views/undo_view.coffee +12 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/deserializer.coffee +55 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/index.coffee +5 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/player.coffee +60 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/player_controller.coffee +43 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/player_element.coffee +32 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/player_view.coffee +133 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/recorder.coffee +82 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/recording.coffee +54 -0
- data/lib/vapid/vendor/trix/src/trix/inspector/watchdog/serializer.coffee +61 -0
- data/lib/vapid/vendor/trix/src/trix/models/attachment.coffee +157 -0
- data/lib/vapid/vendor/trix/src/trix/models/attachment_manager.coffee +24 -0
- data/lib/vapid/vendor/trix/src/trix/models/attachment_piece.coffee +47 -0
- data/lib/vapid/vendor/trix/src/trix/models/block.coffee +230 -0
- data/lib/vapid/vendor/trix/src/trix/models/composition.coffee +521 -0
- data/lib/vapid/vendor/trix/src/trix/models/document.coffee +538 -0
- data/lib/vapid/vendor/trix/src/trix/models/editor.coffee +141 -0
- data/lib/vapid/vendor/trix/src/trix/models/html_parser.coffee +335 -0
- data/lib/vapid/vendor/trix/src/trix/models/line_break_insertion.coffee +31 -0
- data/lib/vapid/vendor/trix/src/trix/models/location_mapper.coffee +156 -0
- data/lib/vapid/vendor/trix/src/trix/models/managed_attachment.coffee +28 -0
- data/lib/vapid/vendor/trix/src/trix/models/piece.coffee +95 -0
- data/lib/vapid/vendor/trix/src/trix/models/point_mapper.coffee +28 -0
- data/lib/vapid/vendor/trix/src/trix/models/selection_manager.coffee +129 -0
- data/lib/vapid/vendor/trix/src/trix/models/splittable_list.coffee +168 -0
- data/lib/vapid/vendor/trix/src/trix/models/string_piece.coffee +49 -0
- data/lib/vapid/vendor/trix/src/trix/models/text.coffee +168 -0
- data/lib/vapid/vendor/trix/src/trix/models/undo_manager.coffee +40 -0
- data/lib/vapid/vendor/trix/src/trix/observers/mutation_observer.coffee +131 -0
- data/lib/vapid/vendor/trix/src/trix/observers/selection_change_observer.coffee +56 -0
- data/lib/vapid/vendor/trix/src/trix/operations/file_verification_operation.coffee +15 -0
- data/lib/vapid/vendor/trix/src/trix/operations/image_preload_operation.coffee +15 -0
- data/lib/vapid/vendor/trix/src/trix/views/attachment_view.coffee +99 -0
- data/lib/vapid/vendor/trix/src/trix/views/block_view.coffee +37 -0
- data/lib/vapid/vendor/trix/src/trix/views/document_view.coffee +68 -0
- data/lib/vapid/vendor/trix/src/trix/views/object_group_view.coffee +23 -0
- data/lib/vapid/vendor/trix/src/trix/views/object_view.coffee +86 -0
- data/lib/vapid/vendor/trix/src/trix/views/piece_view.coffee +97 -0
- data/lib/vapid/vendor/trix/src/trix/views/previewable_attachment_view.coffee +49 -0
- data/lib/vapid/vendor/trix/src/trix/views/text_view.coffee +30 -0
- data/lib/vapid/vendor/trix/test/.gitignore +1 -0
- data/lib/vapid/vendor/trix/test/src/system/attachment_test.coffee +70 -0
- data/lib/vapid/vendor/trix/test/src/system/basic_input_test.coffee +68 -0
- data/lib/vapid/vendor/trix/test/src/system/block_formatting_test.coffee +602 -0
- data/lib/vapid/vendor/trix/test/src/system/caching_test.coffee +21 -0
- data/lib/vapid/vendor/trix/test/src/system/composition_input_test.coffee +138 -0
- data/lib/vapid/vendor/trix/test/src/system/cursor_movement_test.coffee +54 -0
- data/lib/vapid/vendor/trix/test/src/system/custom_element_test.coffee +314 -0
- data/lib/vapid/vendor/trix/test/src/system/html_loading_test.coffee +62 -0
- data/lib/vapid/vendor/trix/test/src/system/html_replacement_test.coffee +101 -0
- data/lib/vapid/vendor/trix/test/src/system/installation_process_test.coffee +59 -0
- data/lib/vapid/vendor/trix/test/src/system/list_formatting_test.coffee +70 -0
- data/lib/vapid/vendor/trix/test/src/system/mutation_input_test.coffee +73 -0
- data/lib/vapid/vendor/trix/test/src/system/pasting_test.coffee +215 -0
- data/lib/vapid/vendor/trix/test/src/system/text_formatting_test.coffee +151 -0
- data/lib/vapid/vendor/trix/test/src/system/undo_test.coffee +48 -0
- data/lib/vapid/vendor/trix/test/src/test.coffee +16 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/assertions.coffee +38 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/editor_helpers.coffee +37 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_empty.jst.eco +1 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_html.jst.eco +2 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_in_table.jst.eco +7 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_with_block_styles.jst.eco +6 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_with_bold_styles.jst.eco +7 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_with_image.jst.eco +2 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_with_styled_content.jst.eco +7 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/editor_with_toolbar_and_input.jst.eco +5 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/fixtures.coffee +536 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/fixtures/logo.png +0 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/index.coffee +18 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/input_helpers.coffee +183 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/selection_helpers.coffee +91 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/test_helpers.coffee +72 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/test_stubs.coffee +31 -0
- data/lib/vapid/vendor/trix/test/src/test_helpers/toolbar_helpers.coffee +45 -0
- data/lib/vapid/vendor/trix/test/src/unit/attachment_test.coffee +23 -0
- data/lib/vapid/vendor/trix/test/src/unit/block_test.coffee +22 -0
- data/lib/vapid/vendor/trix/test/src/unit/composition_test.coffee +13 -0
- data/lib/vapid/vendor/trix/test/src/unit/document_test.coffee +11 -0
- data/lib/vapid/vendor/trix/test/src/unit/document_view_test.coffee +6 -0
- data/lib/vapid/vendor/trix/test/src/unit/html_parser_test.coffee +162 -0
- data/lib/vapid/vendor/trix/test/src/unit/location_mapper_test.coffee +185 -0
- data/lib/vapid/vendor/trix/test/src/unit/mutation_observer_test.coffee +84 -0
- data/lib/vapid/vendor/trix/test/src/unit/serialization_test.coffee +7 -0
- data/lib/vapid/vendor/trix/test/src/unit/string_change_summary_test.coffee +57 -0
- data/lib/vapid/vendor/trix/test/src/unit/text_test.coffee +19 -0
- data/lib/vapid/vendor/trix/test/vendor/rangy-core.js +3845 -0
- data/lib/vapid/vendor/trix/test/vendor/rangy-textrange.js +1930 -0
- data/lib/vapid/version.rb +4 -0
- data/lib/vapid/views/admin/install.html.erb +19 -0
- data/lib/vapid/views/admin/login.html.erb +11 -0
- data/lib/vapid/views/admin/overview/index.html.erb +1 -0
- data/lib/vapid/views/admin/records/_form.erb +9 -0
- data/lib/vapid/views/admin/records/edit.html.erb +5 -0
- data/lib/vapid/views/admin/records/index.html.erb +38 -0
- data/lib/vapid/views/admin/records/new.html.erb +3 -0
- data/lib/vapid/views/errors/404.html.erb +1 -0
- data/lib/vapid/views/errors/500.html.erb +1 -0
- data/lib/vapid/views/layouts/admin.html.erb +41 -0
- data/lib/vapid/views/layouts/admin_form.html.erb +22 -0
- data/lib/vapid/views/layouts/error.html.erb +11 -0
- data/vapid.gemspec +48 -0
- metadata +811 -0
@@ -0,0 +1,141 @@
|
|
1
|
+
#= require trix/models/undo_manager
|
2
|
+
|
3
|
+
class Trix.Editor
|
4
|
+
constructor: (@composition, @selectionManager, @element) ->
|
5
|
+
@undoManager = new Trix.UndoManager @composition
|
6
|
+
|
7
|
+
loadDocument: (document) ->
|
8
|
+
@loadSnapshot({document, selectedRange: [0, 0]})
|
9
|
+
|
10
|
+
loadHTML: (html = "") ->
|
11
|
+
@loadDocument(Trix.Document.fromHTML(html, referenceElement: @element))
|
12
|
+
|
13
|
+
loadJSON: ({document, selectedRange}) ->
|
14
|
+
document = Trix.Document.fromJSON(document)
|
15
|
+
@loadSnapshot({document, selectedRange})
|
16
|
+
|
17
|
+
loadSnapshot: (snapshot) ->
|
18
|
+
@undoManager = new Trix.UndoManager @composition
|
19
|
+
@composition.loadSnapshot(snapshot)
|
20
|
+
|
21
|
+
getDocument: ->
|
22
|
+
@composition.document
|
23
|
+
|
24
|
+
getSelectedDocument: ->
|
25
|
+
@composition.getSelectedDocument()
|
26
|
+
|
27
|
+
getSnapshot: ->
|
28
|
+
@composition.getSnapshot()
|
29
|
+
|
30
|
+
toJSON: ->
|
31
|
+
@getSnapshot()
|
32
|
+
|
33
|
+
# Document manipulation
|
34
|
+
|
35
|
+
deleteInDirection: (direction) ->
|
36
|
+
@composition.deleteInDirection(direction)
|
37
|
+
|
38
|
+
insertAttachment: (attachment) ->
|
39
|
+
@composition.insertAttachment(attachment)
|
40
|
+
|
41
|
+
insertDocument: (document) ->
|
42
|
+
@composition.insertDocument(document)
|
43
|
+
|
44
|
+
insertFile: (file) ->
|
45
|
+
@composition.insertFile(file)
|
46
|
+
|
47
|
+
insertHTML: (html) ->
|
48
|
+
@composition.insertHTML(html)
|
49
|
+
|
50
|
+
insertString: (string) ->
|
51
|
+
@composition.insertString(string)
|
52
|
+
|
53
|
+
insertText: (text) ->
|
54
|
+
@composition.insertText(text)
|
55
|
+
|
56
|
+
insertLineBreak: ->
|
57
|
+
@composition.insertLineBreak()
|
58
|
+
|
59
|
+
# Selection
|
60
|
+
|
61
|
+
getSelectedRange: ->
|
62
|
+
@composition.getSelectedRange()
|
63
|
+
|
64
|
+
getPosition: ->
|
65
|
+
@composition.getPosition()
|
66
|
+
|
67
|
+
getClientRectAtPosition: (position) ->
|
68
|
+
locationRange = @getDocument().locationRangeFromRange([position, position + 1])
|
69
|
+
@selectionManager.getClientRectAtLocationRange(locationRange)
|
70
|
+
|
71
|
+
expandSelectionInDirection: (direction) ->
|
72
|
+
@composition.expandSelectionInDirection(direction)
|
73
|
+
|
74
|
+
moveCursorInDirection: (direction) ->
|
75
|
+
@composition.moveCursorInDirection(direction)
|
76
|
+
|
77
|
+
setSelectedRange: (selectedRange) ->
|
78
|
+
@composition.setSelectedRange(selectedRange)
|
79
|
+
|
80
|
+
# Attributes
|
81
|
+
|
82
|
+
activateAttribute: (name, value = true) ->
|
83
|
+
@composition.setCurrentAttribute(name, value)
|
84
|
+
|
85
|
+
attributeIsActive: (name) ->
|
86
|
+
@composition.hasCurrentAttribute(name)
|
87
|
+
|
88
|
+
canActivateAttribute: (name) ->
|
89
|
+
@composition.canSetCurrentAttribute(name)
|
90
|
+
|
91
|
+
deactivateAttribute: (name) ->
|
92
|
+
@composition.removeCurrentAttribute(name)
|
93
|
+
|
94
|
+
# Nesting level
|
95
|
+
|
96
|
+
canDecreaseNestingLevel: ->
|
97
|
+
@composition.canDecreaseNestingLevel()
|
98
|
+
|
99
|
+
canIncreaseNestingLevel: ->
|
100
|
+
@composition.canIncreaseNestingLevel()
|
101
|
+
|
102
|
+
decreaseNestingLevel: ->
|
103
|
+
if @canDecreaseNestingLevel()
|
104
|
+
@composition.decreaseNestingLevel()
|
105
|
+
|
106
|
+
increaseNestingLevel: ->
|
107
|
+
if @canIncreaseNestingLevel()
|
108
|
+
@composition.increaseNestingLevel()
|
109
|
+
|
110
|
+
# Indentation level (deprecated aliases to be removed in v1.0)
|
111
|
+
|
112
|
+
canDecreaseIndentationLevel: ->
|
113
|
+
@canDecreaseNestingLevel()
|
114
|
+
|
115
|
+
canIncreaseIndentationLevel: ->
|
116
|
+
@canIncreaseNestingLevel()
|
117
|
+
|
118
|
+
decreaseIndentationLevel: ->
|
119
|
+
@decreaseNestingLevel()
|
120
|
+
|
121
|
+
increaseIndentationLevel: ->
|
122
|
+
@increaseNestingLevel()
|
123
|
+
|
124
|
+
# Undo/redo
|
125
|
+
|
126
|
+
canRedo: ->
|
127
|
+
@undoManager.canRedo()
|
128
|
+
|
129
|
+
canUndo: ->
|
130
|
+
@undoManager.canUndo()
|
131
|
+
|
132
|
+
recordUndoEntry: (description, {context, consolidatable} = {}) ->
|
133
|
+
@undoManager.recordUndoEntry(description, {context, consolidatable})
|
134
|
+
|
135
|
+
redo: ->
|
136
|
+
if @canRedo()
|
137
|
+
@undoManager.redo()
|
138
|
+
|
139
|
+
undo: ->
|
140
|
+
if @canUndo()
|
141
|
+
@undoManager.undo()
|
@@ -0,0 +1,335 @@
|
|
1
|
+
{arraysAreEqual, normalizeSpaces, makeElement, tagName, getBlockTagNames, walkTree,
|
2
|
+
findClosestElementFromNode, elementContainsNode, nodeIsAttachmentElement} = Trix
|
3
|
+
|
4
|
+
class Trix.HTMLParser extends Trix.BasicObject
|
5
|
+
allowedAttributes = "style href src width height class".split(" ")
|
6
|
+
|
7
|
+
@parse: (html, options) ->
|
8
|
+
parser = new this html, options
|
9
|
+
parser.parse()
|
10
|
+
parser
|
11
|
+
|
12
|
+
constructor: (@html, {@referenceElement} = {}) ->
|
13
|
+
@blocks = []
|
14
|
+
@blockElements = []
|
15
|
+
@processedElements = []
|
16
|
+
|
17
|
+
getDocument: ->
|
18
|
+
Trix.Document.fromJSON(@blocks)
|
19
|
+
|
20
|
+
# HTML parsing
|
21
|
+
|
22
|
+
parse: ->
|
23
|
+
try
|
24
|
+
@createHiddenContainer()
|
25
|
+
html = sanitizeHTML(@html)
|
26
|
+
@containerElement.innerHTML = html
|
27
|
+
walker = walkTree(@containerElement, usingFilter: nodeFilter)
|
28
|
+
@processNode(walker.currentNode) while walker.nextNode()
|
29
|
+
@translateBlockElementMarginsToNewlines()
|
30
|
+
finally
|
31
|
+
@removeHiddenContainer()
|
32
|
+
|
33
|
+
createHiddenContainer: ->
|
34
|
+
if @referenceElement
|
35
|
+
@containerElement = @referenceElement.cloneNode(false)
|
36
|
+
@containerElement.removeAttribute("id")
|
37
|
+
@containerElement.setAttribute("data-trix-internal", "")
|
38
|
+
@containerElement.style.display = "none"
|
39
|
+
@referenceElement.parentNode.insertBefore(@containerElement, @referenceElement.nextSibling)
|
40
|
+
else
|
41
|
+
@containerElement = makeElement(tagName: "div", style: { display: "none" })
|
42
|
+
document.body.appendChild(@containerElement)
|
43
|
+
|
44
|
+
removeHiddenContainer: ->
|
45
|
+
@containerElement.parentNode.removeChild(@containerElement)
|
46
|
+
|
47
|
+
sanitizeHTML = (html) ->
|
48
|
+
# Remove everything after </html>
|
49
|
+
html = html.replace(/<\/html[^>]*>[^]*$/i, "</html>")
|
50
|
+
|
51
|
+
doc = document.implementation.createHTMLDocument("")
|
52
|
+
doc.documentElement.innerHTML = html
|
53
|
+
{body, head} = doc
|
54
|
+
|
55
|
+
for style in head.querySelectorAll("style")
|
56
|
+
body.appendChild(style)
|
57
|
+
|
58
|
+
nodesToRemove = []
|
59
|
+
walker = walkTree(body)
|
60
|
+
|
61
|
+
while walker.nextNode()
|
62
|
+
node = walker.currentNode
|
63
|
+
switch node.nodeType
|
64
|
+
when Node.ELEMENT_NODE
|
65
|
+
if elementIsRemovable(node)
|
66
|
+
nodesToRemove.push(node)
|
67
|
+
else
|
68
|
+
for {name} in [node.attributes...]
|
69
|
+
unless name in allowedAttributes or name.indexOf("data-trix") is 0
|
70
|
+
node.removeAttribute(name)
|
71
|
+
when Node.COMMENT_NODE
|
72
|
+
nodesToRemove.push(node)
|
73
|
+
|
74
|
+
for node in nodesToRemove
|
75
|
+
node.parentNode.removeChild(node)
|
76
|
+
|
77
|
+
body.innerHTML
|
78
|
+
|
79
|
+
elementIsRemovable = (element) ->
|
80
|
+
return unless element?.nodeType is Node.ELEMENT_NODE
|
81
|
+
return if nodeIsAttachmentElement(element)
|
82
|
+
tagName(element) is "script" or element.getAttribute("data-trix-serialize") is "false"
|
83
|
+
|
84
|
+
nodeFilter = (node) ->
|
85
|
+
if tagName(node) is "style"
|
86
|
+
NodeFilter.FILTER_REJECT
|
87
|
+
else
|
88
|
+
NodeFilter.FILTER_ACCEPT
|
89
|
+
|
90
|
+
processNode: (node) ->
|
91
|
+
switch node.nodeType
|
92
|
+
when Node.TEXT_NODE
|
93
|
+
@processTextNode(node)
|
94
|
+
when Node.ELEMENT_NODE
|
95
|
+
@appendBlockForElement(node)
|
96
|
+
@processElement(node)
|
97
|
+
|
98
|
+
appendBlockForElement: (element) ->
|
99
|
+
elementIsBlockElement = @isBlockElement(element)
|
100
|
+
currentBlockContainsElement = elementContainsNode(@currentBlockElement, element)
|
101
|
+
|
102
|
+
if elementIsBlockElement and not @isBlockElement(element.firstChild)
|
103
|
+
unless @isInsignificantTextNode(element.firstChild) and @isBlockElement(element.firstElementChild)
|
104
|
+
attributes = @getBlockAttributes(element)
|
105
|
+
unless currentBlockContainsElement and arraysAreEqual(attributes, @currentBlock.attributes)
|
106
|
+
@currentBlock = @appendBlockForAttributesWithElement(attributes, element)
|
107
|
+
@currentBlockElement = element
|
108
|
+
|
109
|
+
else if @currentBlockElement and not currentBlockContainsElement and not elementIsBlockElement
|
110
|
+
if parentBlockElement = @findParentBlockElement(element)
|
111
|
+
@appendBlockForElement(parentBlockElement)
|
112
|
+
else
|
113
|
+
@currentBlock = @appendEmptyBlock()
|
114
|
+
@currentBlockElement = null
|
115
|
+
|
116
|
+
findParentBlockElement: (element) ->
|
117
|
+
{parentElement} = element
|
118
|
+
while parentElement and parentElement isnt @containerElement
|
119
|
+
if @isBlockElement(parentElement) and parentElement in @blockElements
|
120
|
+
return parentElement
|
121
|
+
else
|
122
|
+
{parentElement} = parentElement
|
123
|
+
null
|
124
|
+
|
125
|
+
processTextNode: (node) ->
|
126
|
+
unless @isInsignificantTextNode(node)
|
127
|
+
string = node.data
|
128
|
+
unless elementCanDisplayPreformattedText(node.parentNode)
|
129
|
+
string = squishBreakableWhitespace(string)
|
130
|
+
if stringEndsWithWhitespace(node.previousSibling?.textContent)
|
131
|
+
string = leftTrimBreakableWhitespace(string)
|
132
|
+
@appendStringWithAttributes(string, @getTextAttributes(node.parentNode))
|
133
|
+
|
134
|
+
processElement: (element) ->
|
135
|
+
if nodeIsAttachmentElement(element)
|
136
|
+
attributes = getAttachmentAttributes(element)
|
137
|
+
if Object.keys(attributes).length
|
138
|
+
textAttributes = @getTextAttributes(element)
|
139
|
+
@appendAttachmentWithAttributes(attributes, textAttributes)
|
140
|
+
# We have everything we need so avoid processing inner nodes
|
141
|
+
element.innerHTML = ""
|
142
|
+
@processedElements.push(element)
|
143
|
+
else
|
144
|
+
switch tagName(element)
|
145
|
+
when "br"
|
146
|
+
unless @isExtraBR(element) or @isBlockElement(element.nextSibling)
|
147
|
+
@appendStringWithAttributes("\n", @getTextAttributes(element))
|
148
|
+
@processedElements.push(element)
|
149
|
+
when "img"
|
150
|
+
attributes = url: element.getAttribute("src"), contentType: "image"
|
151
|
+
attributes[key] = value for key, value of getImageDimensions(element)
|
152
|
+
@appendAttachmentWithAttributes(attributes, @getTextAttributes(element))
|
153
|
+
@processedElements.push(element)
|
154
|
+
when "tr"
|
155
|
+
unless element.parentNode.firstChild is element
|
156
|
+
@appendStringWithAttributes("\n")
|
157
|
+
when "td"
|
158
|
+
unless element.parentNode.firstChild is element
|
159
|
+
@appendStringWithAttributes(" | ")
|
160
|
+
|
161
|
+
# Document construction
|
162
|
+
|
163
|
+
appendBlockForAttributesWithElement: (attributes, element) ->
|
164
|
+
@blockElements.push(element)
|
165
|
+
block = blockForAttributes(attributes)
|
166
|
+
@blocks.push(block)
|
167
|
+
block
|
168
|
+
|
169
|
+
appendEmptyBlock: ->
|
170
|
+
@appendBlockForAttributesWithElement([], null)
|
171
|
+
|
172
|
+
appendStringWithAttributes: (string, attributes) ->
|
173
|
+
@appendPiece(pieceForString(string, attributes))
|
174
|
+
|
175
|
+
appendAttachmentWithAttributes: (attachment, attributes) ->
|
176
|
+
@appendPiece(pieceForAttachment(attachment, attributes))
|
177
|
+
|
178
|
+
appendPiece: (piece) ->
|
179
|
+
if @blocks.length is 0
|
180
|
+
@appendEmptyBlock()
|
181
|
+
@blocks[@blocks.length - 1].text.push(piece)
|
182
|
+
|
183
|
+
appendStringToTextAtIndex: (string, index) ->
|
184
|
+
{text} = @blocks[index]
|
185
|
+
piece = text[text.length - 1]
|
186
|
+
|
187
|
+
if piece?.type is "string"
|
188
|
+
piece.string += string
|
189
|
+
else
|
190
|
+
text.push(pieceForString(string))
|
191
|
+
|
192
|
+
prependStringToTextAtIndex: (string, index) ->
|
193
|
+
{text} = @blocks[index]
|
194
|
+
piece = text[0]
|
195
|
+
|
196
|
+
if piece?.type is "string"
|
197
|
+
piece.string = string + piece.string
|
198
|
+
else
|
199
|
+
text.unshift(pieceForString(string))
|
200
|
+
|
201
|
+
pieceForString = (string, attributes = {}) ->
|
202
|
+
type = "string"
|
203
|
+
string = normalizeSpaces(string)
|
204
|
+
{string, attributes, type}
|
205
|
+
|
206
|
+
pieceForAttachment = (attachment, attributes = {}) ->
|
207
|
+
type = "attachment"
|
208
|
+
{attachment, attributes, type}
|
209
|
+
|
210
|
+
blockForAttributes = (attributes = {}) ->
|
211
|
+
text = []
|
212
|
+
{text, attributes}
|
213
|
+
|
214
|
+
# Attribute parsing
|
215
|
+
|
216
|
+
getTextAttributes: (element) ->
|
217
|
+
attributes = {}
|
218
|
+
for attribute, config of Trix.config.textAttributes
|
219
|
+
if config.tagName and findClosestElementFromNode(element, matchingSelector: config.tagName, untilNode: @containerElement)
|
220
|
+
attributes[attribute] = true
|
221
|
+
else if config.parser
|
222
|
+
if value = config.parser(element)
|
223
|
+
attributeInheritedFromBlock = false
|
224
|
+
for blockElement in @findBlockElementAncestors(element)
|
225
|
+
if config.parser(blockElement) is value
|
226
|
+
attributeInheritedFromBlock = true
|
227
|
+
break
|
228
|
+
unless attributeInheritedFromBlock
|
229
|
+
attributes[attribute] = value
|
230
|
+
|
231
|
+
if nodeIsAttachmentElement(element)
|
232
|
+
if json = element.getAttribute("data-trix-attributes")
|
233
|
+
for key, value of JSON.parse(json)
|
234
|
+
attributes[key] = value
|
235
|
+
|
236
|
+
attributes
|
237
|
+
|
238
|
+
getBlockAttributes: (element) ->
|
239
|
+
attributes = []
|
240
|
+
while element and element isnt @containerElement
|
241
|
+
for attribute, config of Trix.config.blockAttributes when config.parse isnt false
|
242
|
+
if tagName(element) is config.tagName
|
243
|
+
if config.test?(element) or not config.test
|
244
|
+
attributes.push(attribute)
|
245
|
+
attributes.push(config.listAttribute) if config.listAttribute
|
246
|
+
element = element.parentNode
|
247
|
+
attributes.reverse()
|
248
|
+
|
249
|
+
findBlockElementAncestors: (element) ->
|
250
|
+
ancestors = []
|
251
|
+
while element and element isnt @containerElement
|
252
|
+
if tagName(element) in getBlockTagNames()
|
253
|
+
ancestors.push(element)
|
254
|
+
element = element.parentNode
|
255
|
+
ancestors
|
256
|
+
|
257
|
+
getAttachmentAttributes = (element) ->
|
258
|
+
JSON.parse(element.getAttribute("data-trix-attachment"))
|
259
|
+
|
260
|
+
getImageDimensions = (element) ->
|
261
|
+
width = element.getAttribute("width")
|
262
|
+
height = element.getAttribute("height")
|
263
|
+
dimensions = {}
|
264
|
+
dimensions.width = parseInt(width, 10) if width
|
265
|
+
dimensions.height = parseInt(height, 10) if height
|
266
|
+
dimensions
|
267
|
+
|
268
|
+
# Element inspection
|
269
|
+
|
270
|
+
isBlockElement: (element) ->
|
271
|
+
return unless element?.nodeType is Node.ELEMENT_NODE
|
272
|
+
return if findClosestElementFromNode(element, matchingSelector: "td", untilNode: @containerElement)
|
273
|
+
tagName(element) in getBlockTagNames() or window.getComputedStyle(element).display is "block"
|
274
|
+
|
275
|
+
isInsignificantTextNode: (node) ->
|
276
|
+
return unless node?.nodeType is Node.TEXT_NODE
|
277
|
+
return unless stringIsAllBreakableWhitespace(node.data)
|
278
|
+
return if elementCanDisplayPreformattedText(node.parentNode)
|
279
|
+
not node.previousSibling or @isBlockElement(node.previousSibling) or not node.nextSibling or @isBlockElement(node.nextSibling)
|
280
|
+
|
281
|
+
isExtraBR: (element) ->
|
282
|
+
tagName(element) is "br" and
|
283
|
+
@isBlockElement(element.parentNode) and
|
284
|
+
element.parentNode.lastChild is element
|
285
|
+
|
286
|
+
elementCanDisplayPreformattedText = (element) ->
|
287
|
+
{whiteSpace} = window.getComputedStyle(element)
|
288
|
+
whiteSpace in ["pre", "pre-wrap", "pre-line"]
|
289
|
+
|
290
|
+
# Margin translation
|
291
|
+
|
292
|
+
translateBlockElementMarginsToNewlines: ->
|
293
|
+
defaultMargin = @getMarginOfDefaultBlockElement()
|
294
|
+
|
295
|
+
for block, index in @blocks when margin = @getMarginOfBlockElementAtIndex(index)
|
296
|
+
if margin.top > defaultMargin.top * 2
|
297
|
+
@prependStringToTextAtIndex("\n", index)
|
298
|
+
|
299
|
+
if margin.bottom > defaultMargin.bottom * 2
|
300
|
+
@appendStringToTextAtIndex("\n", index)
|
301
|
+
|
302
|
+
getMarginOfBlockElementAtIndex: (index) ->
|
303
|
+
if element = @blockElements[index]
|
304
|
+
unless tagName(element) in getBlockTagNames() or element in @processedElements
|
305
|
+
getBlockElementMargin(element)
|
306
|
+
|
307
|
+
getMarginOfDefaultBlockElement: ->
|
308
|
+
element = makeElement(Trix.config.blockAttributes.default.tagName)
|
309
|
+
@containerElement.appendChild(element)
|
310
|
+
getBlockElementMargin(element)
|
311
|
+
|
312
|
+
getBlockElementMargin = (element) ->
|
313
|
+
style = window.getComputedStyle(element)
|
314
|
+
if style.display is "block"
|
315
|
+
top: parseInt(style.marginTop), bottom: parseInt(style.marginBottom)
|
316
|
+
|
317
|
+
# Whitespace
|
318
|
+
|
319
|
+
breakableWhitespacePattern = ///[^\S#{Trix.NON_BREAKING_SPACE}]///
|
320
|
+
|
321
|
+
squishBreakableWhitespace = (string) ->
|
322
|
+
string
|
323
|
+
# Replace all breakable whitespace characters with a space
|
324
|
+
.replace(///#{breakableWhitespacePattern.source}///g, " ")
|
325
|
+
# Replace two or more spaces with a single space
|
326
|
+
.replace(/\ {2,}/g, " ")
|
327
|
+
|
328
|
+
leftTrimBreakableWhitespace = (string) ->
|
329
|
+
string.replace(///^#{breakableWhitespacePattern.source}+///, "")
|
330
|
+
|
331
|
+
stringIsAllBreakableWhitespace = (string) ->
|
332
|
+
///^#{breakableWhitespacePattern.source}*$///.test(string)
|
333
|
+
|
334
|
+
stringEndsWithWhitespace = (string) ->
|
335
|
+
/\s$/.test(string)
|