rails_admin_content_builder 1.0.3

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 (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,238 @@
1
+ @import 'medium-editor/medium-editor';
2
+ @import 'medium-editor/themes/bootstrap';
3
+
4
+ .cb-snippet {
5
+ position: fixed;
6
+ z-index: 100;
7
+ top: 50px;
8
+ bottom: 110px;
9
+ right: 0;
10
+
11
+ width: 180px;
12
+
13
+ padding: 20px;
14
+
15
+ background: #f8f8f8;
16
+ border-left: solid 1px rgba(0,0,0,.1);
17
+
18
+ overflow: hidden;
19
+ overflow-y: scroll;
20
+ }
21
+
22
+ .cb-snippet__btn {
23
+ display: block;
24
+ text-decoration: none;
25
+ margin-bottom: 20px;
26
+
27
+ transition: box-shadow .1s ease;
28
+
29
+ &:hover {
30
+ box-shadow: 0 0 0 2px rgba(0,0,0,.1);
31
+ }
32
+ }
33
+
34
+ .cb-snippet__image {
35
+ width: 100%;
36
+ }
37
+
38
+
39
+ .cb-controls {
40
+ position: fixed;
41
+ z-index: 100;
42
+ bottom: 0;
43
+ right: 0;
44
+
45
+ width: 180px;
46
+
47
+ padding: 20px;
48
+
49
+ background: #f8f8f8;
50
+ border-top: solid 1px rgba(0,0,0,.1);
51
+ border-left: solid 1px rgba(0,0,0,.1);
52
+ }
53
+
54
+
55
+ .cb-tools {
56
+ position: absolute;
57
+ z-index: 300;
58
+ top: 0;
59
+ left: -40px;
60
+
61
+ border-radius: .4rem;
62
+ background: darken(#fff, 7%);
63
+
64
+ overflow: hidden;
65
+ }
66
+
67
+ .cb-tools--center {
68
+ top: 50%;
69
+ left: 50%;
70
+ transform: translateX(-50%) translateY(-50%);
71
+
72
+ .cb-tools__btn {
73
+ display: inline-block;
74
+ }
75
+ }
76
+
77
+ .cb-tools--disabled {
78
+ z-index: 100;
79
+ }
80
+
81
+ .cb-tools__btn {
82
+ display: block;
83
+
84
+ font-size: 12px;
85
+ text-align: center;
86
+ text-transform: uppercase;
87
+
88
+ padding: 10px;
89
+
90
+ &:hover,
91
+ &:focus {
92
+ background: rgba(0,0,0,.05);
93
+ text-decoration: none;
94
+ }
95
+ }
96
+
97
+ .cb-tools__input {
98
+
99
+ }
100
+
101
+ .cb-tools__input--upload {
102
+ display: none !important;
103
+ }
104
+
105
+
106
+ .cb-container {
107
+ box-sizing: border-box;
108
+ padding: 0 220px 0 40px;
109
+ }
110
+
111
+ .cb-content {
112
+ position: relative;
113
+ max-width: 100%;
114
+ height: auto !important;
115
+
116
+ &:after {
117
+ visibility: hidden;
118
+ display: block;
119
+ font-size: 0;
120
+ content: " ";
121
+ clear: both;
122
+ height: 0;
123
+ }
124
+ }
125
+
126
+
127
+ .cb-text {
128
+ line-height: 1.6;
129
+
130
+ color: rgba(0,0,0,.7);
131
+ font-family: arial, sans-serif;
132
+ font-size: 16px;
133
+
134
+ margin-bottom: 30px;
135
+
136
+ p {
137
+ margin: 0 0 20px;
138
+
139
+ &:last-of-type {
140
+ margin: 0;
141
+ }
142
+ }
143
+ }
144
+
145
+ .cb-figure {
146
+ position: relative;
147
+ margin: 0 0 15px;
148
+
149
+ img {
150
+ width: 100%;
151
+ }
152
+ }
153
+
154
+ .cb-figure--left {
155
+ float: left;
156
+ width: 50%;
157
+ margin: 0 30px 20px 0;
158
+ }
159
+
160
+ .cb-figure--right {
161
+ float: right;
162
+ width: 50%;
163
+ margin: 0 0 20px 30px;
164
+ }
165
+
166
+ .cb-figure--center {
167
+ margin: 0 0 20px;
168
+ }
169
+
170
+ .cb-figure__clip {
171
+ position: relative;
172
+ }
173
+
174
+ .cb-figcaption {
175
+ margin: 6px 0 0;
176
+
177
+ color: rgba(0,0,0,.6);
178
+ font-size: 14px;
179
+
180
+ line-height: 1.4;
181
+ padding: 8px 14px;
182
+ background: rgba(0,0,0,.05);
183
+
184
+ p {
185
+ margin: 0;
186
+ }
187
+ }
188
+
189
+
190
+ .cb-video {
191
+ position: relative;
192
+ height: 0;
193
+ overflow: hidden;
194
+ padding-bottom: 56.25%;
195
+ background: image_url('cb-video-default.jpg') no-repeat center #e4e4e4;
196
+
197
+ iframe {
198
+ position: absolute;
199
+ width: 100%;
200
+ height: 100%;
201
+ vertical-align: middle;
202
+ }
203
+ }
204
+
205
+ .cb-video--center {
206
+ margin-bottom: 30px;
207
+ }
208
+
209
+
210
+ .cb-loading {
211
+ position: absolute;
212
+ z-index: 200;
213
+ top: 0;
214
+ left: 0;
215
+
216
+ width: 100%;
217
+ height: 100%;
218
+ background: image_url('cb-loading.svg') no-repeat center rgba(#fff, .95);
219
+ }
220
+
221
+
222
+ [contenteditable="true"] {
223
+ outline: none;
224
+
225
+ &:hover,
226
+ &:focus {
227
+ box-shadow: 0 0 0 1px rgba(0,0,0,.2);
228
+ }
229
+ }
230
+
231
+
232
+ .ui-sortable-placeholder {
233
+ margin: 20px 0;
234
+ height: 80px;
235
+
236
+ background: rgba(0,0,0,.05);
237
+ border: dashed 2px rgba(0,0,0,.05);
238
+ }
@@ -0,0 +1,19 @@
1
+ module RailsAdminContentBuilder
2
+ class ContentBuilderController < ::ApplicationController
3
+ def create_images
4
+ @content_builder = ContentBuilder.find(params[:id])
5
+ @image = @content_builder.content_builder_images.create(image: params[:content_builder_image])
6
+ if @image
7
+ render json: find_image(@image.id)
8
+ else
9
+ render json: @image.errors
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def find_image(id)
16
+ ContentBuilderImage.find(id).image.to_json
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ # Add ContentHelper in your Controller
2
+ #
3
+ # class PostsController < ApplicationController
4
+ # include RailsAdminContentBuilder::ContentBuilderHelpers
5
+ #
6
+ # def index
7
+ # end
8
+ # end
9
+ module RailsAdminContentBuilder
10
+ module ContentBuilderHelpers
11
+ # Return content Object
12
+ #
13
+ # @content = content_created
14
+ def content_created
15
+ RailsAdminContentBuilder::ContentBuilder
16
+ end
17
+
18
+ # Return all contents created
19
+ #
20
+ # @content = all_contents_created
21
+ def all_contents_created
22
+ RailsAdminContentBuilder::ContentBuilder.where(status: true)
23
+ end
24
+
25
+ # Return specific contents created by slug
26
+ #
27
+ # @content = find_content_created_by_slug('slug')
28
+ def find_content_created_by_slug(slug)
29
+ RailsAdminContentBuilder::ContentBuilder.where(status: true, slug: slug).first
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,27 @@
1
+ module RailsAdminContentBuilder
2
+ class ContentBuilder < ActiveRecord::Base
3
+ include SearchCop
4
+ extend FriendlyId
5
+
6
+ self.table_name = 'content_builders'
7
+
8
+ friendly_id :title, use: :slugged
9
+
10
+ validates :title, :date_publish, :content_builder_category, :written_by, presence: true
11
+
12
+ has_many :content_builder_images, inverse_of: :content_builder, dependent: :destroy
13
+ belongs_to :content_builder_category, inverse_of: :content_builders
14
+
15
+ search_scope :search do
16
+ attributes :title
17
+ end
18
+
19
+ def content_sanitized
20
+ white_list_sanitizer = Rails::Html::WhiteListSanitizer.new
21
+ white_list_sanitizer.sanitize(
22
+ self.content,
23
+ tags: %w(div b i a u p img figure figcaption a iframe),
24
+ attributes: %w(src class alt href allowfullscreen frameborder height width)).try(:html_safe)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ module RailsAdminContentBuilder
2
+ class ContentBuilderCategory < ActiveRecord::Base
3
+ extend FriendlyId
4
+ friendly_id :name, use: :slugged
5
+
6
+ self.table_name = 'content_builder_categories'
7
+
8
+ validates :name, presence: true
9
+
10
+ has_many :content_builders, inverse_of: :content_builder_category
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module RailsAdminContentBuilder
2
+ class ContentBuilderImage < ActiveRecord::Base
3
+ self.table_name = 'content_builder_images'
4
+
5
+ mount_uploader :image, ContentBuilderImageUploader
6
+
7
+ validates :image, presence: true
8
+ belongs_to :content_builder, inverse_of: :content_builder_images
9
+ end
10
+ end
File without changes
@@ -0,0 +1,42 @@
1
+ <%= stylesheet_link_tag 'rails_admin/content_builder', 'data-turbolinks-track' => false %>
2
+ <%= javascript_include_tag 'rails_admin/content_builder', 'data-turbolinks-track' => false %>
3
+
4
+ <div class="cb-snippet">
5
+ <%= link_to '#', class: 'cb-snippet__btn', data: {snippet: '1'} do %>
6
+ <%= image_tag 'cb-snippet-text.jpg', class: 'cb-snippet__image' %>
7
+ <% end %>
8
+
9
+ <%= link_to '#', class: 'cb-snippet__btn', data: {snippet: '2'} do %>
10
+ <%= image_tag 'cb-snippet-image-text.jpg', class: 'cb-snippet__image' %>
11
+ <% end %>
12
+
13
+ <%= link_to '#', class: 'cb-snippet__btn', data: {snippet: '3'} do %>
14
+ <%= image_tag 'cb-snippet-text-image.jpg', class: 'cb-snippet__image' %>
15
+ <% end %>
16
+
17
+ <%= link_to '#', class: 'cb-snippet__btn', data: {snippet: '4'} do %>
18
+ <%= image_tag 'cb-snippet-image.jpg', class: 'cb-snippet__image' %>
19
+ <% end %>
20
+
21
+ <%= link_to '#', class: 'cb-snippet__btn', data: {snippet: '5'} do %>
22
+ <%= image_tag 'cb-snippet-video.jpg', class: 'cb-snippet__image' %>
23
+ <% end %>
24
+ </div>
25
+
26
+ <%= simple_form_for rails_admin.content_builder_url(@abstract_model.to_param, id: @object.id), html: { class: 'cb-form' }, remote: false do |f| %>
27
+ <div class="cb-controls">
28
+ <%= f.button :submit, t('admin.actions.content_builder.button.save'), name: 'save', class: 'btn btn-block btn-primary' %>
29
+ <% if @object.status %>
30
+ <%= f.button :submit, t('admin.actions.content_builder.button.unpublish'), name: 'unpublish', class: 'btn btn-block btn-danger' %>
31
+ <% else %>
32
+ <%= f.button :submit, t('admin.actions.content_builder.button.publish'), name: 'publish', class: 'btn btn-block btn-success' %>
33
+ <% end %>
34
+ </div>
35
+
36
+ <div class="cb-container">
37
+ <%= @object.content.try(:html_safe) %>
38
+ </div>
39
+
40
+ <%= f.input :id, as: :hidden, :input_html => { :name => "id", :value => @object.id } %>
41
+ <%= f.input :content, as: :hidden, :input_html => { :name => "content", :id => "content", :value => @object.content } %>
42
+ <% end %>
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rails_admin_content_builder"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ Rails.application.config.assets.precompile += %w( cb-loading.svg )
2
+ Rails.application.config.assets.precompile += %w( cb-snippet-text.jpg )
3
+ Rails.application.config.assets.precompile += %w( cb-snippet-image-text.jpg )
4
+ Rails.application.config.assets.precompile += %w( cb-snippet-text-image.jpg )
5
+ Rails.application.config.assets.precompile += %w( cb-snippet-quote.jpg )
6
+ Rails.application.config.assets.precompile += %w( cb-snippet-quote-text.jpg )
7
+ Rails.application.config.assets.precompile += %w( cb-snippet-text-quote.jpg )
8
+ Rails.application.config.assets.precompile += %w( cb-snippet-image.jpg )
9
+ Rails.application.config.assets.precompile += %w( cb-snippet-video.jpg )
10
+ Rails.application.config.assets.precompile += %w( cb-image-default.jpg )
11
+ Rails.application.config.assets.precompile += %w( cb-video-default.jpg )
@@ -0,0 +1,17 @@
1
+ en:
2
+ admin:
3
+ actions:
4
+ content_builder:
5
+ title: "Create News"
6
+ menu: "Create New"
7
+ breadcrumb: "Create New"
8
+ delete_block: "Do you want to remove this content?"
9
+ success_save: "Successfully updated"
10
+ error_save: "Error updating"
11
+ written_by: "Writter By"
12
+ news_source: "News source"
13
+ summary: "Summary"
14
+ button:
15
+ save: "Save"
16
+ publish: "Publish"
17
+ unpublish: 'Unpublish'