widgets 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,21 @@
1
1
  class WidgetsController < ApplicationController
2
2
  layout false
3
3
 
4
+ def remove
5
+ @id = params.delete(:id)
6
+ respond_to :js
7
+ end
8
+
9
+ def replace
10
+ @id = params.delete(:id)
11
+ @name = params.delete(:name)
12
+ @options = params.except(:controller, :action).to_hash.symbolize_keys!
13
+
14
+ respond_to :js
15
+ end
16
+
4
17
  def show
5
18
  @name = params.delete(:id)
6
- @id = params.delete(:widget_id)
7
19
  @options = params.except(:controller, :action).to_hash.symbolize_keys!
8
20
 
9
21
  respond_to :html, :js
@@ -0,0 +1,27 @@
1
+ require 'guid'
2
+
3
+ module ApplicationHelper
4
+ #include ActionView::Helpers::UrlHelper
5
+
6
+ def widget(name, options={}, &block)
7
+ id = Guid.new.to_s
8
+ partial = File.join 'widgets', name.to_s
9
+ attributes = {:id => id, :'data-widget' => name, :style => options.delete(:style), :class => options.delete(:effects)}
10
+ options = {widget_id: id, widget_name: name}.merge options
11
+
12
+ html = if block_given?
13
+ render :layout => partial, :inline => capture(&block), :locals => options, :formats => [:html]
14
+ else
15
+ render :template => partial, :locals => options, :formats => [:html]
16
+ end
17
+
18
+ javascript = render :template => partial, :locals => options, :formats => [:js] rescue ActionView::MissingTemplate
19
+
20
+ content = content_tag :div, html, attributes
21
+ if javascript
22
+ content += content_tag :script, javascript, :type => 'text/javascript'
23
+ end
24
+
25
+ content
26
+ end
27
+ end
@@ -0,0 +1,2 @@
1
+ :plain
2
+ $('##{@id}').replaceWith('');
@@ -0,0 +1,2 @@
1
+ :plain
2
+ $('##{@id}').remove();
@@ -0,0 +1,3 @@
1
+ - content = escape_javascript widget(@name, @options)
2
+ :plain
3
+ $('##{@id}').replaceWith('#{content}');
@@ -0,0 +1 @@
1
+ = widget @name, @options
@@ -1,4 +1,9 @@
1
1
  Rails.application.routes.draw do
2
- # Widget names are path names and can have slashes in them.
3
- resources :widgets, only: [:show], constraints: {id: /.+/}
2
+ resources :widgets, only: [] do
3
+ member do
4
+ get :remove
5
+ get :replace
6
+ get :show, constraints: {id: /.+/} # Widget names are path names and can have slashes in them.
7
+ end
8
+ end
4
9
  end
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ # Widget names are path names and can have slashes in them.
3
+ get 'widgets/:name', to: 'widgets#show', as: 'widget', constraints: {name: /.+/}
4
+ delete 'widgets/:id', to: 'widgets#destroy', as: 'delete_widget'
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Widgets
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: widgets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-20 00:00:00.000000000 Z
12
+ date: 2013-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: guid
@@ -114,7 +114,7 @@ dependencies:
114
114
  requirements:
115
115
  - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: 0.0.6
117
+ version: 0.0.9
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,7 +122,7 @@ dependencies:
122
122
  requirements:
123
123
  - - ~>
124
124
  - !ruby/object:Gem::Version
125
- version: 0.0.6
125
+ version: 0.0.9
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: sqlite3
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -164,12 +164,16 @@ extra_rdoc_files: []
164
164
  files:
165
165
  - app/controllers/widgets_controller.rb
166
166
  - app/helpers/application_helper.rb
167
+ - app/helpers/application_helper.rb~
168
+ - app/views/widgets/destroy.js.haml~
169
+ - app/views/widgets/remove.js.haml
170
+ - app/views/widgets/replace.js.haml
171
+ - app/views/widgets/show.html.haml
167
172
  - config/routes.rb
173
+ - config/routes.rb~
168
174
  - lib/tasks/widgets_tasks.rake
169
175
  - lib/widgets/version.rb
170
- - lib/widgets/version.rb~
171
176
  - lib/widgets.rb
172
- - lib/widgets.rb~
173
177
  - MIT-LICENSE
174
178
  - Rakefile
175
179
  - README.rdoc
@@ -1,10 +0,0 @@
1
- module Widgets
2
- class Engine < Rails::Engine
3
- engine_name :widgets
4
-
5
- config.after_initialize do
6
- require File.expand_path '../../app/controllers/widgets_controller', __FILE__
7
- require File.expand_path '../../app/helpers/application_helper', __FILE__
8
- end
9
- end
10
- end
@@ -1,3 +0,0 @@
1
- module Widgets
2
- VERSION = '0.2.1'
3
- end