cytoplasm 0.2.3 → 0.2.4

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.
@@ -153,7 +153,8 @@ var Cytoplasm;
153
153
  }
154
154
  });
155
155
  },
156
- setStyles:function(){
156
+ setStyles:function(userstyles){
157
+ if (typeof userstyles != "object") userstyles = {};
157
158
  // Remove existing cytoplasm styles
158
159
  if ($('#cytoplasm_dynamic_styles').is("*")) $('#cytoplasm_dynamic_styles').remove();
159
160
 
@@ -161,7 +162,7 @@ var Cytoplasm;
161
162
  var boldweight = (vars.fonts.faces.bold==vars.fonts.faces.regular)?"bold":"normal";
162
163
  var lightweight = (vars.fonts.faces.light==vars.fonts.faces.regular)?"lighter":"normal";
163
164
  var styletag = "body{margin:0;height:100%;overflow-y:scroll}h1,h2,h3,h4,h5,h6{margin:20px 0}header{overflow:hidden;h1{margin:0;white-space:nowrap;cursor:pointer;display:inline;text-shadow:0 0 10px rgba(0,0,0,0.5)}#logo{z-index:1000}}nav{ul{padding:0;list-style:none;li{display:inline-block}}}#main_content{min-height:400px;background:white;overflow:hidden;box-shadow:0 0 10px rgba(0,0,0,0.8);clear:both;&>:first-child{margin-top:0;padding-top:0}&>:last-child{margin-bottom:0;padding-bottom:0}}footer{overflow:hidden}table.cytoTable{width:100%;margin-bottom:15px;box-shadow:0 0 10px rgba(0,0,0,0.5);td{padding:10px;&.labelcell{width:100px}&>h1,&>h2,&>h3,&>h4,&>h5,&>h6{margin:0;padding:0}}}.cytoField{width:100%;border:1px solid #aaa;border-radius:5px;font-size:14px;box-shadow:inset 0 0 5px rgba(0,0,0,0.25);&[type=text],&[type=password],&[type=email]{height:28px;padding:0 7px}}textarea.cytoField{resize:none;height:200px;padding:7px}button,input[type=submit]{&.cytoButton{border-radius:5px;cursor:pointer;&.large{width:100%;height:50px}}}";
164
- var styles = {
165
+ var styles = $.extend(true,{},{
165
166
  body:{
166
167
  background:vars.colors.global.background,
167
168
  font:vars.fonts.sizes.normal+" "+vars.fonts.faces.regular,
@@ -212,6 +213,9 @@ var Cytoplasm;
212
213
  },
213
214
  'table.cytoTable':{
214
215
  background:vars.colors.plugins.cytoTable.background,
216
+ table:{
217
+ 'margin-bottom':'0px'
218
+ },
215
219
  td:{
216
220
  border:vars.colors.plugins.cytoTable.border,
217
221
  "&.labelcell":{"font-size":vars.fonts.sizes.small}
@@ -227,7 +231,7 @@ var Cytoplasm;
227
231
  "box-shadow":vars.layout.plugins.cytoButton.shadow
228
232
  }
229
233
  }
230
- };
234
+ },userstyles);
231
235
 
232
236
  // Heading sizes
233
237
  (function(){
@@ -252,28 +256,6 @@ var Cytoplasm;
252
256
  var parser = new(less.Parser)({});
253
257
  parser.parse(styletag,function(e,tree){$("<style type='text/css' rel='stylesheet' media='screen' id='cytoplasm_dynamic_styles'>"+tree.toCSS({compress:true})+"</style>").appendTo("head");});
254
258
  },
255
- conf:function(which,value){
256
- var returnvar;
257
- if (which==null) return conf;
258
- if (typeof which != "string") return console.warn("Incorrect argument type passed to $.Cytoplasm(\"conf\")!");
259
- if (which.indexOf(".")>-1) {
260
- returnvar = conf;
261
- var levels = [];
262
- $.each(which.split("."),function(i,level){
263
- levels.push(level);
264
- if (returnvar[level]!=null) returnvar = returnvar[level];
265
- });
266
- } else returnvar = conf[which];
267
- if (returnvar==null) return console.warn("Failed to find Cytoplasm config variable "+which+"!");
268
- if (value==null) return returnvar;
269
- else {
270
- if (levels==null || levels==[]) return conf[which] = value;
271
- var exp = "conf";
272
- $.each(levels,function(i,level){exp += "["+level.toString()+"]"});
273
- exp += " = "+value.toString();
274
- return eval(exp);
275
- }
276
- },
277
259
  vars:function(which,value){
278
260
  var returnvar;
279
261
  if (which==null) return vars;
@@ -32,14 +32,13 @@ module Cytoplasm
32
32
  end
33
33
  def fetch_fs_all
34
34
  fs = {}
35
- fetch_json("http://www.fontsquirrel.com/api/fontlist/all").each do |f|
36
- fs[f["family_urlname"]] = f
37
- end
35
+ fetch_json("http://www.fontsquirrel.com/api/fontlist/all").each {|f| fs[f["family_urlname"]] = f}
38
36
  return fs
39
37
  end
40
38
  def fetch_gwf_all
41
39
  gwf = {}
42
- fetch_json("https://www.googleapis.com/webfonts/v1/webfonts?key="+Cytoplasm.conf("fontloader.googlewebfonts_apikey"))["items"].each {|f| gwf[f["family"]] = f}
40
+ puts "CONFIG: "+Cytoplasm.vars.to_s
41
+ fetch_json("https://www.googleapis.com/webfonts/v1/webfonts?key="+Cytoplasm.vars("setup.fontloader.googlewebfonts_apikey"))["items"].each {|f| gwf[f["family"]] = f}
43
42
  return gwf
44
43
  end
45
44
  def fetch_family(dir,fam)
@@ -13,25 +13,26 @@ module Cytoplasm
13
13
 
14
14
  end
15
15
 
16
- def update
16
+ def colors
17
17
 
18
18
  end
19
19
 
20
- def fetch_conf
21
- Cytoplasm.configure_with("config/initializers/cytoplasm.yml")
22
- return Cytoplasm.conf()
20
+ def advanced
21
+
22
+ end
23
+
24
+ def update
25
+ Cytoplasm.save_config(params)
26
+ redirect_to cytoplasm_advanced_config_url
23
27
  end
24
28
 
25
29
  def fetch_vars
26
- Cytoplasm.load_vars_from("config/initializers/cytoplasm.vars.yml")
30
+ Cytoplasm.load_vars_from("config/cytoplasm-config.yml")
27
31
  return Cytoplasm.vars()
28
32
  end
29
33
 
30
34
  def fetch
31
- success = {}
32
- success["conf"] = fetch_conf()
33
- success["vars"] = fetch_vars()
34
- render :text => Cytoplasm::Ajax.success(success)
35
+ render :text => Cytoplasm::Ajax.success({"vars" => fetch_vars()})
35
36
  end
36
37
 
37
38
  end
@@ -0,0 +1,35 @@
1
+ <%
2
+ def recursive_config_row(k,v)
3
+ k = k.to_s
4
+ output = "<tr><td class='labelcell'>"+k.split("[").pop().split("]")[0].capitalize+":</td><td>"
5
+ if v.is_a? Hash
6
+ output += "<table class='cytoTable'>"
7
+ v.each {|kk,vv| output += recursive_config_row(k+"["+kk.to_s+"]",vv)}
8
+ output += "</table>"
9
+ else
10
+ v = v.to_s
11
+ output += "<input type='text' class='cytoField' name='"+k+"' value='"+v+"' placeholder='"+Cytoplasm.defaults(k.split("[").join(".").gsub("]","")).to_s+"' />"
12
+ end
13
+ output += "</td></tr>"
14
+ return output
15
+ end
16
+ %>
17
+
18
+ <h2>Advanced Configuration Tool</h2>
19
+
20
+ <form id="advanced_config_form" action="<%=cytoplasm_update_url%>" method="post">
21
+ <table class="cytoTable">
22
+ <% Cytoplasm.vars().each do |k,v| %>
23
+ <%= raw recursive_config_row(k,v)%>
24
+ <% end %>
25
+ <tr><td colspan=2><button class="cytoButton large">Save and Apply!</button></td></tr>
26
+ </table>
27
+ </form>
28
+
29
+ <script type="text/javascript">
30
+ (function($){
31
+ $.Cytoplasm("ready",function(){
32
+
33
+ });
34
+ })(jQuery);
35
+ </script>
@@ -7,6 +7,7 @@
7
7
  <li><%=link_to("Layout Settings",cytoplasm_layout_settings_url)%></li>
8
8
  <li><%=link_to("Colors Settings",cytoplasm_colors_settings_url)%></li>
9
9
  <li><%=link_to("Manage Fonts",cytoplasm_fonts_url)%></li>
10
+ <li><%=link_to("Advanced Configuration Tool",cytoplasm_advanced_config_url)%></li>
10
11
  </ul>
11
12
 
12
13
  <script type="text/javascript">
@@ -21,6 +21,22 @@
21
21
  </td>
22
22
  </tr>
23
23
  <tr><td class='headercell' colspan=2><h3>Header</h3></td></tr>
24
+ <tr>
25
+ <td class="labelcell">Position Mode:</td>
26
+ <td>
27
+ <input type="radio" name="layout[header][position]" value="inherit" data-label="Inherit" class="cytoRadio" checked="checked" />
28
+ <input type="radio" name="layout[header][position]" value="static" data-label="Static" />
29
+ <input type="radio" name="layout[header][position]" value="relative" data-label="Relative" />
30
+ <input type="radio" name="layout[header][position]" value="absolute" data-label="Absolute" />
31
+ <input type="radio" name="layout[header][position]" value="fixed" data-label="Fixed" />
32
+ </td>
33
+ </tr>
34
+ <tr>
35
+ <td class="labelcell">Height:</td>
36
+ <td>
37
+ <input type="hidden" name="layout[header][height]" class="cytoSlider" value="140" data-max="500" data-unit="px" data-label="Height of the header tag" />
38
+ </td>
39
+ </tr>
24
40
  <tr><td class='headercell' colspan=2><h3>Content</h3></td></tr>
25
41
  <tr>
26
42
  <td class='labelcell'>Margin:</td>
@@ -48,6 +64,22 @@
48
64
  <script type="text/javascript">
49
65
  (function($){
50
66
  $.Cytoplasm("ready",function(){
67
+ // Header
68
+ $('input[name="layout[header][position]"]').cytoRadio("options",{events:{change:function(){
69
+ $('header').css("position",$(this).cytoRadio("value"));
70
+ switch ($(this).cytoRadio("value")) {
71
+ case "relative":
72
+ case "absolute":
73
+ case "fixed":
74
+
75
+ break;
76
+ }
77
+ }}});
78
+ $('input[name="layout[header][height]"]').cytoSlider("options",{events:{change:function(){
79
+ $('header').height($(this).cytoSlider("value"));
80
+ }}});
81
+
82
+ // Content
51
83
  $('input[name="layout[content][margin_mode]"]').cytoRadio("options",{events:{change:function(){
52
84
  console.log("changed!");
53
85
  }}});
data/config/routes.rb CHANGED
@@ -5,7 +5,9 @@ Rails.application.routes.draw do
5
5
  get "/cytoplasm/general" => "Cytoplasm/settings#general", :as => :cytoplasm_general_settings
6
6
  get "/cytoplasm/layout" => "Cytoplasm/settings#layout", :as => :cytoplasm_layout_settings
7
7
  get "/cytoplasm/colors" => "Cytoplasm/settings#colors", :as => :cytoplasm_colors_settings
8
+ get "/cytoplasm/advanced" => "Cytoplasm/settings#advanced", :as => :cytoplasm_advanced_config
8
9
  post "/cytoplasm/settings/fetch" => "Cytoplasm/settings#fetch"
10
+ post "/cytoplasm/update" => "Cytoplasm/settings#update", :as => :cytoplasm_update
9
11
 
10
12
  # Fonts
11
13
  get "/cytoplasm/fonts" => "Cytoplasm/fonts#index", :controller => Cytoplasm::FontsController, :action => :index, :as => :cytoplasm_fonts
data/lib/cytoplasm.rb CHANGED
@@ -4,22 +4,18 @@ require 'yaml'
4
4
  require 'active_support/core_ext/hash/deep_merge'
5
5
 
6
6
  module Cytoplasm
7
- # List of all Cytoplasm configuration settings, with their corresponding default values.
8
- # Create a YAML file at config/initializers/cytoplasm.yml to extend the default settings.
9
- @conf = {
10
- :jqueryui => {
11
- :version => "1.9.2",
12
- :theme => "ui-darkness"
13
- },
14
- :fontloader => {
15
- :directory => "fontsquirrel",
16
- :googlewebfonts_apikey => "AIzaSyDs7hjZSILIAN3T4oFv3qf_DCyy6PfC30E"
17
- }
18
- }
19
-
20
7
  # List of all Cytoplasm variables, with their corresponding default values.
21
- # Create a YAML file at config/initializers/cytoplasm.vars.yml to extend the default values.
22
- @vars = {
8
+ # Create a YAML file at config/cytoplasm-config.yml to extend the default values.
9
+ @defaults = {
10
+ :setup => {
11
+ :jqueryui => {
12
+ :version => "1.9.2",
13
+ :theme => "ui-darkness"
14
+ },
15
+ :fontloader => {
16
+ :googlewebfonts_apikey => "AIzaSyDs7hjZSILIAN3T4oFv3qf_DCyy6PfC30E"
17
+ }
18
+ },
23
19
  :layout => {
24
20
  :mode => "fluid",
25
21
  :padding => "0px",
@@ -114,6 +110,7 @@ module Cytoplasm
114
110
  }
115
111
  }
116
112
  }
113
+ @vars = @defaults
117
114
  @cssvars = ""
118
115
 
119
116
  # Dependencies
@@ -139,43 +136,21 @@ module Cytoplasm
139
136
  };
140
137
 
141
138
  def initialize
142
- configure_with("config/initializers/cytoplasm.yml")
143
- load_vars_from("config/initializers/cytoplasm.vars.yml")
139
+ load_vars_from("config/cytoplasm-config.yml")
144
140
  end
145
141
 
146
- # Configure through hash
147
- def self.configure(opts={})
148
- opts.each {|k,v| @conf[k.to_sym] = v if @valid_settings.include? k.to_sym}
149
- end
150
142
  def self.load_vars(opts={})
151
- opts = optsToSym(opts)
152
- @vars.deep_merge!(opts)
153
- #opts.each {|k,v| @vars[k.to_sym] = v if @valid_vars.include? k.to_sym}
143
+ @vars = @defaults
144
+ @vars.deep_merge!(opts_to_sym(opts))
154
145
  end
155
146
 
156
- def self.optsToSym(opts)
147
+ def self.opts_to_sym(opts)
157
148
  fixed = {}
158
- unless opts.is_a? Hash
159
- return opts
160
- else
161
- opts.each do |k,v|
162
- fixed[k.to_sym] = ((v.is_a?(Hash)) ? optsToSym(v) : v)
163
- end
164
- end
149
+ return opts unless opts.is_a? Hash
150
+ opts.each {|k,v| fixed[k.to_sym] = ((v.is_a?(Hash)) ? opts_to_sym(v) : v)}
165
151
  return fixed
166
152
  end
167
153
 
168
- # Configure through yaml file
169
- def self.configure_with(path_to_yaml_file)
170
- begin
171
- conf = YAML::load(IO.read(path_to_yaml_file))
172
- rescue Errno::ENOENT
173
- puts "YAML configuration file couldn't be found. Using defaults."; return
174
- rescue Psych::SyntaxError
175
- puts "YAML configuration file contains invalid syntax. Using defaults."; return
176
- end
177
- configure(conf)
178
- end
179
154
  def self.load_vars_from(path_to_yaml_file)
180
155
  begin
181
156
  vars = YAML::load(IO.read(path_to_yaml_file))
@@ -188,55 +163,46 @@ module Cytoplasm
188
163
  compile_css()
189
164
  end
190
165
 
166
+ def self.save_config(opts={})
167
+ puts "SAVING CONFIGURATION FILE"
168
+ load_vars(opts)
169
+ File.open("config/cytoplasm-config.yml", 'w+') {|f| f.write(@vars.to_yaml) }
170
+ end
171
+
191
172
  # Getters and setters
192
- def self.config(which=nil,value=nil)
193
- return @conf if which.nil?
173
+ def self.traverse_hash(hash,which=nil,value=nil)
174
+ return hash if which.nil?
194
175
  if which.is_a? String and which.include? '.'
195
- returnvar = @conf
176
+ returnvar = hash
196
177
  levels = []
197
178
  which.split(".").each do |level|
198
179
  levels << level
199
180
  returnvar = returnvar[level.to_sym] unless returnvar[level.to_sym].nil?
200
181
  end
201
182
  else
202
- returnvar = @conf[which.to_sym]
183
+ returnvar = hash[which.to_sym]
203
184
  end
204
185
 
205
186
  unless returnvar.nil?
206
187
  if value.nil?
207
- return returnvar
188
+ return returnvar.to_s
208
189
  else
209
- @conf[which.to_sym] = value
190
+ if which.include? "."
191
+
192
+ else
193
+ hash[which.to_sym] = value
194
+ end
210
195
  end
211
196
  end
212
197
  end
213
198
  def self.variable(which=nil,value=nil)
214
- return @vars if which.nil?
215
- if which.is_a? String and which.include? '.'
216
- returnvar = @vars
217
- levels = []
218
- which.split(".").each do |level|
219
- levels << level
220
- returnvar = returnvar[level.to_sym] unless returnvar[level.to_sym].nil?
221
- end
222
- else
223
- returnvar = @vars[which.to_sym]
224
- end
225
-
226
- unless returnvar.nil?
227
- if value.nil?
228
- return returnvar
229
- else
230
- @vars[which.to_sym] = value
231
- end
232
- end
233
- end
234
- # Shortcuts to the above
235
- def self.conf(which=nil,value=nil)
236
- return config(which,value)
199
+ traverse_hash(@vars,which,value)
237
200
  end
238
201
  def self.vars(which=nil,value=nil)
239
- return variable(which,value)
202
+ variable(which,value)
203
+ end
204
+ def self.defaults(which=nil,value=nil)
205
+ traverse_hash(@defaults,which,value)
240
206
  end
241
207
 
242
208
  # Dependency loaders
@@ -254,16 +220,11 @@ module Cytoplasm
254
220
  end
255
221
  end
256
222
  when "css"
257
- deps << "http://ajax.googleapis.com/ajax/libs/jqueryui/"+conf("jqueryui.version")+"/themes/"+conf("jqueryui.theme")+"/jquery-ui.css"
223
+ deps << "http://ajax.googleapis.com/ajax/libs/jqueryui/"+vars("setup.jqueryui.version")+"/themes/"+vars("setup.jqueryui.theme")+"/jquery-ui.css"
258
224
  deps += load_fonts()
259
- #deps << "cytoplasm/cytoplasm-"+Time.now.to_i.to_s
260
- @dependencies[:css].each do |stylesheet|
261
- deps << "cytoplasm/"+stylesheet
262
- end
225
+ @dependencies[:css].each {|stylesheet| deps << "cytoplasm/"+stylesheet}
263
226
  when "js"
264
- @dependencies[:js].each do |plugin|
265
- deps << "cytoplasm/"+plugin
266
- end
227
+ @dependencies[:js].each {|plugin| deps << "cytoplasm/"+plugin}
267
228
  end
268
229
  return deps
269
230
  end
@@ -287,9 +248,7 @@ module Cytoplasm
287
248
 
288
249
  File.open(varfile,"wb") do |f|
289
250
  css = ""
290
- @vars.each do |k,v|
291
- css += hash_to_css(k,v)
292
- end
251
+ @vars.each {|k,v| css += hash_to_css(k,v)}
293
252
  f.write(css)
294
253
  end
295
254
  end
@@ -298,9 +257,7 @@ module Cytoplasm
298
257
  output = ""
299
258
  if v.is_a? Hash
300
259
  parent += "#{k}_"
301
- v.each do |kk,vv|
302
- output += hash_to_css(kk,vv,parent)
303
- end
260
+ v.each {|kk,vv| output += hash_to_css(kk,vv,parent)}
304
261
  return output
305
262
  else
306
263
  k = k.to_s
@@ -1,3 +1,3 @@
1
1
  module Cytoplasm
2
- VERSION = "0.2.3"
3
- end
2
+ VERSION = "0.2.4"
3
+ end
@@ -0,0 +1,73 @@
1
+ ---
2
+ :setup:
3
+ :jqueryui:
4
+ :version: 1.9.2
5
+ :theme: ui-darkness
6
+ :fontloader:
7
+ :googlewebfonts_apikey: AIzaSyDs7hjZSILIAN3T4oFv3qf_DCyy6PfC30E
8
+ :layout:
9
+ :mode: fluid
10
+ :padding: 0px
11
+ :header:
12
+ :margin: 0px
13
+ :padding: 10px
14
+ :logo:
15
+ :enabled: 'true'
16
+ :position: absolute
17
+ :align: left
18
+ :x: 0px
19
+ :y: 0px
20
+ :nav:
21
+ :enabled: 'true'
22
+ :align: right
23
+ :background: transparent
24
+ :font: light
25
+ :content:
26
+ :margin: 0px
27
+ :padding: 20px
28
+ :footer:
29
+ :margin: 0px
30
+ :padding: 10px
31
+ :plugins:
32
+ :cytoButton:
33
+ :shadow: inset 0px 0px 10px rgba(0,0,0,0.5)
34
+ :fonts:
35
+ :faces:
36
+ :light: TitilliumTextLight
37
+ :regular: TitilliumTextRegular
38
+ :bold: TitilliumTextBold
39
+ :sizes:
40
+ :small: 12px
41
+ :normal: 14px
42
+ :huge: 48px
43
+ :heading_factor: '1.8'
44
+ :colors:
45
+ :global:
46
+ :background: green
47
+ :text: black
48
+ :accent: ! '#aaff7f'
49
+ :header:
50
+ :background: transparent
51
+ :text: white
52
+ :content:
53
+ :background: white
54
+ :text: inherit
55
+ :footer:
56
+ :background: transparent
57
+ :text: white
58
+ :plugins:
59
+ :cytoTable:
60
+ :background: ! '#eeeeee'
61
+ :border: ! '1px solid #cccccc'
62
+ :text: inherit
63
+ :cytoButton:
64
+ :background: linear-gradient(to bottom, yellow, green)
65
+ :border: 1px solid green
66
+ :text: inherit
67
+ :cytoSelect: {}
68
+ :cytoRadio: {}
69
+ :cytoSlider: {}
70
+ :cytoUpload: {}
71
+ :cytoColorPicker: {}
72
+ :controller: cytoplasm/settings
73
+ :action: update