window_rails 0.2.10 → 0.2.11

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.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,7 @@
1
+ == v0.2.11
2
+ * Provides windowing methods to ActionView::Base for JS templates
3
+ * Removes deprecated rake tasks
4
+
1
5
  == v0.2.10
2
6
  * Fixes close window bug
3
7
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  Current WindowRails License:
2
2
 
3
- Copyright (c) 2011 Chris Roberts <chrisroberts.code@gmail.com>
3
+ Copyright (c) 2012 Chris Roberts <chrisroberts.code@gmail.com>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -4,7 +4,7 @@ WindowRails is a plugin for Rails that provides easy to use AJAXy windows. It is
4
4
  completely on {jQueryUI}[http://jquery-ui.com] with helpers for Rails to make it easy to
5
5
  use from a Rails app.
6
6
 
7
- WindowRails is now happily compatible with Rails 2 and Rails 3.
7
+ WindowRails is now happily compatible with Rails 2 and Rails 3 (and now 3.1).
8
8
 
9
9
  == Requirements
10
10
 
@@ -13,7 +13,9 @@ WindowRails is now happily compatible with Rails 2 and Rails 3.
13
13
 
14
14
  == Installation
15
15
 
16
- rake window_rails:install
16
+ Add window_rails to your application Gemfile:
17
+
18
+ gem 'window_rails'
17
19
 
18
20
  === Basic examples to get you started
19
21
 
@@ -42,20 +44,24 @@ WindowRails is now happily compatible with Rails 2 and Rails 3.
42
44
  end
43
45
  end
44
46
 
45
- ==== Linking to a window
46
- ===== Load an entire HTML page into an IFrame
47
- <%= link_to_window('Link', :iframe => {:controller => :my_controller, :action => :my_action}, :window => 'some_name') %>
48
-
49
- With this approach the contents of the HTML respond to block will be loaded into the window
47
+ # or via JS template:
48
+ # app/views/my_resources/action.js.erb
50
49
 
51
- ===== Load a partial page directly into the DOM within the window
52
- <%= link_to_window('Link', :url => {:controller => :my_controller, :action => :my_action}, :width => 400, :height => 300, :window => 'some_name') %>
53
-
54
- With this approach the content returned from the JS respond to block will be loaded into the window. No need for
55
- requesting the window to be created from the controller.
50
+ <%=
51
+ open_window(
52
+ {:partial => 'action_partial'},
53
+ :width => 400,
54
+ :height => 500,
55
+ :title => 'My Window',
56
+ :window => 'unique_window_name'
57
+ )
58
+ %>
56
59
 
57
60
  == Window Interactions
58
61
 
62
+ Examples are shown using the old generator style. For rails 3.1 and beyond, the methods should be defined
63
+ within the JS views
64
+
59
65
  ==== Opening a window via AJAX
60
66
  def open_my_window
61
67
  respond_to do |format|
data/lib/window_rails.rb CHANGED
@@ -3,7 +3,10 @@ require 'window_rails/version'
3
3
  if(defined?(Rails::Engine))
4
4
  require 'window_rails/engine'
5
5
  else
6
- %w(window_rails_generators window_rails_view).each do |part|
6
+ if(defined?(ActionView::Helpers::PrototypeHelper::JavaScriptGenerator::GeneratorMethods))
7
+ require 'window_rails/window_rails_generators'
8
+ end
9
+ %w(window_rails_windows window_rails_view).each do |part|
7
10
  require "window_rails/#{part}"
8
11
  end
9
12
  end
@@ -1,13 +1,12 @@
1
1
  module WindowRails
2
2
  class Engine < Rails::Engine
3
-
4
- rake_tasks do
5
- require 'window_rails/tasks'
6
- end
7
3
 
8
4
  # We do all our setup in here
9
5
  config.to_prepare do
10
- %w(window_rails_generators window_rails_view).each do |part|
6
+ if(defined?(ActionView::Helpers::PrototypeHelper::JavaScriptGenerator::GeneratorMethods))
7
+ require 'window_rails/window_rails_generators'
8
+ end
9
+ %w(window_rails_windows window_rails_view).each do |part|
11
10
  require "window_rails/#{part}"
12
11
  end
13
12
  end
@@ -13,5 +13,5 @@ module WindowRails
13
13
  end
14
14
  end
15
15
 
16
- VERSION = Version.new('0.2.10')
16
+ VERSION = Version.new('0.2.11')
17
17
  end
@@ -91,7 +91,7 @@ module WindowRailsGenerators
91
91
  end
92
92
 
93
93
  def window_setup
94
- @set ||= false
94
+ @_window_rails_setup ||= false
95
95
  unless(@set)
96
96
  self << '
97
97
  if(typeof(window.window_rails_windows) == "undefined") {
@@ -101,7 +101,7 @@ module WindowRailsGenerators
101
101
  }
102
102
  '
103
103
  end
104
- @set = true
104
+ @_window_rails_setup = true
105
105
  nil
106
106
  end
107
107
 
@@ -131,6 +131,7 @@ module WindowRailsGenerators
131
131
  # result will be placed in the window (basically an easy way to integrate partials:
132
132
  # page.update_window(:partial => 'my_parital'))
133
133
  def update_window(content, options={})
134
+ window_setup
134
135
  win = options.delete(:window)
135
136
  error = options.delete(:error)
136
137
  key = store_content(content)
@@ -228,6 +229,7 @@ module WindowRailsGenerators
228
229
  # so we aren't storing worthless junk:
229
230
  # window.window_rails_windows_array.splice(window.window_rails_windows_array.indexOf('#{win}'), 1);
230
231
  def create_window(key, win, options)
232
+ window_setup
231
233
  options[:auto_open] ||= false
232
234
  options[:close] = "function(event,ui){
233
235
  #{
@@ -313,6 +315,7 @@ module WindowRailsGenerators
313
315
  # be isolated from the current page, but this isolation means it cannot communicate with other windows on the page (including
314
316
  # its own).
315
317
  def open_window(content, options={})
318
+ window_setup
316
319
  key = nil
317
320
  if(options[:iframe])
318
321
  iframe = @context.url_for(options.delete(:iframe))
@@ -24,7 +24,7 @@ module WindowRailsView
24
24
  # options:: Options hash supplied to windowing system
25
25
  # Extra options include :method and :delay. :delay is the number
26
26
  # of seconds to wait after page load to open window
27
- def open_window(options={})
27
+ def open_window_deprecated(options={})
28
28
  frame_url = options.has_key?(:iframe) ? url_for(options.delete(:iframe)) : nil
29
29
  window_url = options.has_key?(:url) ? url_for(options.delete(:url)) : nil
30
30
  method = options.delete(:method) || 'get'
@@ -0,0 +1,45 @@
1
+ module WindowRails
2
+ class Holder
3
+ include WindowRailsGenerators
4
+
5
+ attr_accessor :context
6
+
7
+ def initialize(args={})
8
+ @context = args[:context]
9
+ @buffer = ''
10
+ end
11
+
12
+ def << (string)
13
+ @buffer << string.to_s
14
+ end
15
+
16
+ def window_flush
17
+ buf = @buffer.dup
18
+ @buffer = ''
19
+ buf
20
+ end
21
+ end
22
+ end
23
+
24
+ module WindowRails
25
+ module Windows
26
+ def self.included(base)
27
+ WindowRailsGenerators.instance_methods(false).each do |method|
28
+ base.class_eval do
29
+ def _window_rails_holder
30
+ @_window_rails_holder ||= WindowRails::Holder.new
31
+ end
32
+
33
+ define_method method do |*args|
34
+ _window_rails_holder.context = self
35
+ _window_rails_holder.send(method, *args)
36
+ _window_rails_holder.window_flush.html_safe
37
+ end
38
+ end
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+
45
+ ActionView::Base.send(:include, WindowRails::Windows)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: window_rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 10
10
- version: 0.2.10
9
+ - 11
10
+ version: 0.2.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Roberts
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-22 00:00:00 -08:00
18
+ date: 2012-02-10 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -66,7 +66,7 @@ files:
66
66
  - lib/window_rails.rb
67
67
  - lib/window_rails/engine.rb
68
68
  - lib/window_rails/window_rails_view.rb
69
- - lib/window_rails/tasks.rb
69
+ - lib/window_rails/window_rails_windows.rb
70
70
  - lib/window_rails/window_rails_generators.rb
71
71
  - lib/window_rails/version.rb
72
72
  - rails/init.rb
@@ -1,69 +0,0 @@
1
- require 'fileutils'
2
-
3
- namespace :window_rails do
4
-
5
- desc 'Install window_rails'
6
- task :install do
7
- FileUtils.mkdir_p(File.join(Rails.root, 'public', 'window_rails'))
8
- Rake::Task['window_rails:install_javascripts'].invoke
9
- Rake::Task['window_rails:install_stylesheets'].invoke
10
- Rake::Task['window_rails:install_assets'].invoke
11
- Rake::Task['window_rails:install_version'].invoke
12
- puts '*' * 50
13
- puts 'WindowRails installation is complete.'
14
- puts 'NOTE: Please refer to README file for any additional setup.'
15
- puts '*' * 50
16
- end
17
-
18
- task :upgrade do
19
- Rake::Task['window_rails:install_javascripts'].invoke
20
- Rake::Task['window_rails:install_stylesheets'].invoke
21
- Rake::Task['window_rails:install_assets'].invoke
22
- puts 'WindowRails files have been updated to most current version'
23
- end
24
-
25
- task :install_javascripts do
26
- install_items('javascripts')
27
- end
28
-
29
- task :install_stylesheets do
30
- install_items('stylesheets')
31
- end
32
-
33
- task :install_assets do
34
- install_items('images')
35
- end
36
-
37
- task :install_version do
38
- f = File.open(File.join(Rails.root, 'public', 'window_rails', 'version'), 'w')
39
- f.write WindowRails::VERSION
40
- f.close
41
- puts 'Version file written'
42
- end
43
-
44
- desc 'Output current version information'
45
- task :version do
46
- asset_version = nil
47
- if(File.exists?(File.join(Rails.root, 'public', 'window_rails', 'version')))
48
- asset_version = File.read(File.join(Rails.root, 'public', 'window_rails', 'version')).strip
49
- end
50
- puts "Current WindowRails version: #{WindowRails::VERSION}"
51
- puts "Current WindowRails assets version: #{asset_version}"
52
- if(WindowRails::VERSION != asset_version.to_s)
53
- puts "WARNING #{'*' * 50}"
54
- puts 'WindowRails assets within project are out of date'
55
- puts 'Please run: rake window_rails:upgrade'
56
- puts "WARNING #{'*' * 50}"
57
- end
58
- end
59
- end
60
-
61
- def install_items(item)
62
- FileUtils.mkdir_p(File.join(Rails.root, 'public', 'window_rails', item))
63
- FileUtils.cp_r(
64
- File.join(File.dirname(__FILE__), '..', '..', 'files', item, File::SEPARATOR, '.'),
65
- File.join(Rails.root, 'public', 'window_rails', item)
66
- )
67
- puts "#{item.titleize} files installed."
68
- end
69
-