orange 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,122 @@
1
+ /*
2
+ * Metadata - jQuery plugin for parsing metadata from elements
3
+ *
4
+ * Copyright (c) 2006 John Resig, Yehuda Katz, J�örn Zaefferer, Paul McLanahan
5
+ *
6
+ * Dual licensed under the MIT and GPL licenses:
7
+ * http://www.opensource.org/licenses/mit-license.php
8
+ * http://www.gnu.org/licenses/gpl.html
9
+ *
10
+ * Revision: $Id: jquery.metadata.js 4187 2007-12-16 17:15:27Z joern.zaefferer $
11
+ *
12
+ */
13
+
14
+ /**
15
+ * Sets the type of metadata to use. Metadata is encoded in JSON, and each property
16
+ * in the JSON will become a property of the element itself.
17
+ *
18
+ * There are three supported types of metadata storage:
19
+ *
20
+ * attr: Inside an attribute. The name parameter indicates *which* attribute.
21
+ *
22
+ * class: Inside the class attribute, wrapped in curly braces: { }
23
+ *
24
+ * elem: Inside a child element (e.g. a script tag). The
25
+ * name parameter indicates *which* element.
26
+ *
27
+ * The metadata for an element is loaded the first time the element is accessed via jQuery.
28
+ *
29
+ * As a result, you can define the metadata type, use $(expr) to load the metadata into the elements
30
+ * matched by expr, then redefine the metadata type and run another $(expr) for other elements.
31
+ *
32
+ * @name $.metadata.setType
33
+ *
34
+ * @example <p id="one" class="some_class {item_id: 1, item_label: 'Label'}">This is a p</p>
35
+ * @before $.metadata.setType("class")
36
+ * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
37
+ * @desc Reads metadata from the class attribute
38
+ *
39
+ * @example <p id="one" class="some_class" data="{item_id: 1, item_label: 'Label'}">This is a p</p>
40
+ * @before $.metadata.setType("attr", "data")
41
+ * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
42
+ * @desc Reads metadata from a "data" attribute
43
+ *
44
+ * @example <p id="one" class="some_class"><script>{item_id: 1, item_label: 'Label'}</script>This is a p</p>
45
+ * @before $.metadata.setType("elem", "script")
46
+ * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
47
+ * @desc Reads metadata from a nested script element
48
+ *
49
+ * @param String type The encoding type
50
+ * @param String name The name of the attribute to be used to get metadata (optional)
51
+ * @cat Plugins/Metadata
52
+ * @descr Sets the type of encoding to be used when loading metadata for the first time
53
+ * @type undefined
54
+ * @see metadata()
55
+ */
56
+
57
+ (function($) {
58
+
59
+ $.extend({
60
+ metadata : {
61
+ defaults : {
62
+ type: 'class',
63
+ name: 'metadata',
64
+ cre: /({.*})/,
65
+ single: 'metadata'
66
+ },
67
+ setType: function( type, name ){
68
+ this.defaults.type = type;
69
+ this.defaults.name = name;
70
+ },
71
+ get: function( elem, opts ){
72
+ var settings = $.extend({},this.defaults,opts);
73
+ // check for empty string in single property
74
+ if ( !settings.single.length ) settings.single = 'metadata';
75
+
76
+ var data = $.data(elem, settings.single);
77
+ // returned cached data if it already exists
78
+ if ( data ) return data;
79
+
80
+ data = "{}";
81
+
82
+ if ( settings.type == "class" ) {
83
+ var m = settings.cre.exec( elem.className );
84
+ if ( m )
85
+ data = m[1];
86
+ } else if ( settings.type == "elem" ) {
87
+ if( !elem.getElementsByTagName )
88
+ return undefined;
89
+ var e = elem.getElementsByTagName(settings.name);
90
+ if ( e.length )
91
+ data = $.trim(e[0].innerHTML);
92
+ } else if ( elem.getAttribute != undefined ) {
93
+ var attr = elem.getAttribute( settings.name );
94
+ if ( attr )
95
+ data = attr;
96
+ }
97
+
98
+ if ( data.indexOf( '{' ) <0 )
99
+ data = "{" + data + "}";
100
+
101
+ data = eval("(" + data + ")");
102
+
103
+ $.data( elem, settings.single, data );
104
+ return data;
105
+ }
106
+ }
107
+ });
108
+
109
+ /**
110
+ * Returns the metadata object for the first member of the jQuery object.
111
+ *
112
+ * @name metadata
113
+ * @descr Returns element's metadata object
114
+ * @param Object opts An object contianing settings to override the defaults
115
+ * @type jQuery
116
+ * @cat Plugins/Metadata
117
+ */
118
+ $.fn.metadata = function( opts ){
119
+ return $.metadata.get( this[0], opts );
120
+ };
121
+
122
+ })(jQuery);
@@ -0,0 +1,12 @@
1
+ class OrangeContactForms < Orange::Carton
2
+ id
3
+ admin do
4
+ title :title
5
+ text :to_address
6
+ end
7
+
8
+ def self.named(tag)
9
+ all(:title.like => "%#{tag}%")
10
+ end
11
+
12
+ end
@@ -0,0 +1,13 @@
1
+ Dir.glob(File.join(File.dirname(__FILE__), 'cartons', '*.rb')).each {|f| require f }
2
+ Dir.glob(File.join(File.dirname(__FILE__), 'resources', '*.rb')).each {|f| require f }
3
+
4
+ module Orange::Plugins
5
+ class ContactForms < Base
6
+ views_dir File.join(File.dirname(__FILE__), 'views')
7
+ assets_dir File.join(File.dirname(__FILE__), 'assets')
8
+ resource Orange::ContactFormsResource.new
9
+ end
10
+ end
11
+
12
+ Orange.plugin(Orange::Plugins::ContactForms.new)
13
+
@@ -0,0 +1,56 @@
1
+ require 'mail'
2
+
3
+ module Orange
4
+ class ContactFormsResource < Orange::ModelResource
5
+ use OrangeContactForms
6
+ call_me :contactforms
7
+ def stack_init
8
+ orange[:admin, true].add_link("Content", :resource => @my_orange_name, :text => 'Contact Forms')
9
+ orange[:radius].define_tag "contactform" do |tag|
10
+ if tag.attr["name"] && model_class.named(tag.attr["name"]).count >0
11
+ m = model_class.named(tag.attr["name"]).first #selects contactform based on title
12
+ elsif model_class.all.count > 0
13
+ if tag.attr["id"]
14
+ m = model_class.get(tag.attr["id"])
15
+ else
16
+ m = model_class.first
17
+ end
18
+ end
19
+ unless m.nil?
20
+ template = tag.attr["template"] || "contactform"
21
+ orange[:contactforms].contactform(tag.locals.packet, {:model => m, :template => template, :id => m.id})
22
+ else
23
+ ""
24
+ end
25
+ end
26
+ end
27
+
28
+ def contactform(packet, opts = {})
29
+ template = opts[:template].to_sym || :contactform
30
+ packet['route.return_path'] = packet.request.path.to_s
31
+ do_view(packet, template, opts)
32
+ end
33
+
34
+ def mailer(packet, opts = {})
35
+ params = packet.request.params
36
+ route = params['r']
37
+ if params['contact_phone'] != ''
38
+ packet.flash['error'] = "An error has occurred. Please try your submission again."
39
+ packet.reroute(route)
40
+ end
41
+ path = packet['route.path']
42
+ parts = path.split('/')
43
+ form = model_class.get(parts.last.to_i)
44
+ mail = Mail.new do
45
+ from "WNSF <info@wnsf.org>"
46
+ to form.to_address
47
+ subject 'E-mail contact from WNSF.org - '+form.title
48
+ body "From: "+params['contact_from']+" ("+params['contact_email_address']+")\n\nMessage:\n"+params['contact_message']
49
+ end
50
+ mail.delivery_method :sendmail
51
+ mail.deliver
52
+ packet.flash['error'] = "Thanks for your submission. We will contact you as soon as possible."
53
+ packet.reroute(route)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,20 @@
1
+ :javascript
2
+ $(function(){
3
+ $('.contact_form').validate();
4
+ });
5
+ %p
6
+ %h3= model.title
7
+ - if(flash['error'])
8
+ .error= flash('error')
9
+ %form{ :class => 'contact_form', :id => 'contact_form_'+model.id.to_s, :action => route_to(:contactforms, :mailer, model.id), :method => 'POST' }
10
+ %label{ :for => 'contact_from'} Your Name
11
+ %input{ :type => 'text', :class => 'required', :minlength => '4', :maxlength => '80', :id => 'contact_from', :name => 'contact_from' }
12
+ %div.contact_phone
13
+ %label{ :for => 'contact_from'} Your Phone
14
+ %input{ :type => 'text', :class => '', :id => 'contact_phone', :name => 'contact_phone', :value => '' }
15
+ %label{ :for => 'contact_email_address'} Your E-mail
16
+ %input{ :type => 'text', :class => 'email required', :id => 'contact_email_address', :name => 'contact_email_address' }
17
+ %input{ :type => 'hidden', :id => 'r', :name => 'r', :value => packet['route.return_path'] }
18
+ %label{ :for => 'contact_message'} Message
19
+ %textarea{ :class =>'required', :id => 'contact_message', :name => 'contact_message', :minlength => '6', :maxlength => '300' }= "&nbsp;"
20
+ %input{ :type => 'submit', :value => 'Submit' }
@@ -50,8 +50,8 @@ module Orange
50
50
  end
51
51
  end
52
52
  packet.reroute(@my_orange_name, :orange) unless (packet.request.xhr? || no_reroute)
53
- end
54
-
53
+ end
54
+
55
55
  # Creates a new model object and saves it (if a post), then reroutes to the main page
56
56
  # @param [Orange::Packet] packet the packet being routed
57
57
  def onNew(packet, params = {})
@@ -65,13 +65,22 @@ module Orange
65
65
  # Saves updates to an object specified by packet['route.resource_id'], then reroutes to main
66
66
  # @param [Orange::Packet] packet the packet being routed
67
67
  def onSave(packet, m, params = {})
68
- params[:published] = false
69
- m.update(params)
70
- m.orange_site = packet['site'] unless m.orange_site
71
- m.save
68
+ if (params["published"] == "1")
69
+ params["published"] = true
70
+ m.update(params)
71
+ m.orange_site = packet['site'] unless m.orange_site
72
+ orange[:pages].publish(packet, :no_reroute => true)
73
+ else
74
+ params["published"] = false
75
+ m.update(params)
76
+ m.orange_site = packet['site'] unless m.orange_site
77
+ m.save
78
+ end
72
79
  end
73
80
 
74
-
81
+ def find_list(packet, mode)
82
+ model_class.all(:orange_site => packet['site']) || []
83
+ end
75
84
 
76
85
  # Returns a single object found by the model class, given an id.
77
86
  # If id isn't given, we return false.
@@ -5,9 +5,18 @@
5
5
  - for prop in props
6
6
  %p~ view_attribute(prop, model_name, :label => true, :value => model.attribute_get(prop[:name]))
7
7
  %a{:href => route_to(model_name, model['id'], {:context => 'preview', :mode => 'show'}), :rel => 'external', :target => "_blank"}Preview
8
+ :javascript
9
+ $(function(){
10
+ $('button.link_button').click(
11
+ function(){
12
+ $('input[name="pages[published]"]').val('true');
13
+ }
14
+ );
15
+ });
16
+ %input{:type => 'hidden', :id => 'pages[published]', :name => 'pages[published]', :value => 'false'}
8
17
  %input{:type => 'submit', :value => 'Save Changes'}
9
18
  / = route_to(model_name, model[:id], 'publish')
10
- = form_link('Publish', packet.route_to(model_name, model[:id], 'publish'))
19
+ = form_link('Publish', packet.route_to(model_name, model[:id], 'save'))
11
20
  %h3 Published Versions
12
21
  %ul.version_list
13
22
  / %li (Current Draft)
@@ -4,7 +4,7 @@ require 'dm-is-awesome_set'
4
4
  class OrangeRoute < Orange::SiteCarton
5
5
  id
6
6
  admin do
7
- text :slug
7
+ text :slug, :display_name => "Search Engine Friendly Page URL"
8
8
  text :link_text
9
9
  boolean :show_in_nav, :default => false, :display_name => 'Show in Navigation?'
10
10
  end
@@ -9,7 +9,7 @@ module Orange::Middleware
9
9
  # purpose of exposing the context object.
10
10
  class RadiusParser < Base
11
11
  def init(opts = {})
12
- @contexts = opts[:contexts] || [:live]
12
+ @contexts = opts[:radius_contexts] || [:live]
13
13
  # orange.load Orange::Radius.new, :radius
14
14
  end
15
15
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 8
9
- version: 0.2.8
8
+ - 9
9
+ version: 0.2.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - David Haslem
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-18 00:00:00 -04:00
17
+ date: 2010-05-23 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -156,9 +156,20 @@ files:
156
156
  - lib/orange-more/blog/views/blog/blog_post_view.haml
157
157
  - lib/orange-more/blog/views/blog/sitemap_row.haml
158
158
  - lib/orange-more/blog/views/blog_posts/edit.haml
159
+ - lib/orange-more/blog/views/blog_posts/show.haml
159
160
  - lib/orange-more/cloud.rb
160
161
  - lib/orange-more/cloud/plugin.rb
161
162
  - lib/orange-more/cloud/resources/cloud_resource.rb
163
+ - lib/orange-more/contactforms.rb
164
+ - lib/orange-more/contactforms/assets/js/jquery.validate.pack.js
165
+ - lib/orange-more/contactforms/assets/js/lib/jquery-1.4.2.js
166
+ - lib/orange-more/contactforms/assets/js/lib/jquery.form.js
167
+ - lib/orange-more/contactforms/assets/js/lib/jquery.js
168
+ - lib/orange-more/contactforms/assets/js/lib/jquery.metadata.js
169
+ - lib/orange-more/contactforms/cartons/contactforms_carton.rb
170
+ - lib/orange-more/contactforms/plugin.rb
171
+ - lib/orange-more/contactforms/resources/contactforms_resource.rb
172
+ - lib/orange-more/contactforms/views/contactforms/contactform.haml
162
173
  - lib/orange-more/debugger.rb
163
174
  - lib/orange-more/debugger/assets/css/debug_bar.css
164
175
  - lib/orange-more/debugger/middleware/debugger.rb