rails_admin_content_builder 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +4 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +8 -0
  7. data/CODE_OF_CONDUCT.md +49 -0
  8. data/Gemfile +12 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +129 -0
  11. data/Rakefile +21 -0
  12. data/app/assets/images/cb-image-default.jpg +0 -0
  13. data/app/assets/images/cb-loading.svg +1 -0
  14. data/app/assets/images/cb-snippet-image-text.jpg +0 -0
  15. data/app/assets/images/cb-snippet-image.jpg +0 -0
  16. data/app/assets/images/cb-snippet-quote-text.jpg +0 -0
  17. data/app/assets/images/cb-snippet-quote.jpg +0 -0
  18. data/app/assets/images/cb-snippet-text-image.jpg +0 -0
  19. data/app/assets/images/cb-snippet-text-quote.jpg +0 -0
  20. data/app/assets/images/cb-snippet-text.jpg +0 -0
  21. data/app/assets/images/cb-snippet-video.jpg +0 -0
  22. data/app/assets/images/cb-video-default.jpg +0 -0
  23. data/app/assets/javascripts/rails_admin/content_builder.js.erb +295 -0
  24. data/app/assets/stylesheets/rails_admin/content_builder.scss +238 -0
  25. data/app/controllers/rails_admin_content_builder/content_builder_controller.rb +19 -0
  26. data/app/helpers/rails_admin_content_builder/content_builder_helpers.rb +32 -0
  27. data/app/models/rails_admin_content_builder/content_builder.rb +27 -0
  28. data/app/models/rails_admin_content_builder/content_builder_category.rb +12 -0
  29. data/app/models/rails_admin_content_builder/content_builder_image.rb +10 -0
  30. data/app/views/.gitkeep +0 -0
  31. data/app/views/rails_admin/main/content_builder.html.erb +42 -0
  32. data/bin/console +14 -0
  33. data/bin/setup +8 -0
  34. data/config/initializers/assets.rb +11 -0
  35. data/config/locales/content_builder.en.yml +17 -0
  36. data/config/locales/content_builder.pt-BR.yml +17 -0
  37. data/config/routes.rb +5 -0
  38. data/lib/generators/rails_admin_content_builder_generator.rb +32 -0
  39. data/lib/generators/templates/content_builder_image_uploader.rb +54 -0
  40. data/lib/generators/templates/create_content_builder_category_migration.rb +10 -0
  41. data/lib/generators/templates/create_content_builder_image_migration.rb +10 -0
  42. data/lib/generators/templates/create_content_builder_migration.rb +16 -0
  43. data/lib/generators/templates/rails_admin_content_builder.rb +37 -0
  44. data/lib/rails_admin_content_builder.rb +55 -0
  45. data/lib/rails_admin_content_builder/engine.rb +26 -0
  46. data/lib/rails_admin_content_builder/version.rb +3 -0
  47. data/rails_admin_content_builder.gemspec +42 -0
  48. data/screenshot/image1.png +0 -0
  49. data/spec/controllers/rails_admin_content_builder/content_builder_controller_spec.rb +19 -0
  50. data/spec/dummy/Gemfile +11 -0
  51. data/spec/dummy/Gemfile.lock +217 -0
  52. data/spec/dummy/Rakefile +6 -0
  53. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  54. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  55. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  56. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  57. data/spec/dummy/app/uploaders/content_builder_image_uploader.rb +54 -0
  58. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  59. data/spec/dummy/bin/bundle +3 -0
  60. data/spec/dummy/bin/rails +4 -0
  61. data/spec/dummy/bin/rake +4 -0
  62. data/spec/dummy/bin/setup +29 -0
  63. data/spec/dummy/config.ru +4 -0
  64. data/spec/dummy/config/application.rb +31 -0
  65. data/spec/dummy/config/boot.rb +5 -0
  66. data/spec/dummy/config/database.yml +25 -0
  67. data/spec/dummy/config/environment.rb +5 -0
  68. data/spec/dummy/config/environments/development.rb +41 -0
  69. data/spec/dummy/config/environments/production.rb +79 -0
  70. data/spec/dummy/config/environments/test.rb +42 -0
  71. data/spec/dummy/config/initializers/assets.rb +11 -0
  72. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  73. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  74. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  75. data/spec/dummy/config/initializers/inflections.rb +16 -0
  76. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  77. data/spec/dummy/config/initializers/rails_admin.rb +37 -0
  78. data/spec/dummy/config/initializers/rails_admin_content_builder.rb +37 -0
  79. data/spec/dummy/config/initializers/session_store.rb +3 -0
  80. data/spec/dummy/config/initializers/simple_form.rb +165 -0
  81. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  82. data/spec/dummy/config/locales/en.yml +23 -0
  83. data/spec/dummy/config/locales/simple_form.en.yml +31 -0
  84. data/spec/dummy/config/routes.rb +57 -0
  85. data/spec/dummy/config/secrets.yml +22 -0
  86. data/spec/dummy/db/development.sqlite3 +0 -0
  87. data/spec/dummy/db/migrate/20160713200802_create_content_builder_categories.rb +10 -0
  88. data/spec/dummy/db/migrate/20160713200803_create_content_builders.rb +15 -0
  89. data/spec/dummy/db/migrate/20160713200804_create_content_builder_images.rb +10 -0
  90. data/spec/dummy/db/schema.rb +46 -0
  91. data/spec/dummy/lib/templates/erb/scaffold/_form.html.erb +13 -0
  92. data/spec/dummy/log/development.log +1182 -0
  93. data/spec/dummy/public/404.html +67 -0
  94. data/spec/dummy/public/422.html +67 -0
  95. data/spec/dummy/public/500.html +66 -0
  96. data/spec/dummy/public/favicon.ico +0 -0
  97. data/spec/dummy/public/uploads/rails_admin_content_builder/content_builder_image/image/1/center_example.jpg +0 -0
  98. data/spec/dummy/public/uploads/rails_admin_content_builder/content_builder_image/image/1/example.jpg +0 -0
  99. data/spec/dummy/public/uploads/rails_admin_content_builder/content_builder_image/image/1/left_or_right_example.jpg +0 -0
  100. data/spec/dummy/public/uploads/rails_admin_content_builder/content_builder_image/image/2/center_example.jpg +0 -0
  101. data/spec/dummy/public/uploads/rails_admin_content_builder/content_builder_image/image/2/example.jpg +0 -0
  102. data/spec/dummy/public/uploads/rails_admin_content_builder/content_builder_image/image/2/left_or_right_example.jpg +0 -0
  103. data/spec/dummy/public/uploads/tmp/1461693110-14578-0001-7683/center_example.jpg +0 -0
  104. data/spec/dummy/public/uploads/tmp/1461693110-14578-0001-7683/example.jpg +0 -0
  105. data/spec/dummy/public/uploads/tmp/1461693110-14578-0001-7683/left_or_right_example.jpg +0 -0
  106. data/spec/dummy/public/uploads/tmp/1461693202-14651-0001-6505/center_example.jpg +0 -0
  107. data/spec/dummy/public/uploads/tmp/1461693202-14651-0001-6505/example.jpg +0 -0
  108. data/spec/dummy/public/uploads/tmp/1461693202-14651-0001-6505/left_or_right_example.jpg +0 -0
  109. data/spec/dummy/public/uploads/tmp/1461693245-14728-0001-4392/center_example.jpg +0 -0
  110. data/spec/dummy/public/uploads/tmp/1461693245-14728-0001-4392/example.jpg +0 -0
  111. data/spec/dummy/public/uploads/tmp/1461693245-14728-0001-4392/left_or_right_example.jpg +0 -0
  112. data/spec/factories/content_builder_categories.rb +5 -0
  113. data/spec/factories/content_builder_images.rb +6 -0
  114. data/spec/factories/content_builders.rb +10 -0
  115. data/spec/features/create_content_builder_category_spec.rb +18 -0
  116. data/spec/features/create_content_builder_spec.rb +34 -0
  117. data/spec/features/status_content_builder_spec.rb +28 -0
  118. data/spec/fixtures/assets/example.jpg +0 -0
  119. data/spec/helpers/rails_admin_content_builder/content_builder_helper_spec.rb +33 -0
  120. data/spec/models/rails_admin_content_builder/content_builder_category_spec.rb +11 -0
  121. data/spec/models/rails_admin_content_builder/content_builder_image_spec.rb +11 -0
  122. data/spec/models/rails_admin_content_builder/content_builder_spec.rb +44 -0
  123. data/spec/spec_helper.rb +36 -0
  124. data/spec/version_spec.rb +7 -0
  125. data/vendor/assets/stylesheets/rails_admin_content_builder.scss +214 -0
  126. metadata +3100 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 742c830676fed82d2a0389a6f24b26dccc8a119f
4
+ data.tar.gz: e5eaf59557cc530b4a8258b277b2228930a405e6
5
+ SHA512:
6
+ metadata.gz: 89c62ab066b15a6d270b0c1528fe31a8227d76f9da90d087c5d98caee182e10938a25ca7d33309cf74cc7b06c4048760ac51cada25aa0297e691fb726b1df7e5
7
+ data.tar.gz: 144f7984915bb931dda2e06b170b85245fea1f29cedaab927eeabec6b933e7a60ab3558ab7717807b80f3da5e3e10bc4287c0b22e45b688f8ee8bdbd9097d3d0
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea/*
11
+ /test_app/*
12
+ /spec/dummy/tmp/*
13
+ spec/dummy/log/test.log
14
+ spec/dummy/db/test.sqlite3
15
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --order=random
3
+ --drb
4
+ --format Fuubar
@@ -0,0 +1 @@
1
+ rails_admin_content_builder
@@ -0,0 +1 @@
1
+ ruby-2.2.1
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.11.2
5
+ notifications:
6
+ email:
7
+ - luizpicolo@gmail.com
8
+ - gmedina.santos@gmail.com
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at luizpicolo@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+ # Specify your gem's dependencies in rails_admin_content_builder.gemspec
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem 'sqlite3'
7
+ gem 'friendly_id'
8
+ gem 'rails_admin'
9
+ gem 'fuubar'
10
+ gem 'codeclimate-test-reporter'
11
+ gem 'simplecov', require: false
12
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Luiz Picolo
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.
@@ -0,0 +1,129 @@
1
+ # RailsAdminContentBuilder
2
+
3
+ ![Work in progress](http://messages.hellobits.com/warning.svg?message=Work%20in%20progress)
4
+
5
+ [![Build Status](https://travis-ci.org/luizpicolo/rails_admin_content_builder.svg?branch=master)](https://travis-ci.org/luizpicolo/rails_admin_content_builder)
6
+ [![Code Climate](https://codeclimate.com/github/luizpicolo/rails_admin_content_builder/badges/gpa.svg)](https://codeclimate.com/github/luizpicolo/rails_admin_content_builder)
7
+ [![Test Coverage](https://codeclimate.com/github/luizpicolo/rails_admin_content_builder/badges/coverage.svg)](https://codeclimate.com/github/luizpicolo/rails_admin_content_builder/coverage)
8
+ [![Issue Count](https://codeclimate.com/github/luizpicolo/rails_admin_content_builder/badges/issue_count.svg)](https://codeclimate.com/github/luizpicolo/rails_admin_content_builder)
9
+
10
+ Easy way for create contents using [rails_admin](https://github.com/sferik/rails_admin)
11
+
12
+ ## Preview
13
+
14
+ ![preview](https://raw.githubusercontent.com/luizpicolo/rails_admin_content_builder/master/screenshot/image1.png)
15
+
16
+ ## Requirements
17
+
18
+ Dependencies
19
+
20
+ MiniMagick
21
+
22
+ Supported ORM
23
+
24
+ ActiveRecord
25
+
26
+ Supported Asset Plugin
27
+
28
+ CarrierWave
29
+
30
+ ## Installation
31
+
32
+ Add this line to your application's Gemfile:
33
+
34
+ ```ruby
35
+ gem 'rails_admin'
36
+ gem 'rails_admin_content_builder', git: 'git://github.com/luizpicolo/rails_admin_content_builder.git'
37
+ ```
38
+
39
+ Run the generator and migrations
40
+
41
+ rails g rails_admin_content_builder
42
+ rake db:migrate
43
+
44
+ Add styles in app/assets/application.scss
45
+
46
+ ```ruby
47
+ *= require rails_admin_content_builder
48
+ ```
49
+
50
+ ## Usage
51
+
52
+ For custom model, see: [Customizing Model](https://github.com/luizpicolo/rails_admin_content_builder/wiki/Customizing-model)
53
+
54
+ Include in your controller
55
+
56
+ ```ruby
57
+ include RailsAdminContentBuilder::ContentBuilderHelpers
58
+ ```
59
+
60
+ Example
61
+
62
+ ```ruby
63
+ class PostsController < ApplicationController
64
+ include RailsAdminContentBuilder::ContentBuilderHelpers
65
+
66
+ def index
67
+ end
68
+
69
+ def show
70
+ end
71
+ end
72
+ ```
73
+
74
+ ```ruby
75
+ # Return all objects contents
76
+ @contents = all_contents_created
77
+
78
+ # Return especific object content
79
+ @content = find_content_created_by_slug('your-slug')
80
+
81
+ # Return content
82
+ @content = find_content_created_by_slug('your-slug')
83
+ @content.content_sanitized
84
+ ```
85
+
86
+ In your show content view
87
+
88
+ ```html
89
+ <article>
90
+ <h1><%= @content.title %></h1>
91
+ <p>
92
+ <%= @content.written_by %>
93
+ </p>
94
+ <p><%= @content.summary %></p>
95
+
96
+ <%= @content.content_sanitized %>
97
+ </article>
98
+ ```
99
+
100
+ ## Attributes and Methods
101
+
102
+ ```ruby
103
+ # Attributes
104
+ "title" : String
105
+ "written_by" : String
106
+ "date_publish" : DateTime
107
+ "content" : Text
108
+ "status" : Boolean
109
+ "slug" : String
110
+
111
+ # Methods
112
+ content_sanitized : Text
113
+ content_builder_images : Object
114
+ ```
115
+
116
+ ## Development
117
+
118
+ 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.
119
+
120
+ 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).
121
+
122
+ ## Contributing
123
+
124
+ Bug reports and pull requests are welcome on GitHub at https://github.com/luizpicolo/rails_admin_content_builder. 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.
125
+
126
+
127
+ ## License
128
+
129
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,21 @@
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
+
8
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
9
+ load 'rails/tasks/engine.rake'
10
+
11
+ Bundler::GemHelper.install_tasks
12
+
13
+ Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
14
+
15
+ require 'rspec/core'
16
+ require 'rspec/core/rake_task'
17
+
18
+ desc "Run all specs in spec directory (excluding plugin specs)"
19
+ RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
20
+
21
+ task :default => :spec
@@ -0,0 +1 @@
1
+ <?xml version="1.0" encoding="utf-8"?><svg width='50px' height='50px' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" class="uil-ripple"><rect x="0" y="0" width="100" height="100" fill="none" class="bk"></rect><g> <animate attributeName="opacity" dur="2s" repeatCount="indefinite" begin="0s" keyTimes="0;0.33;1" values="1;1;0"></animate><circle cx="50" cy="50" r="40" stroke="#aaaaab" fill="none" stroke-width="6" stroke-linecap="round"><animate attributeName="r" dur="2s" repeatCount="indefinite" begin="0s" keyTimes="0;0.33;1" values="0;22;44"></animate></circle></g><g><animate attributeName="opacity" dur="2s" repeatCount="indefinite" begin="1s" keyTimes="0;0.33;1" values="1;1;0"></animate><circle cx="50" cy="50" r="40" stroke="#7d7d7d" fill="none" stroke-width="6" stroke-linecap="round"><animate attributeName="r" dur="2s" repeatCount="indefinite" begin="1s" keyTimes="0;0.33;1" values="0;22;44"></animate></circle></g></svg>
@@ -0,0 +1,295 @@
1
+ //= require medium-editor
2
+
3
+ // when rails admin ready
4
+ $(document).on('rails_admin.dom_ready', function() {
5
+ $('.cb-form').on('submit', function(e){
6
+ var content = $('.cb-container').html();
7
+ $('#content').attr('value', content);
8
+ });
9
+
10
+ $('.cb-tools__input--upload').each(function() {
11
+ addEventToInputFile($(this).attr('id'));
12
+ });
13
+
14
+ $('.cb-container').sortable({
15
+ revert: true,
16
+ placeholder: 'ui-sortable-placeholder',
17
+ handle: '.cb-tools__btn--move',
18
+ cursor: 'move',
19
+ });
20
+
21
+ activeMediumEditor();
22
+ });
23
+
24
+ // when click on delete button
25
+ $(document).on('click', '.cb-tools__btn--delete', function() {
26
+ var resp = confirm('<%= I18n.t('ad$(min.actions.news_admin.delete_block')%>');
27
+
28
+ if(resp) {
29
+ $($(this).attr('href')).remove();
30
+ }
31
+ });
32
+
33
+ // when click on tools buttons
34
+ $(document).on('click', '.cb-tools__btn', function(e) {
35
+ e.preventDefault();
36
+ });
37
+
38
+ // when click on upload button
39
+ $(document).on('click', '.cb-tools__btn--upload', function() {
40
+ $($(this).attr('href')).find('input').trigger('click');
41
+ });
42
+
43
+ // when click on youtube buttons
44
+ $(document).on('click', '.cb-tools__btn--youtube', function() {
45
+ var resp = prompt('Cole a url do YouTube', '');
46
+ resp = youtubeParser(resp);
47
+
48
+ if(resp) {
49
+ var href = $(this).attr('href');
50
+ $(href).find('iframe').attr('src', 'https://www.youtube.com/embed/' + resp + '?rel=0&amp;showinfo=0');
51
+ }
52
+ });
53
+
54
+ // when click on snippet buttons
55
+ $(document).on('click', '.cb-snippet__btn', function(e) {
56
+ e.preventDefault();
57
+
58
+ var snippet = $(this).attr('data-snippet');
59
+ var container = $('.cb-container');
60
+ var id = generateID();
61
+
62
+ switch (snippet) {
63
+ case '1':
64
+ var element = '<div id="'+ id + '" class="cb-content">';
65
+
66
+ element += '<div class="cb-tools">';
67
+ element += '<a class="cb-tools__btn cb-tools__btn--move fa fa-arrows" href="#"></a>';
68
+ element += '<a class="cb-tools__btn cb-tools__btn--delete fa fa-trash" href="#'+ id + '"></a>';
69
+ element += '</div>';
70
+
71
+ element += '<div class="cb-text">';
72
+ element += '<p>Lorem Ipsum é simplesmente uma simulação de texto da indústria tipográfica e de impressos, e vem sendo utilizado desde o século XVI, quando um impressor desconhecido pegou uma bandeja de tipos e os embaralhou para fazer um livro de modelos de tipos.</p>';
73
+ element += '</div>';
74
+
75
+ element += '</div>';
76
+
77
+ container.append(element);
78
+ scrollTo(id);
79
+ break;
80
+
81
+ case '2':
82
+ var element = '<div id="'+ id + '" class="cb-content">';
83
+
84
+ element += '<div class="cb-tools">';
85
+ element += '<a class="cb-tools__btn cb-tools__btn--move fa fa-arrows" href="#"></a>';
86
+ element += '<a class="cb-tools__btn cb-tools__btn--delete fa fa-trash" href="#'+ id + '"></a>';
87
+ element += '</div>';
88
+
89
+ element += '<figure class="cb-figure cb-figure--left">';
90
+ element += '<div class="cb-figure__clip">';
91
+ element += '<%= image_tag('cb-image-default.jpg') %>';
92
+ element += '<input id="'+ id +'" data-position="left" class="filePicker cb-tools__input cb-tools__input--upload" type="file" name="cb-image">';
93
+ element += '<div class="cb-tools cb-tools--center">';
94
+ element += '<a class="cb-tools__btn cb-tools__btn--upload fa fa-camera" href="#'+ id + '"></a>';
95
+ element += '</div>';
96
+ element += '</div>';
97
+ element += '<figcaption class="cb-figcaption cb-text">Descrição da imagem</figcaption>';
98
+ element += '</figure>';
99
+
100
+ element += '<div class="cb-text">';
101
+ element += '<p>Lorem Ipsum é simplesmente uma simulação de texto da indústria tipográfica e de impressos, e vem sendo utilizado desde o século XVI, quando um impressor desconhecido pegou uma bandeja de tipos e os embaralhou para fazer um livro de modelos de tipos.</p>';
102
+ element += '</div>';
103
+
104
+ element += '</div>';
105
+
106
+ container.append(element);
107
+ addEventToInputFile(id);
108
+ scrollTo(id);
109
+ break;
110
+
111
+ case '3':
112
+ var element = '<div id="'+ id + '" class="cb-content">';
113
+
114
+ element += '<div class="cb-tools">';
115
+ element += '<a class="cb-tools__btn cb-tools__btn--move fa fa-arrows" href="#"></a>';
116
+ element += '<a class="cb-tools__btn cb-tools__btn--delete fa fa-trash" href="#'+ id + '"></a>';
117
+ element += '</div>';
118
+
119
+ element += '<figure class="cb-figure cb-figure--right">';
120
+ element += '<div class="cb-figure__clip">';
121
+ element += '<%= image_tag('cb-image-default.jpg') %>';
122
+ element += '<input id="'+ id +'" data-position="right" class="filePicker cb-tools__input cb-tools__input--upload" type="file" name="cb-image">';
123
+ element += '<div class="cb-tools cb-tools--center">';
124
+ element += '<a class="cb-tools__btn cb-tools__btn--upload fa fa-camera" href="#'+ id + '"></a>';
125
+ element += '</div>';
126
+ element += '</div>';
127
+ element += '<figcaption class="cb-figcaption cb-text">Descrição da imagem</figcaption>';
128
+ element += '</figure>';
129
+
130
+
131
+ element += '<div class="cb-text">';
132
+ element += '<p>Lorem Ipsum é simplesmente uma simulação de texto da indústria tipográfica e de impressos, e vem sendo utilizado desde o século XVI, quando um impressor desconhecido pegou uma bandeja de tipos e os embaralhou para fazer um livro de modelos de tipos.</p>';
133
+ element += '</div>';
134
+
135
+ element += '</div>';
136
+
137
+ container.append(element);
138
+ addEventToInputFile(id);
139
+ scrollTo(id);
140
+ break;
141
+
142
+ case '4':
143
+ var element = '<div id="'+ id + '" class="cb-content">';
144
+
145
+ element += '<div class="cb-tools">';
146
+ element += '<a class="cb-tools__btn cb-tools__btn--move fa fa-arrows" href="#"></a>';
147
+ element += '<a class="cb-tools__btn cb-tools__btn--delete fa fa-trash" href="#'+ id + '"></a>';
148
+ element += '</div>';
149
+
150
+ element += '<figure class="cb-figure cb-figure--center">';
151
+ element += '<div class="cb-figure__clip">';
152
+ element += '<%= image_tag('cb-image-default.jpg') %>';
153
+ element += '<input id="'+ id +'" data-position="center" class="filePicker cb-tools__input cb-tools__input--upload" type="file" name="cb-image">';
154
+ element += '<div class="cb-tools cb-tools--center">';
155
+ element += '<a class="cb-tools__btn cb-tools__btn--upload fa fa-camera" href="#'+ id + '"></a>';
156
+ element += '</div>';
157
+ element += '</div>';
158
+ element += '<figcaption class="cb-figcaption cb-text">Descrição da imagem</figcaption>';
159
+ element += '</figure>';
160
+
161
+ element += '</div>';
162
+
163
+ container.append(element);
164
+ addEventToInputFile(id);
165
+ scrollTo(id);
166
+ break;
167
+
168
+ case '5':
169
+ var element = '<div id="'+ id + '" class="cb-content">';
170
+
171
+ element += '<div class="cb-tools">';
172
+ element += '<a class="cb-tools__btn cb-tools__btn--move fa fa-arrows" href="#"></a>';
173
+ element += '<a class="cb-tools__btn cb-tools__btn--delete fa fa-trash" href="#'+ id + '"></a>';
174
+ element += '</div>';
175
+
176
+ element += '<div class="cb-video cb-video--center">';
177
+ element += '<iframe id="'+ id +'" src="" frameborder="0" allowfullscreen></iframe>';
178
+ element += '<div class="cb-tools cb-tools--center">';
179
+ element += '<a class="cb-tools__btn cb-tools__btn--upload cb-tools__btn--youtube fa fa-youtube-play" href="#'+ id + '"></a>';
180
+ element += '</div>';
181
+ element += '</div>';
182
+
183
+ element += '</div>';
184
+
185
+ container.append(element);
186
+ addEventToInputFile(id);
187
+ scrollTo(id);
188
+ break;
189
+
190
+ default:
191
+ };
192
+
193
+ activeMediumEditor();
194
+ });
195
+
196
+ // scroll to
197
+ var scrollTo = function(id) {
198
+ if(id) {
199
+ $('html, body').animate({
200
+ scrollTop: $('#' + id).offset().top
201
+ }, 400);
202
+ }
203
+ };
204
+
205
+ // add event on input file
206
+ var addEventToInputFile = function(id) {
207
+ $('#' + id).on('change', fileSelectAndUpload);
208
+ };
209
+
210
+ // upload file via ajax
211
+ var fileSelectAndUpload = function(evt) {
212
+ var file = evt.target.files[0];
213
+
214
+ if(file) {
215
+ var formData = new FormData();
216
+ formData.append('content_builder_image', file);
217
+
218
+ $.ajax({
219
+ url: 'create_images',
220
+ data: formData,
221
+ cache: false,
222
+ contentType: false,
223
+ processData: false,
224
+ type: 'PUT',
225
+ beforeSend: function() {
226
+ $('#' + evt.target.id).find('figure').append('<div class="cb-loading"></div>');
227
+ $('.cb-tools--center').addClass('cb-tools--disabled');
228
+ },
229
+ complete: function(){
230
+ $('.cb-loading').remove();
231
+ $('.cb-tools--center').removeClass('cb-tools--disabled');
232
+ }
233
+ }).done(function(e) {
234
+ var p = evt.target.getAttribute('data-position');
235
+ $('#' + evt.target.id).find('img').attr('src', getImageOfPosition(p, e));
236
+ }).fail(function(e) {
237
+ alert('error: ' + e);
238
+ });
239
+ }
240
+ };
241
+
242
+ // get image of position
243
+ var getImageOfPosition = function(position, e) {
244
+ switch(position) {
245
+ case 'left':
246
+ case 'right':
247
+ return e.image.left_or_right.url;
248
+ break;
249
+
250
+ case 'center':
251
+ return e.image.center.url;
252
+ break;
253
+ };
254
+ };
255
+
256
+ // generate random id
257
+ var generateID = function() {
258
+ return '_' + Math.random().toString(36).substr(2, 9);
259
+ };
260
+
261
+ // active medium editor plugin
262
+ var activeMediumEditor = function() {
263
+ var editor = new MediumEditor('.cb-text', {
264
+ placeholder: {
265
+ text: '',
266
+ hideOnClick: true
267
+ },
268
+
269
+ toolbar: {
270
+ buttons: ['bold', 'italic', 'underline', 'anchor']
271
+ },
272
+
273
+ anchor: {
274
+ placeholderText: 'Ex: http://site.com'
275
+ },
276
+
277
+ anchorPreview: false,
278
+
279
+ paste: {
280
+ cleanPastedHTML: true
281
+ }
282
+ });
283
+ };
284
+
285
+ // parse url by youtube using expression regular
286
+ var youtubeParser = function(url) {
287
+ var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
288
+ var match = url.match(regExp);
289
+
290
+ if(match && match[7].length == 11) {
291
+ return b = match[7];
292
+ } else {
293
+ alert('Ops! Você não informou uma url válida.');
294
+ }
295
+ };