slickr_cms 0.5.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +385 -0
- data/Rakefile +36 -0
- data/app/assets/config/slickr_manifest.js +0 -0
- data/app/assets/javascripts/slickr/slickr_javascript.js +19 -0
- data/app/assets/stylesheets/slickr/active_admin_reorderable/main.scss +39 -0
- data/app/assets/stylesheets/slickr/active_skin/_comments.scss +3 -0
- data/app/assets/stylesheets/slickr/active_skin/_custom_wrapper_breadcrumbs.scss +9 -0
- data/app/assets/stylesheets/slickr/active_skin/_dashboard.scss +49 -0
- data/app/assets/stylesheets/slickr/active_skin/_elements.scss +51 -0
- data/app/assets/stylesheets/slickr/active_skin/_filter_bar.scss +1 -0
- data/app/assets/stylesheets/slickr/active_skin/_fonts.scss +4 -0
- data/app/assets/stylesheets/slickr/active_skin/_form_elements.scss +122 -0
- data/app/assets/stylesheets/slickr/active_skin/_header.scss +49 -0
- data/app/assets/stylesheets/slickr/active_skin/_image_cropper.scss +247 -0
- data/app/assets/stylesheets/slickr/active_skin/_image_editor.scss +17 -0
- data/app/assets/stylesheets/slickr/active_skin/_image_gallery.scss +147 -0
- data/app/assets/stylesheets/slickr/active_skin/_input-moment.css +1 -0
- data/app/assets/stylesheets/slickr/active_skin/_loader.scss +69 -0
- data/app/assets/stylesheets/slickr/active_skin/_logged_in.scss +86 -0
- data/app/assets/stylesheets/slickr/active_skin/_page_editing.scss +78 -0
- data/app/assets/stylesheets/slickr/active_skin/_page_tree.scss +54 -0
- data/app/assets/stylesheets/slickr/active_skin/_resource_view.scss +28 -0
- data/app/assets/stylesheets/slickr/active_skin/_split_display_with_image.scss +58 -0
- data/app/assets/stylesheets/slickr/active_skin/_utility_nav.scss +8 -0
- data/app/assets/stylesheets/slickr/active_skin/_variables.scss +26 -0
- data/app/assets/stylesheets/slickr/active_skin/active_skin.scss +19 -0
- data/app/assets/stylesheets/slickr/active_skin/megadraft_plugins.scss +3 -0
- data/app/assets/stylesheets/slickr/megadraft/_block.scss +183 -0
- data/app/assets/stylesheets/slickr/megadraft/_dropdown.scss +74 -0
- data/app/assets/stylesheets/slickr/megadraft/_media.scss +26 -0
- data/app/assets/stylesheets/slickr/megadraft/_modal.scss +112 -0
- data/app/assets/stylesheets/slickr/megadraft/_sidebar.scss +101 -0
- data/app/assets/stylesheets/slickr/megadraft/_toolbar.scss +145 -0
- data/app/assets/stylesheets/slickr/megadraft/_typography.scss +94 -0
- data/app/assets/stylesheets/slickr/megadraft/megadraft.scss +21 -0
- data/app/assets/stylesheets/slickr/react_modal/main.scss +73 -0
- data/app/assets/stylesheets/slickr/react_popup/main.scss +188 -0
- data/app/assets/stylesheets/slickr/react_select/_control.scss +271 -0
- data/app/assets/stylesheets/slickr/react_select/_menu.scss +70 -0
- data/app/assets/stylesheets/slickr/react_select/_mixins.scss +45 -0
- data/app/assets/stylesheets/slickr/react_select/_multi.scss +90 -0
- data/app/assets/stylesheets/slickr/react_select/_select.scss +62 -0
- data/app/assets/stylesheets/slickr/react_select/_spinner.scss +21 -0
- data/app/assets/stylesheets/slickr/react_select/default.scss +6 -0
- data/app/assets/stylesheets/slickr/slickr_styles.scss +6 -0
- data/app/controllers/pages_controller.rb +24 -0
- data/app/controllers/slickr/engine_controller.rb +8 -0
- data/app/decorators/slickr/page_decorator.rb +41 -0
- data/app/helpers/active_admin/dashboard_helper.rb +34 -0
- data/app/helpers/slickr_helper.rb +100 -0
- data/app/models/activeadmin_settings_cached/model.rb +25 -0
- data/app/models/application_record.rb +3 -0
- data/app/models/draftjs_exporter/entities/standard_image.rb +14 -0
- data/app/models/draftjs_exporter/entities/target_blank_link.rb +17 -0
- data/app/models/draftjs_exporter/entities/vimeo.rb +8 -0
- data/app/models/draftjs_exporter/entities/you_tube.rb +8 -0
- data/app/models/draftjs_exporter/generators/vimeo_generator.rb +13 -0
- data/app/models/draftjs_exporter/generators/you_tube_generator.rb +13 -0
- data/app/models/slickr.rb +5 -0
- data/app/models/slickr/event_log.rb +8 -0
- data/app/models/slickr/image.rb +64 -0
- data/app/models/slickr/page.rb +130 -0
- data/app/models/slickr/page/draft.rb +13 -0
- data/app/models/slickr/setting.rb +9 -0
- data/app/models/slickr/slickr_admin_user.rb +35 -0
- data/app/uploaders/slickr_avatar_uploader.rb +33 -0
- data/app/uploaders/slickr_image_uploader.rb +80 -0
- data/app/views/admin/dashboard/_dashboard.html.erb +38 -0
- data/app/views/admin/form/_text_area_helper.html.arb +9 -0
- data/app/views/admin/slickr_images/_form.html.erb +3 -0
- data/app/views/admin/slickr_images/_gallery.html.erb +3 -0
- data/app/views/admin/slickr_pages/_dashboard.html.erb +3 -0
- data/app/views/admin/slickr_pages/_edit.html.erb +20 -0
- data/app/views/admin/slickr_pages/_form.html.erb +64 -0
- data/app/views/admin/slickr_settings/_index.html.erb +22 -0
- data/app/views/admin/users/_show.html.erb +24 -0
- data/app/views/layouts/partials/_slickr_head.html.erb +28 -0
- data/app/views/layouts/partials/_svg-map.html +1 -0
- data/app/views/vimeo/iframe.html.erb +1 -0
- data/app/views/you_tube/iframe.html.erb +1 -0
- data/config/initializers/active_admin.rb +5 -0
- data/config/initializers/active_admin_settings_cached.rb +3 -0
- data/config/initializers/paper_trail.rb +1 -0
- data/config/locales/dashboard.en.yml +6 -0
- data/config/locales/devise.en.yml +64 -0
- data/config/locales/event_logs.en.yml +10 -0
- data/config/locales/slickr_image.yml +6 -0
- data/config/locales/slickr_page.en.yml +6 -0
- data/config/routes.rb +32 -0
- data/db/migrate/20171123225335_create_slickr_pages.rb +32 -0
- data/db/migrate/20171124081428_change_page_tree_structure.rb +8 -0
- data/db/migrate/20171124083546_create_versions.rb +80 -0
- data/db/migrate/20171124090607_add_object_changes_to_versions.rb +9 -0
- data/db/migrate/20171124090700_add_meta_data_to_versions.rb +8 -0
- data/db/migrate/20171124093204_create_slickr_event_logs.rb +13 -0
- data/db/migrate/20171124103352_change_slickr_pages_page_id_attribute.rb +5 -0
- data/db/migrate/20171124113241_create_slickr_images.rb +11 -0
- data/db/migrate/20171129144523_add_roles_names_and_avatars_to_admin_users.rb +10 -0
- data/db/migrate/20171129144524_add_header_image_to_slickr_pages.rb +5 -0
- data/db/migrate/20171129144524_add_subheader_to_slickr_pages.rb +5 -0
- data/db/migrate/20171129144525_rename_slickr_pages_og_title_2_and_og_description_2.rb +6 -0
- data/db/migrate/20180315001123_create_slickr_settings.rb +17 -0
- data/db/migrate/20180319134446_rename_slickr_pages_meta_title.rb +8 -0
- data/lib/generators/slickr/install_generator.rb +298 -0
- data/lib/generators/slickr/templates/ability.rb +23 -0
- data/lib/generators/slickr/templates/active_admin_no_blank_slate.rb +22 -0
- data/lib/generators/slickr/templates/active_admin_svg_map.rb +20 -0
- data/lib/generators/slickr/templates/custom_webpack.js +9 -0
- data/lib/generators/slickr/templates/environment.js +34 -0
- data/lib/generators/slickr/templates/javascript_extensions/page_edit/actions/additional_actions.js +22 -0
- data/lib/generators/slickr/templates/javascript_extensions/page_edit/additional_megadraft_actions.js +7 -0
- data/lib/generators/slickr/templates/javascript_extensions/page_edit/additional_megadraft_decorators.js +11 -0
- data/lib/generators/slickr/templates/javascript_extensions/page_edit/components/content/additional_entity_inputs.js +7 -0
- data/lib/generators/slickr/templates/javascript_extensions/page_edit/components/content/editor_state_change.js +14 -0
- data/lib/generators/slickr/templates/javascript_extensions/page_edit/containers/additional_prop_types.js +7 -0
- data/lib/generators/slickr/templates/javascript_extensions/page_edit/decorators/pdf_link_component.jsx +13 -0
- data/lib/generators/slickr/templates/javascript_extensions/page_edit/entity_inputs/pdf_link_input.jsx +81 -0
- data/lib/generators/slickr/templates/javascript_extensions/page_edit/plugins/plugin_list.js +5 -0
- data/lib/generators/slickr/templates/javascript_extensions/page_edit/reducers/additional_reducers.js +8 -0
- data/lib/generators/slickr/templates/javascript_extensions/page_edit/reducers/loaded_pdfs.js +11 -0
- data/lib/generators/slickr/templates/migrations/add_header_image_to_slickr_pages.rb +5 -0
- data/lib/generators/slickr/templates/migrations/add_meta_data_to_versions.rb +8 -0
- data/lib/generators/slickr/templates/migrations/add_object_changes_to_versions.rb +9 -0
- data/lib/generators/slickr/templates/migrations/add_roles_names_and_avatars_to_admin_users.rb +10 -0
- data/lib/generators/slickr/templates/migrations/add_subheader_to_slickr_pages.rb +5 -0
- data/lib/generators/slickr/templates/migrations/change_page_tree_structure.rb +8 -0
- data/lib/generators/slickr/templates/migrations/change_slickr_pages_page_id_attribute.rb +5 -0
- data/lib/generators/slickr/templates/migrations/create_slickr_event_logs.rb +13 -0
- data/lib/generators/slickr/templates/migrations/create_slickr_images.rb +11 -0
- data/lib/generators/slickr/templates/migrations/create_slickr_pages.rb +32 -0
- data/lib/generators/slickr/templates/migrations/create_slickr_settings.rb +17 -0
- data/lib/generators/slickr/templates/migrations/create_versions.rb +80 -0
- data/lib/generators/slickr/templates/migrations/rename_slickr_pages_meta_title.rb +5 -0
- data/lib/generators/slickr/templates/migrations/rename_slickr_pages_og_title_2_and_og_description_2.rb +6 -0
- data/lib/generators/slickr/templates/page.rb +54 -0
- data/lib/generators/slickr/templates/setting.yml +26 -0
- data/lib/generators/slickr/templates/slickr.yml +15 -0
- data/lib/generators/slickr/templates/slickr_page_template.html.erb +3 -0
- data/lib/slickr.rb +5 -0
- data/lib/slickr/admin/admin_users.rb +77 -0
- data/lib/slickr/admin/dashboard.rb +13 -0
- data/lib/slickr/admin/drafts.rb +10 -0
- data/lib/slickr/admin/images.rb +87 -0
- data/lib/slickr/admin/inputs/file_modified_input.rb +9 -0
- data/lib/slickr/admin/pages.rb +133 -0
- data/lib/slickr/admin/setting.rb +10 -0
- data/lib/slickr/engine.rb +45 -0
- data/lib/slickr/version.rb +3 -0
- data/lib/tasks/slickr_tasks.rake +4 -0
- metadata +446 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e78a8814f2bbb933cb0ac0d41434a28a1d6b61e0
|
4
|
+
data.tar.gz: 7534522461e070a59694829facd64b856e10464a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7d349b150bde3218bbb67e6a39183af0ab2b2465252202ab708bf97ee9db8003ae890e693dbe66be85c4e0ba9fe5fa00cd493b8b2cde9ebfef9156174d6405e4
|
7
|
+
data.tar.gz: 4e52a365817f45e48563c485a3fd12ddbe42ee774e2f29fd9c6a9656bd45d64b7718706fd4960d5253ed97928bfd5b15af00c9dc41fdc24f9ea1b176d5746baa
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,385 @@
|
|
1
|
+
# Slickr
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
[Sitemap configuration](docs/sitemap.md)
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
How to use my plugin.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
Add these lines to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'active_admin_slickr'
|
14
|
+
gem 'slickr'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
```bash
|
19
|
+
bundle
|
20
|
+
```
|
21
|
+
|
22
|
+
Or install them yourself as:
|
23
|
+
```bash
|
24
|
+
gem install active_admin_slickr
|
25
|
+
gem install slickr
|
26
|
+
```
|
27
|
+
|
28
|
+
## Migrations
|
29
|
+
|
30
|
+
After installing the gem run:
|
31
|
+
|
32
|
+
```bash
|
33
|
+
rake db:migrate
|
34
|
+
```
|
35
|
+
|
36
|
+
## CMS
|
37
|
+
|
38
|
+
If you don't already have webpacker installed run:
|
39
|
+
|
40
|
+
Add this line to your application's Gemfile:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
gem 'webpacker', '~> 3.0.2'
|
44
|
+
```
|
45
|
+
|
46
|
+
And then execute:
|
47
|
+
```bash
|
48
|
+
$ bundle
|
49
|
+
```
|
50
|
+
|
51
|
+
Or install it yourself as:
|
52
|
+
```bash
|
53
|
+
$ gem install webpacker
|
54
|
+
```
|
55
|
+
|
56
|
+
Then install webpacker:
|
57
|
+
```bash
|
58
|
+
bundle exec rails Webpacker:install
|
59
|
+
```
|
60
|
+
|
61
|
+
Finally, to use Webpacker with React:
|
62
|
+
```bash
|
63
|
+
bundle exec rails webpacker:install:react
|
64
|
+
```
|
65
|
+
|
66
|
+
## Generators
|
67
|
+
|
68
|
+
```bash
|
69
|
+
rails g slickr:install
|
70
|
+
```
|
71
|
+
|
72
|
+
then
|
73
|
+
|
74
|
+
```bash
|
75
|
+
yarn install
|
76
|
+
```
|
77
|
+
|
78
|
+
## Stylesheets
|
79
|
+
|
80
|
+
Firstly, please comment out the default Active Admin stylesheets.
|
81
|
+
|
82
|
+
```css
|
83
|
+
// Active Admin's got SASS!
|
84
|
+
// @import "active_admin/mixins";
|
85
|
+
// @import "active_admin/base";
|
86
|
+
```
|
87
|
+
|
88
|
+
Then add the following in `active_admin.scss`:
|
89
|
+
|
90
|
+
```css
|
91
|
+
@import 'active_admin_slickr';
|
92
|
+
@import 'slickr/slickr_styles';
|
93
|
+
```
|
94
|
+
|
95
|
+
## Javascript
|
96
|
+
- In the `active_admin.js` file, you require:
|
97
|
+
|
98
|
+
```javascript
|
99
|
+
//= require active_admin/base
|
100
|
+
//= require active_admin_slickr
|
101
|
+
//= require slickr/slickr_javascript
|
102
|
+
```
|
103
|
+
|
104
|
+
## Roles
|
105
|
+
|
106
|
+
You will have some basic default roles added to your AdminUser model which you
|
107
|
+
can easily add to. Roles are managed by CanCanCan and can be altered in the
|
108
|
+
Ability model
|
109
|
+
|
110
|
+
## Admin User
|
111
|
+
|
112
|
+
The AdminUser model is already setup through this gem so you can remove your own
|
113
|
+
version. If however you need to extend it you can still create the ```admin_users.rb```
|
114
|
+
file within the ```admin``` folder but set it up like so:
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
ActiveAdmin.register AdminUser, as: "Users" do
|
118
|
+
end
|
119
|
+
```
|
120
|
+
|
121
|
+
## Model Ordering
|
122
|
+
|
123
|
+
Slickr uses acts_as_list for ordering. In order to use it in you app you must first
|
124
|
+
add a ```position``` column to the require table:
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
rails g migration AddPositionToAdminUser position:integer
|
128
|
+
rake db:migrate
|
129
|
+
```
|
130
|
+
|
131
|
+
Then add acts_as_list to your model (and also a default scope if you need it):
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
class AdminUser < ActiveRecord::Base
|
135
|
+
acts_as_list
|
136
|
+
default_scope { order(position: :asc) }
|
137
|
+
end
|
138
|
+
```
|
139
|
+
|
140
|
+
In your Active Admin model you then need to add the following:
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
ActiveAdmin.register AdminUser do
|
144
|
+
config.sort_order = 'position_asc'
|
145
|
+
config.paginate = false
|
146
|
+
reorderable
|
147
|
+
|
148
|
+
...
|
149
|
+
|
150
|
+
index as: :reorderable_table do
|
151
|
+
...
|
152
|
+
end
|
153
|
+
|
154
|
+
...
|
155
|
+
end
|
156
|
+
```
|
157
|
+
|
158
|
+
That's it, you now have reorderable tables.
|
159
|
+
|
160
|
+
## Extending Megadraft
|
161
|
+
|
162
|
+
In text editing mode, Megadraft has a range of options such as bold, italic,
|
163
|
+
bullet list, etc. With this editor there is also the ability to add icons to
|
164
|
+
the toolbar that can display info from your models.
|
165
|
+
|
166
|
+
When you run the generator, you will see that a new folder has been added to
|
167
|
+
the ``` app/javascript ``` folder called ``` slickr_extensions ```. Additionally,
|
168
|
+
a new model is added under ``` app/models/slickr/page.rb ```.
|
169
|
+
|
170
|
+
In ``` app/models/slickr/page.rb ``` you can add to ``` additional_page_edit_paths ```
|
171
|
+
to include new methods to get info from a model. There is currently an example
|
172
|
+
method ``` admin_user_index_path ``` which requests the admin index path and has
|
173
|
+
params of ``` type: 'megadraft_admins') ```.
|
174
|
+
|
175
|
+
When the icon is clicked in the Megadraft toolbar, this path will be requested
|
176
|
+
which requires the controller action to be added to Active Admin AdminUser. For
|
177
|
+
example add:
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
controller do
|
181
|
+
def index
|
182
|
+
if params[:type] == 'megadraft_admins'
|
183
|
+
@admins = AdminUser.all
|
184
|
+
index! do |format|
|
185
|
+
format.html { render :json => @admins.to_json }
|
186
|
+
end
|
187
|
+
else
|
188
|
+
index!
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
```
|
193
|
+
|
194
|
+
making sure the params match.
|
195
|
+
|
196
|
+
### Extending Redux store
|
197
|
+
|
198
|
+
In ``` slickr_extensions/page_edit/containers/additional_prop_types.js ``` the
|
199
|
+
propTypes are extended with our default but you can add to this as needed.
|
200
|
+
|
201
|
+
Next we need to handle state change which is done through ``` slickr_extensions/page_edit/reducers/additional_reducers.js ```. Again this is
|
202
|
+
based on our admins example and simply references a function that responds
|
203
|
+
to ``` LOAD_ADMINS ``` to get the payload from the admin controller we added above.
|
204
|
+
|
205
|
+
The action to trigger this state change is at ``` slickr_extensions/page_edit/actions/additional_actions.js ```.
|
206
|
+
|
207
|
+
### Custom Entities
|
208
|
+
|
209
|
+
See [Megadraft custom entities](https://github.com/globocom/megadraft/blob/master/docs/custom_entities.md)
|
210
|
+
for more info.
|
211
|
+
|
212
|
+
Megadraft ships with a default entity "LINK" and an according action in the toolbar that allows a user to type in an url. We are adding to it with "ADMIN_LINK" with an action that allows a user to select
|
213
|
+
an admin email. We extend the entity inputs from ``` slickr_extensions/page_edit/components/content/additional_entity_inputs.js ``` and
|
214
|
+
agin you can add more as needed.
|
215
|
+
|
216
|
+
In order to render the custom entities, we need to define decorators as seen
|
217
|
+
in ``` slickr_extensions/page_edit/actions/additional_actions.js ```. Upon
|
218
|
+
highlighting text in the Megadraft editor and then clicking the admin
|
219
|
+
icon in the Megadraft toolbar, componentWillMount() is fired which in
|
220
|
+
this case is used to signify a state change in Megadraft and passes ```editorState```
|
221
|
+
as "load_admins" which is handled in ``` slickr_extensions/page_edit/components/content/editor_state_change.js ```.
|
222
|
+
|
223
|
+
The action we setup above to load the admins is now fired and the render method
|
224
|
+
of entity input is called. This renders a drop down menu on the screen and an
|
225
|
+
array of admins with a value as a fake link and label of their email populates the drop down.
|
226
|
+
|
227
|
+
The value of ``` this.props.url ``` in
|
228
|
+
|
229
|
+
```javascript
|
230
|
+
<Select
|
231
|
+
name="form-field-name"
|
232
|
+
value={this.props.url}
|
233
|
+
options={admins}
|
234
|
+
onChange={this.onAdminChange}
|
235
|
+
/>
|
236
|
+
```
|
237
|
+
|
238
|
+
at this point is undefined but when an admin email is clicked, the rendering in
|
239
|
+
the editor is handled by ``` slickr_extensions/page_edit/decorators/admin_link_component.jsx ```.
|
240
|
+
The text you highlighted earlier is now wrapped with a link with an href of
|
241
|
+
the link you declared in the value of the drop down. The value of ``` this.props.url ```
|
242
|
+
is now the href value.
|
243
|
+
|
244
|
+
## Megadraft to HTML
|
245
|
+
|
246
|
+
The content generated by Megadraft needs to be converted to HTML to be displayed
|
247
|
+
in preview mode or in the front end. If you have added any custom entities you will
|
248
|
+
need to add to "DRAFTJS_CONFIG" in ``` app/models/slickr/page.rb ``` by adding
|
249
|
+
|
250
|
+
``` ruby
|
251
|
+
'ADMIN_LINK' => DraftjsExporter::Entities::Link.new(className: 'admin__link')
|
252
|
+
```
|
253
|
+
|
254
|
+
for our example in "entity_decorators".
|
255
|
+
|
256
|
+
### Page Layouts
|
257
|
+
|
258
|
+
For each page you create, you will select a page layout. We have included some
|
259
|
+
defaults in ``` app/models/slickr/page.rb ``` in the "LAYOUTS" constant but you
|
260
|
+
can remove or add as many as you like.
|
261
|
+
|
262
|
+
For each layout listed in "LAYOUTS" you will need a corresponding file
|
263
|
+
at ``` app/views/slickr_page_templates ``` with the same name like ``` contact.html.erb```
|
264
|
+
or ``` contact.slim ```.
|
265
|
+
|
266
|
+
The instance variable is accessed as ``` slickr_page``` and the megadraft content
|
267
|
+
as ``` raw content ```. So as a simple example the page could look as follows:
|
268
|
+
|
269
|
+
``` html
|
270
|
+
<h1><%= page["title"] %></h1>
|
271
|
+
<p><%= page["page_intro"] %></p>
|
272
|
+
<%= raw content %>
|
273
|
+
```
|
274
|
+
|
275
|
+
## Megadraft Text Area
|
276
|
+
|
277
|
+
Slickr enables the Megadraft editor to be used in text area inputs which normal
|
278
|
+
Active Admin resources. Below is an example for how to have a mix of normal
|
279
|
+
text area fields and megadraft text areas:
|
280
|
+
|
281
|
+
```ruby
|
282
|
+
form do |f|
|
283
|
+
f.inputs do
|
284
|
+
f.input :title
|
285
|
+
f.input :body_normal,
|
286
|
+
as: :text
|
287
|
+
render 'admin/form/text_area_helper', f: f, field: :body_megadraft
|
288
|
+
f.input :body_megadraft,
|
289
|
+
as: :text
|
290
|
+
end
|
291
|
+
f.actions
|
292
|
+
end
|
293
|
+
```
|
294
|
+
|
295
|
+
### View Helper
|
296
|
+
|
297
|
+
In order to use the DraftJS output from Megadraft there is a helper available to
|
298
|
+
use in your views:
|
299
|
+
|
300
|
+
```html
|
301
|
+
<%= draftjs_to_html(@slickr_page, :body_megadraft) %>
|
302
|
+
```
|
303
|
+
|
304
|
+
replacing the instance variable with that generated in your controller and the
|
305
|
+
second argument with whatever field has the DraftJS content.
|
306
|
+
|
307
|
+
|
308
|
+
## Developing
|
309
|
+
|
310
|
+
During development you can use a local copy of the engine in your app and there
|
311
|
+
are 2 options for doing this. One thing you'll have to do first is you change the
|
312
|
+
slickr.yml file in the config folder. Comment out:
|
313
|
+
|
314
|
+
```bash
|
315
|
+
slickr: dist
|
316
|
+
```
|
317
|
+
|
318
|
+
and uncomment
|
319
|
+
|
320
|
+
```bash
|
321
|
+
slickr: package/slickr/packs
|
322
|
+
```
|
323
|
+
|
324
|
+
### Option 1
|
325
|
+
|
326
|
+
In the main app, package.json file, replace:
|
327
|
+
|
328
|
+
```
|
329
|
+
"slickr": "git+https://github.com/primate-inc/slickr#master"
|
330
|
+
```
|
331
|
+
|
332
|
+
with a local copy like
|
333
|
+
|
334
|
+
```
|
335
|
+
"slickr": "file:/Users/primate/Documents/Projects/slickr"
|
336
|
+
```
|
337
|
+
|
338
|
+
and use the local copy of the engine to load into the main apps node_modules.
|
339
|
+
This works well if you need to make changes to the codebase that does not
|
340
|
+
involve the webpacker code.
|
341
|
+
|
342
|
+
### Option 2
|
343
|
+
|
344
|
+
To live reload your changes on the local engine rather than loading a compiled
|
345
|
+
version into the main app you can run the following from the engine:
|
346
|
+
|
347
|
+
```bash
|
348
|
+
yarn install
|
349
|
+
```
|
350
|
+
|
351
|
+
to install any missing packages. Then
|
352
|
+
|
353
|
+
```bash
|
354
|
+
yarn link
|
355
|
+
```
|
356
|
+
|
357
|
+
Now in your main app type
|
358
|
+
|
359
|
+
```bash
|
360
|
+
yarn link slickr
|
361
|
+
```
|
362
|
+
|
363
|
+
The local engine now takes precedence over the version in the main app node_modules
|
364
|
+
folder and when you run the dev server in the main app with
|
365
|
+
|
366
|
+
```bash
|
367
|
+
./bin/webpack-dev-server
|
368
|
+
```
|
369
|
+
|
370
|
+
any changes you make to your engine react code will be live reloaded.
|
371
|
+
|
372
|
+
When you're done you can type
|
373
|
+
|
374
|
+
```bash
|
375
|
+
yarn unlink slickr
|
376
|
+
```
|
377
|
+
|
378
|
+
from the main app but note that you'll have to ``` yarn install ``` again as the
|
379
|
+
slickr node module will be removed.
|
380
|
+
|
381
|
+
## Contributing
|
382
|
+
Contribution directions go here.
|
383
|
+
|
384
|
+
## License
|
385
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Slickr'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'test'
|
31
|
+
t.pattern = 'test/**/*_test.rb'
|
32
|
+
t.verbose = false
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
task default: :test
|