simplec 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +258 -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/_image.html.erb +14 -0
  26. data/app/views/simplec/fields/_string.html.erb +4 -0
  27. data/app/views/simplec/fields/_text.html.erb +4 -0
  28. data/app/views/simplec/pages/show.html.erb +2 -0
  29. data/config/routes.rb +8 -0
  30. data/db/migrate/20170809204353_create_simplec_pages.rb +30 -0
  31. data/db/migrate/20170809204511_create_simplec_subdomains.rb +12 -0
  32. data/db/migrate/20170809210304_create_simplec_embedded_images.rb +15 -0
  33. data/lib/simplec.rb +5 -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/tasks/simplec_tasks.rake +4 -0
  40. metadata +166 -0
@@ -0,0 +1,56 @@
1
+ module Simplec
2
+ module ActionController
3
+ module Extensions
4
+
5
+ def self.included(receiver)
6
+ receiver.helper_method :subdomain, :page,
7
+ :simplec_path, :simplec_url
8
+ end
9
+
10
+ def subdomain(name=nil)
11
+ name ||= request.subdomain
12
+ @_subdomains ||= Hash.new
13
+ return @_subdomains[name] if @_subdomains[name]
14
+ @_subdomains[name] = Subdomain.find_by!(name: name)
15
+ end
16
+
17
+ def page(path, options={})
18
+ @_page ||= Hash.new
19
+ return @_page[path] if @_page[path]
20
+
21
+ _subdomain = subdomain
22
+ _subdomain = Subdomain.find_by!(
23
+ name: options[:subdomain]
24
+ ) if options[:subdomain]
25
+
26
+ @_page[path] = _subdomain.pages.find_by!(path: path)
27
+ end
28
+
29
+ def simplec_path(page_or_path, options={})
30
+ # TODO cache page_paths
31
+ _page = page_or_path.is_a?(Page) ?
32
+ page_or_path : page(page_or_path, options)
33
+
34
+ unless _page
35
+ raise ActiveRecord::RecordNotFound if options[:raise]
36
+ return nil
37
+ end
38
+
39
+ _page.path
40
+ end
41
+
42
+ def simplec_url(page_or_path, options={})
43
+ # TODO cache page_urls
44
+ _page = page_or_path.is_a?(Page) ?
45
+ page_or_path : page(page_or_path, options)
46
+
47
+ unless _page
48
+ raise ActiveRecord::RecordNotFound if options[:raise]
49
+ return nil
50
+ end
51
+
52
+ URI.join(root_url(subdomain: _page.subdomain.try(:name)), _page.path).to_s
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,118 @@
1
+ module Simplec
2
+ module ActionView
3
+ module Helper
4
+
5
+ def head(page)
6
+ content_for :title, page.title
7
+ content_for :meta_description, page.meta_description
8
+ end
9
+
10
+ def title
11
+ content_for :title
12
+ end
13
+
14
+ def meta_description_tag
15
+ tag :meta, name: 'description', content: content_for(:meta_description)
16
+ end
17
+
18
+ def template(page)
19
+ _template = page.type.demodulize.downcase
20
+ render "pages/#{_template}"
21
+ end
22
+
23
+ def page_field(f, options={})
24
+ render "simplec/fields/#{options[:type]}", options.merge(f: f)
25
+ end
26
+
27
+ # Retreive a document.
28
+ #
29
+ # slug - matching a Document slug.
30
+ # options[:subdomain] - a string matching a Subdomain name, find a document
31
+ # from another subdomain
32
+ # options[:raise] - if true, casuse a 404 if document isn't found
33
+ #
34
+ # Example:
35
+ #
36
+ # -# Save as...
37
+ # <%= link_to doc('/permission/general').name,
38
+ # doc('/permission/general').path,
39
+ # download: true %>
40
+ #
41
+ # -# Display in new window...
42
+ # <%= link_to doc('/permission/general').name,
43
+ # doc('/permission/general').path,
44
+ # target: '_blank' %>
45
+ #
46
+ def doc(slug, options={})
47
+ @_docs ||= Hash.new
48
+ key = "[#{options[:subdomain]}][#{slug}]"
49
+ return @_docs[key] if @_docs[key]
50
+ @_docs[key] = subdomain(options[:subdomain]).
51
+ documents.find_by(slug: slug)
52
+ raise ActiveRecord::RecordNotFound if options[:raise] && !@_docs[key]
53
+ @_docs[key]
54
+ end
55
+
56
+ # Retreive a document.
57
+ #
58
+ # slug - matching a Document slug.
59
+ # options[:subdomain] - a string matching a Subdomain name, find a document
60
+ # set from another subdomain
61
+ # options[:raise] - if true, casuse a 404 if document set isn't found
62
+ #
63
+ # Example:
64
+ #
65
+ # <% docset('/faith').each do |doc| %>
66
+ # <%= link_to doc.name, doc.path %>
67
+ # <% end %>
68
+ #
69
+ def docset(slug, options={})
70
+ @_docsets ||= Hash.new
71
+ key = "[#{options[:subdomain]}][#{slug}]"
72
+ return @_docsets[key] if @_docsets[key]
73
+ set = subdomain(options[:subdomain]).
74
+ document_sets.find_by(slug: slug)
75
+ raise ActiveRecord::RecordNotFound if options[:raise] && !set
76
+ @_docsets[key] = set.documents
77
+ end
78
+
79
+ # page_or_path - a page object or a path of a page
80
+ # options[:subdomain] - a string matching a Subdomain name, find a page
81
+ # from another subdomain
82
+ # options[:raise] - if true, casuse a 404 if a page set isn't found
83
+ #
84
+ # Example:
85
+ #
86
+ # <% subpages('/give-volunteer', conditions: ->{ order(title: :asc) }).each do |page| %>
87
+ # ... do something with page ...
88
+ # <% end%>
89
+ def subpages(page_or_path, options={})
90
+ if options[:conditions] && !options[:conditions].respond_to?(:call)
91
+ raise ArgumentError, <<-ERROR
92
+ #{options[:conditions]} was passed as :conditions but is not callable.
93
+ "Pass a callable instead: `conditions: -> { where(approved: true) }`
94
+ ERROR
95
+ end
96
+
97
+ @_subpages ||= Hash.new # TODO apply new conditions after cache
98
+ key = "[#{options[:subdomain]}][#{page_or_path}]"
99
+
100
+ unless @_subpages[key]
101
+ page = page_or_path.is_a?(Page) ? page_or_path : nil
102
+ page ||= subdomain(options[:subdomain]).pages.find_by(path: page_or_path)
103
+
104
+ unless page
105
+ raise ActiveRecord::RecordNotFound if options[:raise]
106
+ return @_subpages[key] = Array.new
107
+ end
108
+
109
+ @_subpages[key] = page.subpages
110
+ end
111
+
112
+ @_subpages[key].respond_to?(:merge) && options[:conditions] ?
113
+ @_subpages[key].merge(options[:conditions]) : @_subpages[key]
114
+ end
115
+ end
116
+
117
+ end
118
+ end
@@ -0,0 +1,37 @@
1
+ module Simplec
2
+ module EmbeddedImageActions
3
+ module ClassMethods; end
4
+
5
+ module InstanceMethods
6
+
7
+ def create
8
+ @embedded_image = EmbeddedImage.new(embedded_image_params)
9
+ if @embedded_image.save
10
+ respond_to do |format|
11
+ format.json {
12
+ render :show, status: 201, location: @embedded_image.url
13
+ }
14
+ end
15
+ else
16
+ respond_to do |format|
17
+ format.json {
18
+ render status: 422, json: @embedded_image.errors
19
+ }
20
+ end
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def embedded_image_params
27
+ params.permit(:asset_url, :asset_name)
28
+ end
29
+
30
+ end
31
+
32
+ def self.included(receiver)
33
+ receiver.extend ClassMethods
34
+ receiver.send :include, InstanceMethods
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,18 @@
1
+ require 'simplec/action_controller/extensions'
2
+ require 'simplec/action_view/helper'
3
+
4
+ module Simplec
5
+ class Engine < ::Rails::Engine
6
+ isolate_namespace Simplec
7
+
8
+ initializer "simplec_controller_extensions" do
9
+ ActiveSupport.on_load(:action_controller_base) {
10
+ prepend Simplec::ActionController::Extensions
11
+ helper Simplec::ActionView::Helper
12
+ }
13
+ ActiveSupport.on_load(:active_record) {
14
+ Dir["#{Rails.root}/app/models/page/*.rb"].each {|file| require_dependency file }
15
+ }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Simplec
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :simplec do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simplec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Smith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.0.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: pg
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.21.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.21.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: dragonfly
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: jquery-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bootstrap-sass
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: bcrypt
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A CMS that doesn't take over an application.
98
+ email:
99
+ - matt@nearapogee.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - MIT-LICENSE
105
+ - README.md
106
+ - Rakefile
107
+ - app/assets/config/simplec_manifest.js
108
+ - app/assets/fonts/simplec/summernote.eot
109
+ - app/assets/fonts/simplec/summernote.ttf
110
+ - app/assets/fonts/simplec/summernote.woff
111
+ - app/assets/javascripts/simplec/application.js
112
+ - app/assets/javascripts/simplec/summernote-config.js
113
+ - app/assets/javascripts/simplec/summernote.js
114
+ - app/assets/stylesheets/simplec/application.css
115
+ - app/assets/stylesheets/simplec/summernote.scss
116
+ - app/constraints/simplec/subdomains.rb
117
+ - app/controllers/simplec/application_controller.rb
118
+ - app/controllers/simplec/pages_controller.rb
119
+ - app/helpers/simplec/application_helper.rb
120
+ - app/jobs/simplec/application_job.rb
121
+ - app/mailers/simplec/application_mailer.rb
122
+ - app/models/simplec/application_record.rb
123
+ - app/models/simplec/embedded_image.rb
124
+ - app/models/simplec/page.rb
125
+ - app/models/simplec/subdomain.rb
126
+ - app/views/simplec/fields/_editor.html.erb
127
+ - app/views/simplec/fields/_image.html.erb
128
+ - app/views/simplec/fields/_string.html.erb
129
+ - app/views/simplec/fields/_text.html.erb
130
+ - app/views/simplec/pages/show.html.erb
131
+ - config/routes.rb
132
+ - db/migrate/20170809204353_create_simplec_pages.rb
133
+ - db/migrate/20170809204511_create_simplec_subdomains.rb
134
+ - db/migrate/20170809210304_create_simplec_embedded_images.rb
135
+ - lib/simplec.rb
136
+ - lib/simplec/action_controller/extensions.rb
137
+ - lib/simplec/action_view/helper.rb
138
+ - lib/simplec/embedded_image_actions.rb
139
+ - lib/simplec/engine.rb
140
+ - lib/simplec/version.rb
141
+ - lib/tasks/simplec_tasks.rake
142
+ homepage: https://github.com/nearapogee/simplec
143
+ licenses:
144
+ - MIT
145
+ metadata: {}
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubyforge_project:
162
+ rubygems_version: 2.6.11
163
+ signing_key:
164
+ specification_version: 4
165
+ summary: Developer oriented CMS.
166
+ test_files: []