tomify 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/tomify/dynamic/classes/field.coffee +7 -1
  3. data/app/assets/javascripts/tomify/dynamic/classes/form.coffee +2 -2
  4. data/app/assets/javascripts/tomify/dynamic/classes/request.coffee +1 -1
  5. data/app/assets/javascripts/tomify/dynamic/classes/store.coffee +5 -4
  6. data/app/assets/javascripts/tomify/dynamic/react/components/admin/pages.coffee.erb +1 -1
  7. data/app/assets/javascripts/tomify/dynamic/react/components/admin/settings.coffee +10 -5
  8. data/app/assets/javascripts/tomify/dynamic/react/components/admin/{sidebars.coffee → sidebars.coffee.erb} +2 -1
  9. data/app/assets/javascripts/tomify/dynamic/react/components/admin/uploads.coffee +1 -1
  10. data/app/assets/javascripts/tomify/dynamic/react/components/admin/users.coffee +1 -1
  11. data/app/assets/javascripts/tomify/dynamic/react/components/fields/json.coffee +30 -0
  12. data/app/assets/javascripts/tomify/dynamic/react/components/layout/analytics.coffee +1 -2
  13. data/app/assets/stylesheets/tomify/_page.scss +5 -1
  14. data/app/controllers/tomify/concerns/default/env_helper.rb +2 -0
  15. data/app/controllers/tomify/public/pages_controller.rb +1 -1
  16. data/app/helpers/tomify/carrierwave_helper.rb +16 -10
  17. data/app/models/tomify/concerns/sidebar.rb +3 -2
  18. data/app/models/tomify/concerns/upload.rb +1 -1
  19. data/app/models/tomify/setting.rb +1 -1
  20. data/app/views/templates/contact.haml +1 -1
  21. data/app/views/templates/default.haml +1 -1
  22. data/app/views/templates/sidebar.haml +4 -0
  23. data/app/views/tomify/defaults/_container.haml +6 -1
  24. data/db/migrate/19900000000010_add_template_to_sidebars.rb +5 -0
  25. data/lib/tomify/version.rb +1 -1
  26. data/lib/tomify.rb +5 -1
  27. metadata +6 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2d0a5f91a0962812c61a3b7f66a1fd034c8750b
4
- data.tar.gz: 30dbe54efd78321b91cb16a41fe48fcf15b2692a
3
+ metadata.gz: af725db32ac310b47ea7eefedfaf879b7b927040
4
+ data.tar.gz: 80da5c622cdb34254d793df17e2919afcef6c98a
5
5
  SHA512:
6
- metadata.gz: f57feac1ed194f776c2e0badc337ef50d7e7738b1611e22012ef6769161da150dd67ea244e37e2a00a6c44d7c6d92290cb7ca8b239131f9f74eb6f8725443a65
7
- data.tar.gz: 3ab0aa47ba4bf03d0dcc7eab29f5931bd20cccf4babfa46268188f90bdb3907d1f9f9c3ba01316e02973e82576ef07946e4264b94b5e174e942f988aee0f5dd7
6
+ metadata.gz: 34a9285af9d4e3f98bc13e7173c7c0bf34ef3e932c0321bfa8bf651ad74dd06610ae64c8329675a8b0e72ff08a5cb4b6e2d6ac163f5fdb2e636b4bccd6dc37b4
7
+ data.tar.gz: edd76bd3edf8f8545c2895a1066187822f42e302a58176cf4374b6e88857d36a6e1e5d4f1ff87147a68802d7243d587767196f955eb21f8ac15bd725555d3771
@@ -16,10 +16,16 @@ class @Field
16
16
  field.setForm(options.form)
17
17
  field
18
18
  copy: (form) ->
19
- Field.build $.extend({}, @options, { form: form })
19
+ Field.build Object.assign({}, @options, { form: form })
20
20
  constructor: (options) ->
21
21
  @options = options
22
22
  setForm: (form) ->
23
23
  @props.value = form.value.bind(form)
24
24
  @props.onChange = form.onChange.bind(form)
25
25
  @props.options = form.options.bind(form, @props) if @props.model
26
+ show: ->
27
+ record = @options.form.record.get()
28
+ changes = @options.form.changes.get()
29
+ return @options.if(record, changes) if @options.if
30
+ return !@options.unless(record, changes) if @options.unless
31
+ true
@@ -25,7 +25,7 @@ class @Form
25
25
  options.push { value: record.id, name: record.name }
26
26
  options
27
27
  add: (name, type, options = {}) ->
28
- options = $.extend { type: type, name: name, form: @ }, options
28
+ options = Object.assign { type: type, name: name, form: @ }, options
29
29
  @fields.push Field.build(options)
30
30
  @models.push options.model if options.model
31
31
  setComponent: (component, store) ->
@@ -70,4 +70,4 @@ class @Form
70
70
  <FieldComponent {...field.props} />
71
71
  </div>
72
72
  render: ->
73
- @renderField(field) for field in @fields
73
+ @renderField(field) for field in @fields when field.show()
@@ -9,7 +9,7 @@ class @Request
9
9
  @ajax: (options) ->
10
10
  options.url = options.url.assign(options.data)
11
11
  if options.type in ["POST", "PUT"]
12
- $.extend options, {
12
+ Object.assign options, {
13
13
  data: @formData(new FormData(), options.data),
14
14
  cache: false,
15
15
  processData: false,
@@ -11,21 +11,22 @@ class @Store extends Observer
11
11
  merge: (data) ->
12
12
  throw "Store: Invalid Data Type" unless @isObject()
13
13
  @trigger "merge", data
14
- @set($.extend({}, @get(), data))
14
+ @set Object.assign({}, @get(), data)
15
15
  push: (data) ->
16
16
  throw "Store: Invalid Data Type" unless @isArray()
17
17
  @trigger "push", data
18
- @set(@get().concat([data]))
18
+ @set @get().concat([data])
19
19
  remove: (field) ->
20
20
  throw "Store: Invalid Data Type" unless @isObject()
21
21
  @trigger "remove", data
22
22
  data = @get()
23
23
  delete data[field]
24
- @set(item for item in data when item?)
24
+ data = (item for item in data when item?) if @isArray()
25
+ @set data
25
26
  get: (field) ->
26
27
  throw "Store: Invalid Data Type" unless @isDefined()
27
28
  return @data if @isBoolean() || @isString()
28
- data = $.extend(@data.constructor(), @data)
29
+ data = Object.assign @data.constructor(), @data
29
30
  if field then data[field] else data
30
31
  empty: ->
31
32
  return @data.length == 0 if @isArray()
@@ -12,7 +12,7 @@ model.columns = [
12
12
  }
13
13
  ]
14
14
 
15
- form = new Form("horizontal")
15
+ form = new Form "horizontal"
16
16
  form.add "parent_id", "select", model: "Admin.Page", allowBlank: true
17
17
  form.add "sidebar_id", "select", model: "Admin.Sidebar", allowBlank: true
18
18
  form.add "active", "checkbox"
@@ -6,7 +6,7 @@ model.columns = [
6
6
  { name: "value", value: (r) ->
7
7
  type = r.type.split("::").last
8
8
  return "#{r.value}" if type == "Boolean"
9
- return "JSON (Don't Edit)" if type == "Json"
9
+ return "JSON" if type == "Json"
10
10
  r.value
11
11
  },
12
12
  { name: "updated_at", value: (r) -> r.updated_at.date() },
@@ -16,15 +16,20 @@ model.columns = [
16
16
  options = ["Boolean", "Json", "Text", "Uploader"]
17
17
  options = ({ name: option, value: "Tomify::Setting::#{option}" } for option in options)
18
18
 
19
- newForm = new Form("horizontal")
19
+ newForm = new Form "horizontal"
20
20
  newForm.add "type", "select", options: options
21
21
  newForm.add "public", "checkbox"
22
22
  newForm.add "name", "text"
23
- newForm.add "value", "text"
23
+ newForm.add "value", "checkbox", if: (record, changes) -> changes.type.split("::").last == "Boolean"
24
+ newForm.add "value", "text", if: (record, changes) -> changes.type.split("::").last == "Text"
25
+ newForm.add "json", "json", if: (record, changes) -> changes.type.split("::").last == "Json"
24
26
 
25
- editForm = new Form("horizontal")
27
+ editForm = new Form "horizontal"
26
28
  editForm.add "public", "checkbox"
27
29
  editForm.add "name", "text"
28
- editForm.add "value", "text"
30
+ editForm.add "value", "checkbox", if: (record) -> record.type.split("::").last == "Boolean"
31
+ editForm.add "value", "text", if: (record) -> record.type.split("::").last == "Text"
32
+ editForm.add "json", "json", if: (record) -> record.type.split("::").last == "Json"
33
+ # editForm.add "value", "json", if: (record) -> record.type.split("::").last == "Uploader"
29
34
 
30
35
  Component.create "Admin.Settings.Index.Container", render: -> <Index.Container name="Admin.Setting" newForm={newForm} editForm={editForm} />
@@ -7,9 +7,10 @@ model.columns = [
7
7
  { name: "actions", edit: true, destroy: true }
8
8
  ]
9
9
 
10
- form = new Form("horizontal")
10
+ form = new Form "horizontal"
11
11
  form.add "active", "checkbox"
12
12
  form.add "name", "text"
13
+ form.add "template", "select", options: <%= Tomify::Page.templates %>
13
14
  form.add "heading", "text"
14
15
  form.add "text", "markdown"
15
16
 
@@ -6,7 +6,7 @@ model.columns = [
6
6
  { name: "actions", edit: true, destroy: true }
7
7
  ]
8
8
 
9
- form = new Form("horizontal")
9
+ form = new Form "horizontal"
10
10
  form.add "name", "text"
11
11
  form.add "file", "file"
12
12
 
@@ -11,7 +11,7 @@ model.columns = [
11
11
  { name: "actions", edit: true, destroy: true }
12
12
  ]
13
13
 
14
- form = new Form("horizontal")
14
+ form = new Form "horizontal"
15
15
  form.add "admin", "checkbox"
16
16
  form.add "email", "text"
17
17
  form.add "first_name", "text"
@@ -0,0 +1,30 @@
1
+ Component.create "Form.Field.Json",
2
+ onKeyChange: (key, e) ->
3
+ changes = Object.assign {}, @props.value(@props.name)
4
+ value = changes[key]
5
+ delete changes[key]
6
+ key = e.target.value
7
+ changes[key] = value if key
8
+ @props.onChange(@props.name, target: { value: changes })
9
+ onValueChange: (key, e) ->
10
+ changes = Object.assign {}, @props.value(@props.name)
11
+ changes[key] = e.target.value
12
+ @props.onChange(@props.name, target: { value: changes })
13
+ render: ->
14
+ changes = Object.assign {}, @props.value(@props.name)
15
+ changes[""] ?= ""
16
+ index = 0
17
+ <div>
18
+ {for key, value of changes
19
+ <div key={index++} className="form-group">
20
+ <div className="col-xs-6">
21
+ <input placeholder="Key" className="form-control" type="text" value={key} onChange={@onKeyChange.bind(null, key)} />
22
+ </div>
23
+ {if key
24
+ <div className="col-xs-6">
25
+ <input placeholder="Value" className="form-control" type="text" value={value} onChange={@onValueChange.bind(null, key)} />
26
+ </div>
27
+ }
28
+ </div>
29
+ }
30
+ </div>
@@ -6,8 +6,7 @@ Component.create "Layout.Analytics",
6
6
  return unless code = setting "google_analytics_code"
7
7
 
8
8
  window.GoogleAnalyticsObject = "ga"
9
- window.ga = (args...) -> window[window.GoogleAnalyticsObject] args...
10
- window?[window.GoogleAnalyticsObject] ?= (args...) ->
9
+ window[window.GoogleAnalyticsObject] ?= (args...) ->
11
10
  api = window[window.GoogleAnalyticsObject]
12
11
  (api.q or= []).push args
13
12
  return
@@ -1,4 +1,4 @@
1
- .page {
1
+ .page, .sidebar {
2
2
  h1 { color: $brand; }
3
3
  h2, h3 { font-style: italic; }
4
4
  h2 { font-size: 1.5em; }
@@ -29,3 +29,7 @@
29
29
  ul li:before { content: "\f055"; }
30
30
  }
31
31
  }
32
+
33
+ .sidebar {
34
+ h1, h2, h3, h4, h5, h6 { margin-top: 0; }
35
+ }
@@ -16,6 +16,8 @@ module Tomify::Concerns::Default::EnvHelper
16
16
  [
17
17
  { name: "App", path: "admin/settings" },
18
18
  { name: "Pages", path: "admin/pages" },
19
+ { name: "Sidebars", path: "admin/sidebars" },
20
+ { name: "Uploads", path: "admin/uploads" },
19
21
  { name: "Users", path: "admin/users" }
20
22
  ]
21
23
  end
@@ -17,6 +17,6 @@ class Tomify::Public::PagesController < Tomify.controllers.public
17
17
  when "default"
18
18
  end
19
19
 
20
- render "templates/#{template}", layout: true
20
+ render "templates/#{template}", layout: true, locals: { record: @page }
21
21
  end
22
22
  end
@@ -1,17 +1,23 @@
1
1
  module Tomify::CarrierwaveHelper
2
2
  def self.load_config
3
- return unless defined? Carrierwave
3
+ return unless defined? CarrierWave
4
4
  return unless settings = Tomify.setting(:aws)
5
5
 
6
- CarrierWave.configure do |config|
7
- config.fog_provider = "fog/aws"
8
- config.storage = :fog
9
- config.fog_credentials = {
10
- provider: "AWS",
11
- aws_access_key_id: settings["access_key"],
12
- aws_secret_access_key: settings["secret_key"]
13
- }
14
- config.fog_directory = settings["bucket"]
6
+ descendants = CarrierWave::Uploader::Base.descendants
7
+ descendants.push CarrierWave::Uploader::Base
8
+ descendants.push CarrierWave
9
+ descendants.each do |klass|
10
+ klass.configure do |config|
11
+ config.fog_provider = "fog/aws"
12
+ config.fog_credentials = {
13
+ provider: "AWS",
14
+ aws_access_key_id: settings["access_key"],
15
+ aws_secret_access_key: settings["secret_key"]
16
+ }
17
+ config.fog_directory = settings["bucket"]
18
+ config.fog_public = true
19
+ config.storage = :fog
20
+ end
15
21
  end
16
22
  end
17
23
  end
@@ -3,7 +3,8 @@ module Tomify::Concerns::Sidebar
3
3
 
4
4
  included do
5
5
  has_many :pages, class_name: Tomify.models.page.to_s
6
- validates_presence_of :name
6
+
7
+ validates_presence_of :name, :template
7
8
 
8
9
  scope :active, -> { where(active: true) }
9
10
 
@@ -12,7 +13,7 @@ module Tomify::Concerns::Sidebar
12
13
 
13
14
  class_methods do
14
15
  def admin_params
15
- [:active, :name, :heading, :text]
16
+ [:active, :name, :heading, :template, :text]
16
17
  end
17
18
  end
18
19
  end
@@ -2,7 +2,7 @@ module Tomify::Concerns::Upload
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  included do
5
- mount_uploader :file, Tomify::FileUploader
5
+ mount_uploader :file, Tomify.uploaders.file
6
6
 
7
7
  before_validation :set_model
8
8
  before_validation :validate_content_type, on: :update, if: :content_type_changed?
@@ -18,7 +18,7 @@ class Tomify::Setting < Tomify.models.base
18
18
  end
19
19
 
20
20
  def self.admin_params
21
- [:type, :name, :public, :value, :json]
21
+ [:type, :name, :public, :value, json: {}]
22
22
  end
23
23
 
24
24
  def serializable_hash(options = nil)
@@ -1,7 +1,7 @@
1
1
  .container-fluid
2
2
  .row.text-center
3
3
  .col-md-8.col-md-offset-2
4
- .page= @page.text_to_html
4
+ .page= record.text_to_html
5
5
  - if contact_email = setting(:contact_email)
6
6
  %p
7
7
  = link_to "mailto:#{contact_email}", target: :_blank do
@@ -1,4 +1,4 @@
1
1
  .container-fluid
2
2
  .row.text-center
3
3
  .col-md-8.col-md-offset-2
4
- .page= @page.text_to_html
4
+ .page= record.text_to_html
@@ -0,0 +1,4 @@
1
+ .panel.panel-success
2
+ - if record.try(:heading)
3
+ .panel-heading= record.heading
4
+ .panel-body= record.text_to_html
@@ -1,3 +1,8 @@
1
+ - sidebar = @page.sidebar if @page&.sidebar&.active
1
2
  .container-fluid
2
3
  .row
3
- .col-md-12= yield
4
+ - if sidebar
5
+ .col-md-8= yield
6
+ .col-md-4.sidebar= render template: "templates/#{sidebar.template}", locals: { record: sidebar }
7
+ - else
8
+ .col-md-12= yield
@@ -0,0 +1,5 @@
1
+ class AddTemplateToSidebars < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_column :sidebars, :template, :string, null: false
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Tomify
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/tomify.rb CHANGED
@@ -36,7 +36,11 @@ module Tomify
36
36
  )
37
37
 
38
38
  mattr_accessor :uploaders
39
- self.uploaders = Constantly.new(base: "TomifyUploader")
39
+ self.uploaders = Constantly.new(
40
+ base: "TomifyUploader",
41
+ file: "Tomify::FileUploader",
42
+ setting: "Tomify::SettingUploader"
43
+ )
40
44
 
41
45
  def self.root
42
46
  Pathname.new Gem::Specification.find_by_name("tomify").gem_dir
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tomify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Prats
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-30 00:00:00.000000000 Z
11
+ date: 2017-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -267,13 +267,14 @@ files:
267
267
  - app/assets/javascripts/tomify/dynamic/global.coffee
268
268
  - app/assets/javascripts/tomify/dynamic/react/components/admin/pages.coffee.erb
269
269
  - app/assets/javascripts/tomify/dynamic/react/components/admin/settings.coffee
270
- - app/assets/javascripts/tomify/dynamic/react/components/admin/sidebars.coffee
270
+ - app/assets/javascripts/tomify/dynamic/react/components/admin/sidebars.coffee.erb
271
271
  - app/assets/javascripts/tomify/dynamic/react/components/admin/uploads.coffee
272
272
  - app/assets/javascripts/tomify/dynamic/react/components/admin/users.coffee
273
273
  - app/assets/javascripts/tomify/dynamic/react/components/edit.coffee
274
274
  - app/assets/javascripts/tomify/dynamic/react/components/fields/checkbox.coffee
275
275
  - app/assets/javascripts/tomify/dynamic/react/components/fields/default.coffee
276
276
  - app/assets/javascripts/tomify/dynamic/react/components/fields/file.coffee
277
+ - app/assets/javascripts/tomify/dynamic/react/components/fields/json.coffee
277
278
  - app/assets/javascripts/tomify/dynamic/react/components/fields/markdown.coffee
278
279
  - app/assets/javascripts/tomify/dynamic/react/components/fields/select.coffee
279
280
  - app/assets/javascripts/tomify/dynamic/react/components/fields/textarea.coffee
@@ -368,6 +369,7 @@ files:
368
369
  - app/uploaders/tomify_uploader.rb
369
370
  - app/views/templates/contact.haml
370
371
  - app/views/templates/default.haml
372
+ - app/views/templates/sidebar.haml
371
373
  - app/views/tomify/defaults/_body.haml
372
374
  - app/views/tomify/defaults/_container.haml
373
375
  - app/views/tomify/defaults/_env.haml
@@ -398,6 +400,7 @@ files:
398
400
  - db/migrate/19900000000007_add_verified_to_users.rb
399
401
  - db/migrate/19900000000008_add_name_to_tokens.rb
400
402
  - db/migrate/19900000000009_add_invited_to_users.rb
403
+ - db/migrate/19900000000010_add_template_to_sidebars.rb
401
404
  - db/seeds.rb
402
405
  - lib/generators/tomify/bundle/bundle_generator.rb
403
406
  - lib/generators/tomify/bundle/templates/default.js