inverter 0.2.2 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9f690d3662f0f18c84658e8a29adca5b6fac0b9
4
- data.tar.gz: 535064670509e2b8a5a6223121630776763772e6
3
+ metadata.gz: 564ec4fa572bfa7f6cc0fa67891caad0253b272d
4
+ data.tar.gz: 0fb3028fa52c4c4b5b68f8f0a736cc8fde23b6f7
5
5
  SHA512:
6
- metadata.gz: c91a1f301761818c05fd5d60d02aa6bb1212bd11c53ff986efe28ac423d8cc0e4a668e406bcb7287689e333cd5ff495906356155d1dacd197e110b388db67e98
7
- data.tar.gz: d0930d472b39cc9ee5a51f70c78b8a07ea9be9b6e951ef43fce073fc6a88138d21455384ee8d41e9fa6b05a05a6acb6bd2bb1cb0e9a16f1fca164d71cf0fa378
6
+ metadata.gz: 3ed5adbc98926a81745305997ed573b65fe1419f14592611ef7fb592f204f296c58d3522228fae8004a0958a34069c6c7dae312e244f05b74fbce049cecbc811
7
+ data.tar.gz: 4d78f109f0d6339d39716c96fe6cc366a4903a89ea34f3ad833e52265024d4758972fe667fb54456763fd906405aa67547b34bc48782c286d91083748dc2d091
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .DS_Store
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # Inverter
2
2
 
3
- ## Easy way to connect Rails templates content to CMS
3
+ *Easy way to connect Rails templates content to CMS*
4
+
5
+ Mark content that you want to change via CMS in Rails templates. It's automatically populated to models and is accessible via CMS. When Rails renders template it pulls editable content from databased automatically.
4
6
 
5
- Mark right in Rails temlpates content that you want to change via CMS. It's automatically populated to models and is accessible via CMS. While Rails rendering template it's pulling editable content from databased automatically.
6
7
 
7
8
  ## Installation
8
9
 
@@ -48,7 +49,7 @@ Setup admin page controller configuration ```controllers/admin/pages_controller.
48
49
 
49
50
  def syncronize_templates
50
51
  if Rails.env.development?
51
- resource_class.sync_objects_with_templates!
52
+ resource_class.sync_with_templates!
52
53
  end
53
54
  end
54
55
  end
@@ -62,6 +63,10 @@ An example of editable template with three content blocks and page name (to iden
62
63
  <!--// About //-->
63
64
  <h1>About</h1>
64
65
 
66
+ <!--[ hero : inverter-image ]-->
67
+ <%= image_tag('hero-1.png', alt: 'Welcome to Inverter') %>
68
+ <!--END-->
69
+
65
70
  <!--[ subtitle ]-->
66
71
  <p>
67
72
  This is an example of the content block named subtitle. This content is editable
@@ -85,6 +90,7 @@ An example of editable template with three content blocks and page name (to iden
85
90
  <!--END-->
86
91
  ```
87
92
 
93
+
88
94
  ### Character Setup
89
95
 
90
96
  Inverter supports [chr](https://github.com/slate-studio/chr) out of the box. Include custom input in the cms configuration file ```admin.coffee```, and setup module configuration:
@@ -117,6 +123,7 @@ Inverter input has an option ```defaultInputType``` which specifies what input t
117
123
 
118
124
  You can also specify input type that you want to use for specific block like this: ```<!--[ Main Body : text ]-->``` — in this case ```Main Body``` would be a label and ```text``` is an input type that will be used to edit this block in CMS.
119
125
 
126
+
120
127
  ### Meta Tags Support
121
128
 
122
129
  ```Mongoid::Inverter``` concern includes page meta tags fields. Check out [meta-tags](https://github.com/kpumuk/meta-tags) gem documentation for usage details, it helps to make pages SEO friendly.
@@ -134,17 +141,23 @@ To enable meta-tags support include following helper in application layout:
134
141
 
135
142
  To override default behavior add custom fields and write own ```update_inverter_meta_tags``` implementation.
136
143
 
144
+
137
145
  ## Inverter family
138
146
 
139
- - [Mongosteen](https://github.com/slate-studio/mongosteen): An easy way to add restful actions for mongoid models
140
- - [Character](https://github.com/slate-studio/chr): A simple and lightweight javascript library for building data management web apps
147
+ - [Mongosteen](https://github.com/slate-studio/mongosteen): An easy way to add RESTful actions for mongoid models
148
+ - [Character](https://github.com/slate-studio/chr): Powerful responsive javascript CMS for apps
149
+ - [Loft](https://github.com/slate-studio/loft): Media assets manager for Character CMS
141
150
 
142
- ## Credits
151
+
152
+ ## License
153
+
154
+ Copyright © 2015 [Slate Studio, LLC](http://slatestudio.com). Inverter is free software, and may be redistributed under the terms specified in the [license](LICENSE.md).
155
+
156
+
157
+ ## About Slate Studio
143
158
 
144
159
  [![Slate Studio](https://slate-git-images.s3-us-west-1.amazonaws.com/slate.png)](http://slatestudio.com)
145
160
 
146
161
  Inverter is maintained and funded by [Slate Studio, LLC](http://slatestudio.com). Tweet your questions or suggestions to [@slatestudio](https://twitter.com/slatestudio) and while you’re at it follow us too.
147
162
 
148
- ## License
149
163
 
150
- Copyright © 2015 [Slate Studio, LLC](http://slatestudio.com). Character is free software, and may be redistributed under the terms specified in the [license](LICENSE.md).
@@ -0,0 +1,131 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Author: Alexander Kravets <alex@slatestudio.com>,
3
+ # Slate Studio (http://www.slatestudio.com)
4
+ #
5
+ # Coding Guide:
6
+ # https://github.com/thoughtbot/guides/tree/master/style/coffeescript
7
+ # -----------------------------------------------------------------------------
8
+
9
+ # -----------------------------------------------------------------------------
10
+ # INPUT INVERTER IMAGE
11
+ # - depends on Loft character plugin for assets management
12
+ # -----------------------------------------------------------------------------
13
+ class @InputInverterImage extends InputString
14
+
15
+ # PRIVATE ===============================================
16
+
17
+ _add_input: ->
18
+ @_normalize_value()
19
+
20
+ @$el.addClass('input-loft-image')
21
+ @$el.addClass('has-value')
22
+
23
+ @$input =$ "<input type='hidden' name='#{ @name }' value='#{ @_safe_value() }' />"
24
+ @$el.append @$input
25
+
26
+ @_add_image()
27
+ @_add_choose_button()
28
+ @_add_remove_button()
29
+ @_add_alt()
30
+
31
+
32
+ _normalize_value: ->
33
+ if @value.indexOf('<img') > -1
34
+ @value = @value.replace(new RegExp('"', 'g'), "'")
35
+
36
+ if ! @value.indexOf(' alt=') > -1
37
+ @value.replace('<img ', "<img alt='' ")
38
+ else
39
+ @value = "<img src='' alt='' />"
40
+
41
+
42
+ _alt: -> $(@value).attr('alt')
43
+
44
+
45
+ _src: -> $(@value).attr('src')
46
+
47
+
48
+ _add_alt: ->
49
+ @$altInput =$ "<input type='text' value='' placeholder='Text alternative (alt)' />"
50
+ @$el.append @$altInput
51
+
52
+ @_update_alt()
53
+
54
+ @$altInput.on 'change', (e) =>
55
+ newAlt = $(e.target).val()
56
+ @_update_value(@_src(), newAlt)
57
+
58
+
59
+ _update_alt: ->
60
+ @$altInput.val(@_alt())
61
+ if @_src() == '' then @$altInput.hide() else @$altInput.show()
62
+
63
+
64
+ _add_image: ->
65
+ @$image =$ "<a href='' target='_blank' class='image'><img src='' /></a>"
66
+ @$el.append @$image
67
+ @_update_image()
68
+
69
+
70
+ _update_image: ->
71
+ imageUrl = @_src()
72
+ if imageUrl == ''
73
+ @$el.removeClass('has-value')
74
+ @$image.hide()
75
+ else
76
+ @$el.addClass('has-value')
77
+ @$image.attr('href', imageUrl).children().attr('src', imageUrl)
78
+ @$image.show()
79
+
80
+
81
+ _add_choose_button: ->
82
+ @$chooseBtn =$ "<a href='#' class='choose'></a><br/>"
83
+ @$el.append @$chooseBtn
84
+
85
+ @_update_choose_button_title()
86
+
87
+ @$chooseBtn.on 'click', (e) =>
88
+ e.preventDefault()
89
+ chr.modules.assets.showModal 'images', false, (objects) =>
90
+ newSrc = objects[0].file.url
91
+ alt = @_alt() || objects[0].name
92
+ @_update_value(newSrc, alt)
93
+
94
+
95
+ _update_choose_button_title: ->
96
+ title = if @value == '' then 'Choose or upload' else 'Choose other or upload'
97
+ @$chooseBtn.html(title)
98
+
99
+
100
+ _update_value: (src, alt) ->
101
+ value = @value
102
+ value = value.replace("src='#{ @_src() }'", "src='#{ src }'")
103
+ value = value.replace("alt='#{ @_alt() }'", "alt='#{ alt }'")
104
+ @updateValue(value)
105
+
106
+
107
+ _add_remove_button: ->
108
+ @$removeBtn =$ "<a href='#' class='remove'>Remove</a>"
109
+ @$el.append @$removeBtn
110
+
111
+ @$removeBtn.on 'click', (e) =>
112
+ e.preventDefault()
113
+ if confirm('Are you sure?')
114
+ @updateValue('')
115
+
116
+
117
+ # PUBLIC ================================================
118
+
119
+ updateValue: (@value) ->
120
+ @_normalize_value()
121
+ @$input.val(@value)
122
+
123
+ @_update_image()
124
+ @_update_alt()
125
+
126
+
127
+ chr.formInputs['inverter-image'] = InputInverterImage
128
+
129
+
130
+
131
+
@@ -1,3 +1,15 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Author: Alexander Kravets <alex@slatestudio.com>,
3
+ # Slate Studio (http://www.slatestudio.com)
4
+ #
5
+ # Coding Guide:
6
+ # https://github.com/thoughtbot/guides/tree/master/style/coffeescript
7
+ # -----------------------------------------------------------------------------
8
+
9
+ # -----------------------------------------------------------------------------
10
+ # INPUT INVERTER
11
+ # -----------------------------------------------------------------------------
12
+
1
13
  # _slugify(string)
2
14
  if ! @_slugify
3
15
  @_slugify = (string) ->
@@ -7,23 +19,29 @@ if ! @_slugify
7
19
  .replace(/\-\-+/g, '-') # Replace multiple - with single -
8
20
  .trim() # Trim - from start/end of text
9
21
 
10
- # -----------------------------------------------------------------------------
11
- # INPUT HASH
12
- # -----------------------------------------------------------------------------
22
+
13
23
  class @InputInverter
14
24
  constructor: (@name, @value, @config, @object) ->
15
- @_createEl()
25
+ @startsWith = @config.startsWith
26
+ @_create_el()
16
27
 
17
28
  @inputs = {}
18
29
 
19
30
  for name, value of @value
20
- input = @_addInput(name, value, @config)
31
+ input = @_add_input(name, value, @config)
21
32
  @inputs[name] = input
22
33
  @$el.append input.$el
23
34
 
24
35
  return this
25
36
 
26
- _addInput: (name, value) ->
37
+
38
+ # PRIVATE ===============================================
39
+
40
+ _create_el: ->
41
+ @$el =$ "<div class='input-#{ @config.type } #{ @config.klassName }'>"
42
+
43
+
44
+ _add_input: (name, value) ->
27
45
  inputConfig = $.extend {}, @config
28
46
 
29
47
  # get input label and type from name, e.g. "Page Title : text"
@@ -37,26 +55,30 @@ class @InputInverter
37
55
  inputType ?= @config.defaultInputType || 'text'
38
56
  inputType = $.trim(inputType)
39
57
 
40
- if ! _chrFormInputs[inputType]
58
+ if ! chr.formInputs[inputType]
41
59
  inputType = 'text'
42
60
 
61
+ if @startsWith
62
+ # update label if @startsWith is used
63
+ inputConfig.label = inputConfig.label.replace(@startsWith, '').titleize()
64
+
65
+ # use hidden input type for blocks that do not start with @startsWith
66
+ if ! name.startsWith(@startsWith)
67
+ inputType = 'hidden'
68
+
43
69
  # input css class
44
70
  inputConfig.klassName = 'inverter-block-' + _slugify(inputConfig.label)
45
71
  inputConfig.klass ?= 'stacked'
46
72
 
47
- inputClass = _chrFormInputs[inputType]
73
+ inputClass = chr.formInputs[inputType]
48
74
 
49
75
  inputName = if @config.namePrefix then "#{ @config.namePrefix }#{ @name }[#{ name }]" else "#{ @name }[#{ name }]"
50
76
  inputConfig.namePrefix = @config.namePrefix
51
77
 
52
78
  return new inputClass(inputName, value, inputConfig, @object)
53
79
 
54
- _createEl: ->
55
- @$el =$ "<div class='input-#{ @config.type } #{ @config.klassName }'>"
56
80
 
57
- #
58
- # PUBLIC
59
- #
81
+ # PUBLIC ================================================
60
82
 
61
83
  initialize: ->
62
84
  for name, input of @inputs
@@ -64,6 +86,7 @@ class @InputInverter
64
86
 
65
87
  @config.onInitialize?(this)
66
88
 
89
+
67
90
  hash: (hash={}) ->
68
91
  obj = {}
69
92
  for key, input of @inputs
@@ -71,20 +94,18 @@ class @InputInverter
71
94
  hash[@config.klassName] = obj
72
95
  return hash
73
96
 
97
+
74
98
  updateValue: (@value) ->
75
99
  for key, input of @inputs
76
100
  input.updateValue(@value[key])
77
101
 
78
- showErrorMessage: (message) ->
79
- @$el.addClass 'error'
80
- @$errorMessage.html(message)
81
102
 
82
- hideErrorMessage: ->
83
- @$el.removeClass 'error'
84
- @$errorMessage.html('')
103
+ showErrorMessage: (message) -> ;
104
+
105
+ hideErrorMessage: -> ;
85
106
 
86
107
 
87
- _chrFormInputs['inverter'] = InputInverter
108
+ chr.formInputs['inverter'] = InputInverter
88
109
 
89
110
 
90
111
 
@@ -1 +1,2 @@
1
- #= require ./chr/form/input-inverter
1
+ #= require ./input-inverter
2
+ #= require ./input-inverter-image
@@ -16,6 +16,9 @@ module Mongoid
16
16
  # indexes
17
17
  index({ _template_name: 1 })
18
18
 
19
+ # scopes
20
+ default_scope -> { asc(:created_at) }
21
+
19
22
 
20
23
  # returns title to be used in cms and identify page in list
21
24
  def list_item_title
@@ -94,6 +97,11 @@ module Mongoid
94
97
  self._blocks.delete(key)
95
98
  end
96
99
 
100
+ # keep same blocks order as in template
101
+ ordered_blocks = {}
102
+ template_blocks.keys.each { |k| ordered_blocks[k] = self._blocks[k] }
103
+ self._blocks = ordered_blocks
104
+
97
105
  # update page name
98
106
  self._name = name
99
107
 
@@ -9,6 +9,7 @@ module Inverter
9
9
  def render_with_inverter_object(*args, &block)
10
10
  # reset Inveter.object to nil
11
11
  Inverter.reset_object()
12
+
12
13
  # make a pointer to meta_tags for future use
13
14
  Inverter.set_meta_tags(meta_tags)
14
15
 
@@ -0,0 +1,39 @@
1
+ module Inverter
2
+ module TemplateRendererHelper
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ alias_method_chain :render, :inverter_object
7
+ end
8
+
9
+ def render_with_inverter_object(context, options)
10
+ template_name = options[:template]
11
+ prefixes = options[:prefixes]
12
+
13
+ if prefixes
14
+ template_prefix = prefixes[0]
15
+ template_name = "#{ template_prefix }/#{ template_name }"
16
+ end
17
+
18
+ if template_name
19
+ template_name = "#{ template_name }.html.erb"
20
+
21
+ # set inverter object if it's not already set, return nil if already set
22
+ inverter_object = Inverter.update_inverter_object(template_name)
23
+
24
+ if inverter_object
25
+ inverter_object.update_inverter_meta_tags()
26
+ end
27
+ end
28
+
29
+ # original render
30
+ render_without_inverter_object(context, options)
31
+ end
32
+ protected :render_with_inverter_object
33
+
34
+ end
35
+ end
36
+
37
+
38
+
39
+
@@ -1,3 +1,3 @@
1
1
  module Inverter
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.7"
3
3
  end
data/lib/inverter.rb CHANGED
@@ -5,7 +5,7 @@ require "inverter/configuration"
5
5
  require "inverter/parser"
6
6
  require "inverter/version"
7
7
  require "inverter/engine"
8
- require "inverter/template"
8
+ require "inverter/template_renderer_helper"
9
9
 
10
10
  module Inverter
11
11
  extend Configuration
@@ -15,4 +15,4 @@ end
15
15
  require "meta_tags"
16
16
 
17
17
  ActionController::Base.send :include, Inverter::ControllerHelper
18
- ActionView::Template.send :include, Inverter::Template
18
+ ActionView::TemplateRenderer.send :include, Inverter::TemplateRendererHelper
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inverter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Kravets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-23 00:00:00.000000000 Z
11
+ date: 2015-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: render_anywhere
@@ -48,12 +48,14 @@ executables: []
48
48
  extensions: []
49
49
  extra_rdoc_files: []
50
50
  files:
51
+ - ".gitignore"
51
52
  - CONTRIBUTING.md
52
53
  - Gemfile
53
54
  - LICENSE.md
54
55
  - README.md
55
56
  - Rakefile
56
- - app/assets/javascripts/chr/form/input-inverter.coffee
57
+ - app/assets/javascripts/input-inverter-image.coffee
58
+ - app/assets/javascripts/input-inverter.coffee
57
59
  - app/assets/javascripts/inverter.coffee
58
60
  - inverter.gemspec
59
61
  - lib/inverter.rb
@@ -63,7 +65,7 @@ files:
63
65
  - lib/inverter/engine.rb
64
66
  - lib/inverter/object.rb
65
67
  - lib/inverter/parser.rb
66
- - lib/inverter/template.rb
68
+ - lib/inverter/template_renderer_helper.rb
67
69
  - lib/inverter/version.rb
68
70
  homepage: http://slatestudio.com
69
71
  licenses:
@@ -1,24 +0,0 @@
1
- module Inverter
2
- module Template
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- alias_method :initialize_original, :initialize
7
-
8
- def initialize(source, identifier, handler, details)
9
- template_name = identifier.gsub(Rails.root.to_s + '/app/views/', '')
10
- inverter_object = Inverter.update_inverter_object(template_name)
11
-
12
- if inverter_object
13
- inverter_object.update_inverter_meta_tags()
14
- end
15
-
16
- initialize_original(source, identifier, handler, details)
17
- end
18
- end
19
- end
20
- end
21
-
22
-
23
-
24
-