simplec 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +308 -0
  4. data/Rakefile +36 -0
  5. data/app/assets/config/simplec_manifest.js +2 -0
  6. data/app/assets/fonts/simplec/summernote.eot +0 -0
  7. data/app/assets/fonts/simplec/summernote.ttf +0 -0
  8. data/app/assets/fonts/simplec/summernote.woff +0 -0
  9. data/app/assets/javascripts/simplec/application.js +13 -0
  10. data/app/assets/javascripts/simplec/summernote-config.js +82 -0
  11. data/app/assets/javascripts/simplec/summernote.js +7046 -0
  12. data/app/assets/stylesheets/simplec/application.css +15 -0
  13. data/app/assets/stylesheets/simplec/summernote.scss +691 -0
  14. data/app/constraints/simplec/subdomains.rb +23 -0
  15. data/app/controllers/simplec/application_controller.rb +9 -0
  16. data/app/controllers/simplec/pages_controller.rb +19 -0
  17. data/app/helpers/simplec/application_helper.rb +4 -0
  18. data/app/jobs/simplec/application_job.rb +4 -0
  19. data/app/mailers/simplec/application_mailer.rb +6 -0
  20. data/app/models/simplec/application_record.rb +5 -0
  21. data/app/models/simplec/embedded_image.rb +15 -0
  22. data/app/models/simplec/page.rb +203 -0
  23. data/app/models/simplec/subdomain.rb +30 -0
  24. data/app/views/simplec/fields/_editor.html.erb +5 -0
  25. data/app/views/simplec/fields/_file.html.erb +16 -0
  26. data/app/views/simplec/fields/_image.html.erb +16 -0
  27. data/app/views/simplec/fields/_string.html.erb +4 -0
  28. data/app/views/simplec/fields/_text.html.erb +4 -0
  29. data/app/views/simplec/pages/show.html.erb +2 -0
  30. data/config/routes.rb +8 -0
  31. data/db/migrate/20170809204353_create_simplec_pages.rb +30 -0
  32. data/db/migrate/20170809204511_create_simplec_subdomains.rb +12 -0
  33. data/db/migrate/20170809210304_create_simplec_embedded_images.rb +15 -0
  34. data/lib/simplec/action_controller/extensions.rb +56 -0
  35. data/lib/simplec/action_view/helper.rb +118 -0
  36. data/lib/simplec/embedded_image_actions.rb +37 -0
  37. data/lib/simplec/engine.rb +18 -0
  38. data/lib/simplec/version.rb +3 -0
  39. data/lib/simplec.rb +5 -0
  40. data/lib/tasks/simplec_tasks.rake +4 -0
  41. metadata +41 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f687b8e569576f0ede5b259472437ff8108761a
4
- data.tar.gz: 1d9a9fa05e066db3fbcb1e43dd4d40b4f27cf13e
3
+ metadata.gz: f95b9fb5eef66eaf27ab18d642ee76f5ea67a547
4
+ data.tar.gz: 05505f307bf86ffd6afd16545f5b6a5396a708da
5
5
  SHA512:
6
- metadata.gz: 86fee8f0499aa2d98e8bc69e1d964b592538b15cfa36413dd65a0a2509c16edc396f0d0ce0e887949c708c4c64b6eff3c8c6a5472a3a5b86c5630796f829146c
7
- data.tar.gz: b99fd88d68b73d27feab77a5c600317586fef2ce91a0158820b04113ee36df715f1d756220693d18edfea897d48980441e94a0aba39efff7717d1163b7cb8516
6
+ metadata.gz: c4cadd40978e45f0f20c8759226bef7ba6d6c2564de022ba589bfd36cf6af9a0520c40979b90c8aa9c764eb68113eaa7353e6da576a4f01bb70d7f291895325e
7
+ data.tar.gz: 88d5a6034a54698c229887b0ab8165b5c6a0ef9fe309440a63895089cd53726cad136f8015173d597217154fab58d243a9f2b88dea95d35d62e9919dbe113156
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Matt Smith
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,308 @@
1
+ # Simplec
2
+
3
+ ### A CMS for developers, built by developers.
4
+
5
+ This gem handles all of the rote parts of a CMS, but gets out of the way for
6
+ everything else. In Rails it is easy to build things from scratch, but it is
7
+ a waste of resources to build again and again. This library is an attempt to
8
+ get all of the good parts of a CMS without the baggage of a CMS that takes
9
+ over the entire ecosystem.
10
+
11
+ ## Dependencies
12
+ - rails >= 5.0.5
13
+
14
+ - pg >= 0.21.0; postgres >= 9.5
15
+
16
+ We hate dependencies, but postgres is just too good. We use it for search
17
+ and JSONB.
18
+
19
+ - imagemagick
20
+
21
+ For image processing.
22
+
23
+ - dragonfly
24
+
25
+ We still hate dependencies, but this is a necessity and the best option.
26
+
27
+ ## Recommended Dependencies
28
+
29
+ - summernote
30
+
31
+ Used for editor fields. Source is included.
32
+
33
+ - bootstrap-sass >= 3.0.0
34
+
35
+ Required if you want to use editor fields (which utilize summernote).
36
+
37
+ - jquery-rails
38
+
39
+ Hope to be able to remove this, but required for summernote/bootstrap for now.
40
+
41
+ **The recommended dependencies are only required for the admin portions of your
42
+ application.**
43
+
44
+ _Optionally, you can create a separate set of assets for only the admin via
45
+ standard Rails methods. Or you could not include them and deal with the
46
+ fallout. ;-)_
47
+
48
+
49
+ ## Features
50
+ - Pages with Templates
51
+
52
+ - Subdomain support
53
+
54
+ - Use application models or assets in CMS pages
55
+
56
+ - Search (coming soon)
57
+
58
+ ## Anti-Features
59
+ - User management
60
+
61
+ - Permissions
62
+
63
+ ## Proposed auxilary gems
64
+
65
+ - simplec-vlad: The easiest way to deploy and manage an installation.
66
+ Database and file syncs between enviroments.
67
+
68
+ - simplec-blog: Don't always need or want a blog bundled in. (You might have
69
+ your own.)
70
+
71
+ - simplec-admin: Opinionated, prebuilt way of managing pages. Take it or leave
72
+ it. Or don't mount it and generate scaffold controllers and views for basic
73
+ functions.
74
+
75
+ - simplec-events
76
+
77
+ ## Usage
78
+
79
+ 1. Add to gemfile
80
+ 2. Mount engine
81
+ 3. Create pages and corresponding templates
82
+ 4. Build, generator, or use an auxilary gem for page admin.
83
+ 5. Let users loose.
84
+
85
+ 'www' is considered the default subdomain.
86
+
87
+ 'admin' subdomain is reserved for administration functions if you wish.
88
+
89
+ If you want to modify all pages you should edit ::Page < Simplec::Page, this
90
+ will be generated in an installer later.
91
+
92
+ If you want to test a subclass of ::Page, make sure test has ::Page defined.
93
+
94
+ Create a public layout. The public layout is the default. This will be
95
+ generated in an installer later.
96
+
97
+ Put page model definitions in `app/models/page/`.
98
+
99
+ Put model templates in `app/views/pages/`. AND prefix with an underscore (_),
100
+ i.e. `_home.html.erb`.
101
+
102
+ TODO override field types howto
103
+
104
+ TODO explain using uuids for keys + pgcrypto
105
+
106
+ ### Steps
107
+
108
+ 1. Install simplec in your Rails application.
109
+
110
+ See installation section.
111
+
112
+ 2. Build and admin interface with the rest of your application.
113
+
114
+ Simplec doesn't tell you how to do this. Currently, you should look at the
115
+ test/dummy application for inspiration.
116
+
117
+ 3. Then define a model:
118
+
119
+ ```ruby
120
+ # app/models/page/home.rb
121
+ class Page::Home < ::Page
122
+ field :tagline
123
+ end
124
+ ```
125
+
126
+ 4. And the corresponding template:
127
+
128
+ ```erb
129
+ <!-- app/views/pages/_home.html.erb -->
130
+ <h1>My Application</h1>
131
+ <h2><%= @page.tagline %></h2>
132
+ ```
133
+
134
+ Note: You need to call `#html_safe` on fields with `type: :editor`.
135
+
136
+ 5. And create a page in your admin.
137
+
138
+ 6. Done.
139
+
140
+
141
+ ## Installation
142
+
143
+ 1. Add this line to your application's Gemfile:
144
+
145
+ ```ruby
146
+ gem 'pg'
147
+ gem 'simplec'
148
+ # plus optional gems
149
+ ```
150
+
151
+ At this point it is assumed you are integrating Simplec into an existing
152
+ application, logically then you have your database already configured.
153
+ However, Simplec requires some postgres configuration. Please read the
154
+ section below on Postgres.
155
+
156
+ 2. Install and run the migrations
157
+
158
+ ```shell
159
+ rake simplec:install:migrations
160
+ rake db:migrate
161
+ ```
162
+
163
+ 3. Mount the engine
164
+
165
+ ```ruby
166
+ Rails.application.routes.draw do
167
+ mount Simplec::Engine => "/"
168
+ end
169
+ ```
170
+
171
+ 4. Install and configure `dragonfly`
172
+
173
+ ```shell
174
+ rails generate dragonfly
175
+ ```
176
+
177
+ Then configure `config/initializers/dragonfly.rb`.
178
+
179
+ It is recommended to use `rack/cache` or some other HTTP caching solution.
180
+
181
+ 5. Optional - Install bootstap-sass.
182
+
183
+ ```ruby
184
+ gem 'bootstrap-sass', "~> 3.3.7'
185
+ ```
186
+
187
+ Currenty, we have worked out integration with Bootstrap > 3 and are waiting
188
+ for the dust to settle on V4. See directions here:
189
+ https://github.com/twbs/bootstrap-sass
190
+
191
+ 6. Optional - If you want to use the bundled summernote:
192
+
193
+ Load the JS in your application's manifest.
194
+
195
+ ```javascript
196
+ //= require simplec/summernote
197
+ //= require simplec/summernote-config
198
+ ```
199
+
200
+ Please note that this needs to be loaded after jquery and bootstrap.
201
+
202
+ ```css
203
+ @import "simplec/summernote";
204
+ ```
205
+
206
+ Please note that this needs to be loaded after bootstrap. And to use
207
+ `@import` statements, you must use `.scss` files.
208
+
209
+ ## Postgres
210
+
211
+ Note you will need to do this in your production environment as well.
212
+
213
+ On some operating systems, `pgcrypto` is in a separate `postgres` package,
214
+ be sure to install that as well.
215
+
216
+ The `pgcrypto` extension is required for the `gen_random_uuid()` function
217
+ used to generate uuid primary keys.
218
+
219
+ 1. Create your application postgres user (matching database.yml)
220
+
221
+ ```shell
222
+ # -s for superuser in development
223
+ createuser -s myapp
224
+ ```
225
+
226
+ 2. Create databases and add pgcrypto
227
+
228
+ ```shell
229
+ # create development/test databases
230
+ rake db:create
231
+
232
+ # required for gen_random_uuid() function
233
+ # used for ids in Simplec models
234
+ #
235
+ psql myapp_development -c "CREATE EXTENSION pgcrypto;"
236
+ psql myapp_test -c "CREATE EXTENSION pgcrypto;"
237
+ ```
238
+
239
+ ## imagemagick
240
+
241
+ Installation varies per operating system. Image magic is used by dragonfly
242
+ for on the fly (then cached) image manipulation.
243
+
244
+ See this page for a good cheat sheet: http://markevans.github.io/dragonfly/imagemagick
245
+
246
+ ## Roadmap
247
+
248
+ 1. Finish example admin.
249
+
250
+ 1. Installer `rails generater simplec:install`
251
+
252
+ 1. Upgrade summernote from 0.8.2 to 0.8.6
253
+
254
+ 1. Search
255
+
256
+ 1. Caching
257
+
258
+ 1. Optional Gems
259
+
260
+ 1. Remove as many dependencies as possible.
261
+
262
+ ## Contributing
263
+ 1. Use it and file create issues. Somethings are core, other things will be
264
+ relegated to 3rd party extensions.
265
+ 2. Pull requests are welcome. See rule #1.
266
+
267
+ ## TODO
268
+
269
+ - Document `lib/simplec/controller_extensions.rb`
270
+
271
+ - Document why _subdomain in subdomain form in admin.
272
+
273
+ - rails generate simplec:install
274
+ Install app/models/page.rb, app/models/page/
275
+ initializer if needed, with options documented
276
+
277
+ - simplec_path/simplec_url caching
278
+
279
+ ## Running dummy application
280
+
281
+ 1. Create simplec postgres user
282
+
283
+ # -s for superuser in development
284
+ createuser -s simplec
285
+
286
+ 2. Create databases and add pgcrypto
287
+
288
+ rake db:create
289
+
290
+ # required for gen_random_uuid() function
291
+ # used for ids in Simplec models
292
+ #
293
+ psql simplec_development -c "CREATE EXTENSION pgcrypto;"
294
+
295
+ 3. Migrate database
296
+
297
+ rake db:migrate
298
+
299
+
300
+ ## Contributors
301
+
302
+ - Matt Smith, Near Apogee Consulting (www.nearapogee.com)
303
+
304
+ - @lithxe, @jessedo81 for ongoing feedback, use cases, development support,
305
+ and the initial project to test the concept.
306
+
307
+ ## License
308
+ 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 = 'Simplec'
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
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/simplec .js
2
+ //= link_directory ../stylesheets/simplec .css
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,82 @@
1
+ // Summernote
2
+ //
3
+ //
4
+ $.summernote.options.callbacks.onImageUpload = function(files) {
5
+ // Dumb but a default or instance callback required to get the
6
+ // event handler to fire.
7
+ console.log('image upload:', files);
8
+ };
9
+ $.summernote.options.toolbar = [
10
+ ['style', ['style']],
11
+ ['font', ['bold', 'italic', 'underline', 'clear']],
12
+ // ['font', ['bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript', 'clear']],
13
+ // ['fontname', ['fontname']],
14
+ // ['fontsize', ['fontsize']],
15
+ //['color', ['color']],
16
+ ['para', ['ul', 'ol', 'paragraph']],
17
+ //['height', ['height']],
18
+ //['table', ['table']],
19
+ //['insert', ['link', 'picture', 'hr']],
20
+ ['insert', ['link', 'picture', 'hr']],
21
+ ['view', ['fullscreen', 'codeview']],
22
+ ['help', ['help']]
23
+ ];
24
+
25
+ if (!window.simplec) window.simplec = {};
26
+
27
+ window.simplec.initSummernote = function() {
28
+ window.simplec.summernoteInitialized = true;
29
+
30
+ $('.editor-field').on('summernote.init', function(event) {
31
+
32
+ // Material Kit Hack
33
+ //$('.note-toolbar .btn-default').
34
+ // removeClass('btn-default').addClass('btn-simple');
35
+
36
+ //$('.note-popover').css({'display': 'none'}); // BS4 HACK
37
+ var $editor = $(event.target),
38
+ $input = $($editor.data('input'));
39
+ if ($input.val().length > 0) $editor.summernote('code', $input.val());
40
+ }).on('summernote.change', function(event, contents, $editable) {
41
+ var $editor = $(event.target),
42
+ $input = $($editor.data('input'));
43
+ $input.val(contents);
44
+ }.bind(window)).on('summernote.image.upload', function(event, files) {
45
+ console.log('upload event');
46
+ for (var i = 0; i < files.length; i++) {
47
+ var file = files[i],
48
+ reader = new FileReader();
49
+ reader.onloadend = function() {
50
+ $.ajax({
51
+ method: 'POST',
52
+ url: '/embedded-images',
53
+ dataType: 'json',
54
+ contentType: 'application/json',
55
+ data: JSON.stringify({
56
+ asset_url: reader.result,
57
+ asset_name: file.name
58
+ })
59
+ }).fail(function(data, textStatus, jqXHR){
60
+ console.log('IMAGE UPLOAD FAIL', textStatus);
61
+ }).done(function(data, textStatus, jqXHR){
62
+ $(event.target).summernote(
63
+ 'insertImage',
64
+ jqXHR.responseJSON.asset_url, jqXHR.responseJSON.asset_name
65
+ );
66
+ });
67
+ };
68
+ reader.readAsDataURL(file);
69
+ }
70
+ });
71
+
72
+ $('.editor-field').summernote({
73
+ height: 500,
74
+ minHeight: 100,
75
+ maxHeight: 1200
76
+ });
77
+
78
+ };
79
+
80
+ $(document).on('ready turbolinks:load', function() {
81
+ if (!window.simplec.summernoteInitialized) window.simplec.initSummernote();
82
+ });