cedar 0.0.5.pre → 0.0.6.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: acef5941c14bbcb1c6b19d460cf8d36e38871302
4
- data.tar.gz: 01bc4d750b27f8b1a26ca13ddb37e5b47734d48c
3
+ metadata.gz: 58111764bdfb5c2ec636954edf7541c25eb583dc
4
+ data.tar.gz: a02844c34a92ed350db5096afd21b9ce9d730d04
5
5
  SHA512:
6
- metadata.gz: bdb4a33c1e9d85447b8c2c30ae63841c1b4cb6dc27deea51d26e9ec16b2d168be67d16f25ae45eb601bb52791ec323d933dfcdb76137728f00ba7c03affafe24
7
- data.tar.gz: dd5a97a2da202d6e72a553759681377b5d7424d96c0bdebb7e48e10bff61e33de7fa3e4e17a3d401eb02cf6d9151319d01d0897bc9934ab91562456c44b9b0f7
6
+ metadata.gz: 936d4cb40c51c1eaaf078e01a23c00a0da1c1d25a36dcb08b50f2dd9b178e7e81b9ad25348764710b24fe84de9c0ee0d3394a4e811f14543bfbeee86cd3b7a27
7
+ data.tar.gz: 57d1ce79ea55e2f970384c92dd1a27712b1d0eaa6e3513197a73f2ce2870e7e4508aca917dff18f1fc90a2e603934fb0991db6c464240bf9ad0371907fb70c24
@@ -0,0 +1,222 @@
1
+ /**
2
+ * Global object for settings and storage
3
+ */
4
+ var Cedar = {
5
+ initialized: false,
6
+ store: null,
7
+ auth: null,
8
+ config: {
9
+ api: 'http://jed.cdr.core.plyinc.dev/api',
10
+ server: 'http://jed.cdr.core.plyinc.dev/'
11
+ }
12
+ };
13
+
14
+
15
+ /**
16
+ * Cedar.Init
17
+ *
18
+ * take care of global initializations
19
+ */
20
+ Cedar.Init = function() {
21
+ if ( Cedar.initialized ) {
22
+ return;
23
+ }
24
+
25
+ if ( Cedar.store === null ) {
26
+ Cedar.store = new Cedar.Store();
27
+ }
28
+
29
+ if ( Cedar.auth === null ) {
30
+ Cedar.auth = new Cedar.Auth();
31
+ }
32
+
33
+ if (Cedar.auth.isEditMode()) {
34
+ jQuery( document ).ready(function( $ ) {
35
+ var logOff = '<a href="" onclick="location.reload(true)" style="position: absolute; bottom: 20px; right: 120px; ">[refresh]</a>';
36
+ logOff += '<a href="' + Cedar.auth.getLogOffURL() + '" style="position: absolute; bottom: 20px; right: 60px; ">[logout]</a>';
37
+ $(document.body).append(logOff);
38
+ });
39
+ }
40
+
41
+ Cedar.initialized = true;
42
+ }
43
+
44
+
45
+ /**
46
+ * Cedar.Auth
47
+ *
48
+ * responsible for determining if we're authorized for edit mode
49
+ */
50
+ Cedar.Auth = function() {
51
+ }
52
+ Cedar.Auth.prototype.isEditMode = function() {
53
+ return this.isEditUrl();
54
+ }
55
+ Cedar.Auth.prototype.isEditUrl = function() {
56
+ var sPageURL = window.location.search.substring(1);
57
+ var sURLVariables = sPageURL.split('&');
58
+ for (var i = 0; i < sURLVariables.length; i++) {
59
+ if (sURLVariables[i] == 'cdrlogin') {
60
+ return true;
61
+ }
62
+ }
63
+ return false;
64
+ }
65
+ Cedar.Auth.prototype.getLogOffURL = function() {
66
+ return this.removeURLParameter(window.location.href, 'cdrlogin');
67
+ }
68
+
69
+ // adapted from stackoverflow: http://stackoverflow.com/questions/1634748/how-can-i-delete-a-query-string-parameter-in-javascript
70
+ Cedar.Auth.prototype.removeURLParameter = function(url, parameter) {
71
+ //prefer to use l.search if you have a location/link object
72
+ var urlparts= url.split('?');
73
+ if (urlparts.length>=2) {
74
+
75
+ var prefix= encodeURIComponent(parameter); //+'=';
76
+ var pars= urlparts[1].split(/[&;]/g);
77
+
78
+ //reverse iteration as may be destructive
79
+ for (var i= pars.length; i-- > 0;) {
80
+ //idiom for string.startsWith
81
+ if (pars[i].lastIndexOf(prefix, 0) !== -1) {
82
+ pars.splice(i, 1);
83
+ }
84
+ }
85
+
86
+ url= urlparts[0];
87
+ if (pars.length > 0) {
88
+ url += '?'+pars.join('&');
89
+ }
90
+ return url;
91
+ } else {
92
+ return url;
93
+ }
94
+ }
95
+
96
+
97
+ /**
98
+ * Cedar.Store
99
+ *
100
+ * responsible for retrieving Cedar elements from server or local cache.
101
+ */
102
+ Cedar.Store = function() {
103
+ this._cache = {};
104
+ }
105
+
106
+ Cedar.Store.prototype.put = function ( key, item ) {
107
+ this._cache[key] = item;
108
+ }
109
+
110
+ // different cedar types may use different api paths
111
+ Cedar.Store.prototype.find = function ( key, getPath ) {
112
+ if ( getPath === null )
113
+ console.log('Cedar Error: must provide api "get" path');
114
+
115
+ if (typeof this._cache[key] === 'undefined'){
116
+ return $.getJSON(Cedar.config.api + getPath + key, function(json) {
117
+ this.put(key, json);
118
+ console.log('retrieved from server');
119
+ }.bind(this));
120
+ }
121
+ else {
122
+ console.log('retrieved from cache');
123
+ return $.Deferred().resolve(this._cache[key]);
124
+ }
125
+ return false;
126
+ }
127
+
128
+ Cedar.Store.prototype.clear = function(key) {
129
+ delete this._cache[key];
130
+ }
131
+
132
+
133
+ /**
134
+ * Cedar.ContentEntry
135
+ *
136
+ * basic content block class
137
+ *
138
+ *
139
+ *
140
+ * options:
141
+ *
142
+ * {
143
+ * el (element or jQuery selector)
144
+ * }
145
+ */
146
+ Cedar.ContentEntry = function(options) {
147
+ Cedar.Init();
148
+
149
+ var defaults = {
150
+ el: 'div'
151
+ };
152
+
153
+ this.options = $.extend( {}, defaults, options );
154
+
155
+ this.cedarId = this.options.cedarId;
156
+ this.el = this.options.el;
157
+ this.$el = $(this.el);
158
+ this.apiGet = '/objects/contententries/';
159
+ }
160
+
161
+ // parse the json for the relevant content
162
+ Cedar.ContentEntry.prototype.setContent = function(json) {
163
+ if (json.code == "UNKNOWN_ID"){
164
+ this.content = '&nbsp;'; // if an element is new, fill with blank space to allow edit box to display
165
+ }
166
+ else if (typeof json.settings.content !== 'undefined') {
167
+ this.content = json.settings.content;
168
+ }
169
+ else {
170
+ this.content = '';
171
+ console.log('Cedar Error: Unable to parse json');
172
+ }
173
+ }
174
+
175
+ // takes into account edit mode styling
176
+ Cedar.ContentEntry.prototype.getContent = function(options){
177
+ if (Cedar.auth.isEditMode()) {
178
+ return this.getEditOpen(this.cedarId) + this.content + this.getEditClose();
179
+ }
180
+ else {
181
+ return this.content;
182
+ }
183
+ }
184
+
185
+ // element is optional parameter
186
+ Cedar.ContentEntry.prototype.fill = function(element) {
187
+ if (typeof element !== 'undefined') {
188
+ $(element).html(this.getContent());
189
+ }
190
+ else if (typeof this.$el !== 'undefined') {
191
+ this.$el.html(this.getContent());
192
+ }
193
+ }
194
+
195
+ // check store for content
196
+ Cedar.ContentEntry.prototype.retrieve = function() {
197
+ return Cedar.store.find(this.cedarId, this.apiGet ).done( function(json) {
198
+ this.setContent(json);
199
+ this.json = json;
200
+ }.bind(this));
201
+ }
202
+
203
+ // fill the asssociated element with the retrieved content
204
+ Cedar.ContentEntry.prototype.render = function() {
205
+ this.retrieve().done(function() {
206
+ this.fill();
207
+ }.bind(this));
208
+ }
209
+
210
+ // styling for edit box
211
+ Cedar.ContentEntry.prototype.getEditOpen = function(id) {
212
+ var block;
213
+ block = '<span class="cedar-cms-editable clearfix">';
214
+ block += '<span class="cedar-cms-edit-tools">';
215
+ block += '<a target="cedarEdit" href="' + Cedar.config.server + 'cmsadmin/EditData?cdr=1&t=ContentEntry&o=' + encodeURIComponent(id) + '" class="cedar-cms-edit-icon" >';
216
+ block += '<b class="cedar-cms-edit-label">content block</b><i class="cedar-cms-icon cedar-cms-icon-right cedar-cms-icon-edit"></i></a>';
217
+ block += '</span>';
218
+ return block;
219
+ }
220
+ Cedar.ContentEntry.prototype.getEditClose = function(){
221
+ return '</span>';
222
+ }
@@ -0,0 +1,25 @@
1
+ // Marionette
2
+ var CedarMarionetteHeader = Backbone.Marionette.ItemView.extend({
3
+ template : function(serialized_model) {
4
+ return _.template('<h1><%= content %></h1>')(serialized_model);
5
+ }
6
+ });
7
+ var CedarMarionetteParagraph = Backbone.Marionette.ItemView.extend({
8
+ template : function(serialized_model) {
9
+ return _.template('<p><%= content %></p>')(serialized_model);
10
+ }
11
+ });
12
+
13
+ var CedarMarionetteLayout = Backbone.Marionette.LayoutView.extend({
14
+ template: '#layout-view-template',
15
+
16
+ regions: {
17
+ cedarHeading: '.js-cedar-heading',
18
+ anotherParagraph: '.js-cedar-paragraph'
19
+ },
20
+
21
+ onRender: function() {
22
+ this.cedarHeading.show(new CedarMarionetteHeader({model: this.options.heading}))
23
+ this.anotherParagraph.show(new CedarMarionetteParagraph({model: this.options.introText}))
24
+ }
25
+ });
@@ -0,0 +1,6 @@
1
+ // for intergration demonstration only - not currently used
2
+
3
+ /*
4
+ Cedar.config.api = '<%= Rails.application.routes.url_helpers.cedar_index_path %>';
5
+ Cedar.config.server = '<%= Cedar::Application.config.cedar_server %>';
6
+ */
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Styles particular to the CMS when in "edit-mode" while viewing a front-end page.
3
+ * @browsers ALL
4
+ **/
5
+
6
+
7
+
8
+
9
+ .cedar-cms-editable {
10
+ display: block !important;
11
+ border: 1px dotted #F65126 !important
12
+ }
13
+
14
+ .cedar-cms-edit-tools {
15
+ font-family: Arial, sans-serif;
16
+ position: relative;
17
+ display: block !important;
18
+ font-size: 10px !important;
19
+ line-height: 1.2 !important;
20
+ text-align: left !important;
21
+ }
22
+
23
+ .cedar-cms-edit-tools a {
24
+ color: #F26521 !important;
25
+ text-decoration: none !important;
26
+ }
27
+
28
+ .cedar-cms-edit-tools a:hover {
29
+ color: #FA8A2D !important;
30
+ text-decoration: none !important;
31
+ }
32
+
33
+ .cedar-cms-edit-label {
34
+ color: #F26521 !important;
35
+ text-transform: uppercase;
36
+ font-size: 10px;
37
+ padding: 0 6px;
38
+ }
39
+
40
+ .cedar-cms-edit-tools .cedar-cms-edit-icon,
41
+ .cedar-cms-edit-tools .cedar-cms-edit-icon:hover {
42
+ display: block;
43
+ position: absolute;
44
+ top: 0;
45
+ right: 0;
46
+ height: 18px;
47
+ z-index: 1001;
48
+ border: 1px solid #fff;
49
+ background-color: #ffddd0 !important;
50
+ padding: 0;
51
+ }
52
+
53
+ /* 4 classes to display icons */
54
+
55
+ .cedar-cms-edit-tools.spacer {
56
+ height: 20px;
57
+ }
58
+
59
+ .cedar-cms-edit-tools.left-align .cedar-cms-edit-icon {
60
+ right: auto;
61
+ left: 0;
62
+ }
63
+
64
+ /* Standalone icons */
65
+ .cedar-cms-icon {
66
+ min-height: 18px;
67
+ width: 18px;
68
+ height: 18px;
69
+ display: -moz-inline-stack;
70
+ display: inline-block;
71
+ vertical-align: middle;
72
+ zoom: 1;
73
+ *display: inline;
74
+ _height: 18px;
75
+ background: transparent url(cedar-display-tools-sprite.png) scroll no-repeat 0 0;
76
+ }
77
+
78
+ .cedar-cms-icon-right {
79
+ border-right: 0;
80
+ border-left: 1px solid #fff;
81
+ }
82
+
83
+
84
+ .cedar-cms-icon-edit {
85
+ background-position: -89px -20px;
86
+ }
data/lib/cedar/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cedar
2
- VERSION = "0.0.5.pre"
2
+ VERSION = "0.0.6.pre"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cedar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5.pre
4
+ version: 0.0.6.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jed Murdock
@@ -51,6 +51,11 @@ files:
51
51
  - README.md
52
52
  - Rakefile
53
53
  - cedar.gemspec
54
+ - lib/assets/images/cedar-display-tools-sprite.png
55
+ - lib/assets/javascripts/cedar.js
56
+ - lib/assets/javascripts/cedar.marionette.js
57
+ - lib/assets/javascripts/cedarInit.js.erb
58
+ - lib/assets/stylesheets/cedar.scss
54
59
  - lib/cedar.rb
55
60
  - lib/cedar/version.rb
56
61
  homepage: http://plyinteractive.com