edifice 1.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile.lock +120 -1
  3. data/README.md +73 -0
  4. data/Rakefile +6 -0
  5. data/_site/images/logo_edifice_80x93.png +0 -0
  6. data/_site/images/text_img_edifice_600x180.png +0 -0
  7. data/_site/images/text_img_railsway_547x54.png +0 -0
  8. data/_site/images/text_img_really_450x26.png +0 -0
  9. data/_site/index.html +141 -0
  10. data/_site/pygments.css +62 -0
  11. data/_site/style.css +477 -0
  12. data/_site/style.scss +239 -0
  13. data/_site/stylesheets/css/ie.css +57 -0
  14. data/_site/stylesheets/css/print.css +29 -0
  15. data/app/assets/javascripts/edifice/framework.js +0 -146
  16. data/edifice.gemspec +6 -0
  17. data/lib/edifice.rb +3 -2
  18. data/lib/edifice/controller.rb +0 -1
  19. data/lib/edifice/version.rb +1 -1
  20. data/{test/rails3/lib/tasks/.gitkeep → log/test.log} +0 -0
  21. data/spec/edifice_controller_spec.rb +28 -0
  22. data/spec/javascript_event_spec.rb +25 -0
  23. data/spec/pjax_support_spec.rb +35 -0
  24. data/{test/rails3 → spec/rails3.1}/.gitignore +1 -0
  25. data/{test/rails3/public → spec/rails3.1/app/assets}/images/rails.png +0 -0
  26. data/spec/rails3.1/app/assets/javascripts/application.js +10 -0
  27. data/spec/rails3.1/app/assets/javascripts/test/base.js +11 -0
  28. data/spec/rails3.1/app/assets/javascripts/vendor/jquery-pjax.js +264 -0
  29. data/spec/rails3.1/app/assets/stylesheets/application.css +7 -0
  30. data/{test/rails3 → spec/rails3.1}/app/controllers/application_controller.rb +0 -0
  31. data/spec/rails3.1/app/controllers/test_controller.rb +2 -0
  32. data/spec/rails3.1/app/views/layouts/application.html.erb +15 -0
  33. data/{test/rails3/public/favicon.ico → spec/rails3.1/app/views/test/base.html.erb} +0 -0
  34. data/{test/rails3/public/javascripts/.gitkeep → spec/rails3.1/app/views/test/empty.html.erb} +0 -0
  35. data/{test/rails3 → spec/rails3.1}/config/application.rb +22 -16
  36. data/{test/rails3 → spec/rails3.1}/config/boot.rb +0 -0
  37. data/{test/rails3 → spec/rails3.1}/config/environment.rb +1 -1
  38. data/{test/rails3 → spec/rails3.1}/config/environments/test.rb +6 -2
  39. data/{test/rails3 → spec/rails3.1}/config/initializers/backtrace_silencers.rb +0 -0
  40. data/{test/rails3 → spec/rails3.1}/config/initializers/inflections.rb +0 -0
  41. data/{test/rails3 → spec/rails3.1}/config/initializers/mime_types.rb +0 -0
  42. data/{test/rails3 → spec/rails3.1}/config/initializers/secret_token.rb +1 -1
  43. data/{test/rails3 → spec/rails3.1}/config/initializers/session_store.rb +2 -2
  44. data/spec/rails3.1/config/initializers/wrap_parameters.rb +14 -0
  45. data/spec/rails3.1/config/routes.rb +4 -0
  46. data/{test/rails3/public/stylesheets → spec/rails3.1/log}/.gitkeep +0 -0
  47. data/spec/spec_helper.rb +7 -0
  48. metadata +141 -90
  49. data/README +0 -46
  50. data/test/rails3/Gemfile +0 -33
  51. data/test/rails3/Gemfile.lock +0 -75
  52. data/test/rails3/README +0 -256
  53. data/test/rails3/Rakefile +0 -7
  54. data/test/rails3/app/controllers/posts_controller.rb +0 -15
  55. data/test/rails3/app/helpers/application_helper.rb +0 -2
  56. data/test/rails3/app/models/post.rb +0 -10
  57. data/test/rails3/app/views/layouts/application.html.erb +0 -14
  58. data/test/rails3/app/views/posts/new.html.erb +0 -17
  59. data/test/rails3/config.ru +0 -4
  60. data/test/rails3/config/database.yml +0 -22
  61. data/test/rails3/config/environments/development.rb +0 -26
  62. data/test/rails3/config/environments/production.rb +0 -49
  63. data/test/rails3/config/locales/en.yml +0 -5
  64. data/test/rails3/config/routes.rb +0 -4
  65. data/test/rails3/db/seeds.rb +0 -7
  66. data/test/rails3/doc/README_FOR_APP +0 -2
  67. data/test/rails3/public/404.html +0 -26
  68. data/test/rails3/public/422.html +0 -26
  69. data/test/rails3/public/500.html +0 -26
  70. data/test/rails3/public/javascripts/application.js +0 -0
  71. data/test/rails3/public/javascripts/jquery-1.5.1.js +0 -8316
  72. data/test/rails3/public/robots.txt +0 -5
  73. data/test/rails3/public/stylesheets/form.css +0 -18
  74. data/test/rails3/script/rails +0 -6
  75. data/test/rails3/vendor/plugins/.gitkeep +0 -0
data/edifice.gemspec CHANGED
@@ -18,4 +18,10 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency 'rake'
23
+ s.add_development_dependency 'rails'
24
+ s.add_development_dependency 'rspec-rails'
25
+ s.add_development_dependency 'capybara'
26
+ s.add_development_dependency 'jquery-rails'
21
27
  end
data/lib/edifice.rb CHANGED
@@ -1,7 +1,8 @@
1
- require 'edifice/helper'
2
1
  require 'edifice/controller'
2
+ require 'edifice/helper'
3
3
  require 'edifice/renderer'
4
4
 
5
+
5
6
  module Edifice
6
7
  require 'edifice/engine' if defined?(Rails)
7
8
  end
@@ -9,4 +10,4 @@ end
9
10
  ActionController::Base.send :include, Edifice::Controller
10
11
  ActionMailer::Base.send :include, Edifice::Controller
11
12
  ActionView::Base.send :include, Edifice::Helper
12
- ActionView::Renderer.send :include, Edifice::Renderer
13
+ ActionView::Renderer.send :include, Edifice::Renderer
@@ -1,5 +1,4 @@
1
1
  module Edifice
2
-
3
2
  module Controller
4
3
  def self.included(controller)
5
4
  controller.helper_method(:view_path, :view_path_normalized,
@@ -1,3 +1,3 @@
1
1
  module Edifice
2
- VERSION = "1.0"
2
+ VERSION = "1.1.0"
3
3
  end
File without changes
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe TestController do
4
+ include RSpec::Rails::ControllerExampleGroup
5
+ render_views
6
+
7
+ it 'should set correct body classes' do
8
+ get :base
9
+ assert_select 'body.c_test.v_base.l_application'
10
+ end
11
+
12
+ it 'should set correct meta tags' do
13
+ get :base
14
+
15
+ assert_select 'meta[name=edifice-view_path][content=test]'
16
+ assert_select 'meta[name=edifice-view_name][content=base]'
17
+ assert_select 'meta[name=edifice-layout][content=application]'
18
+ end
19
+
20
+ it 'should set correct response headers' do
21
+ get :base
22
+
23
+ response.headers.keys.should include('x-edifice-view_path', 'x-edifice-view_name', 'x-edifice-layout')
24
+ response.headers['x-edifice-view_path'].should ==('test')
25
+ response.headers['x-edifice-view_name'].should ==('base')
26
+ response.headers['x-edifice-layout'].should ==('application')
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe 'javascript events', :type => :request, :js => true do
4
+ it "should fire the onReady event" do
5
+ visit('/test/base')
6
+
7
+ # this gets added onReady
8
+ page.should have_selector('h1.ready')
9
+ end
10
+
11
+ it "should fire the onLoad event" do
12
+ visit('/test/base')
13
+
14
+ # this gets added onReady
15
+ page.should have_selector('h1.load')
16
+ end
17
+
18
+ it "should fire the onReady event via AJAX" do
19
+ visit('/test/empty')
20
+ page.should have_no_selector('h1.ready')
21
+
22
+ page.evaluate_script('jQuery.get("/test/base")')
23
+ page.should have_selector('h1.ready')
24
+ end
25
+ end
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe 'pjax support', :type => :request, :js => true do
4
+ it "should alter the metatags when using pjax" do
5
+ visit('/test/empty')
6
+ page.should have_selector('meta[name=edifice-view_name][content=empty]')
7
+
8
+ page.evaluate_script('jQuery.pjax({url: "/test/base", container: "body"})')
9
+ page.should have_selector('meta[name=edifice-view_name][content=base]')
10
+ end
11
+
12
+ it "should not alter the metatags otherwise" do
13
+ visit('/test/empty')
14
+ page.should have_selector('meta[name=edifice-view_name][content=empty]')
15
+
16
+ page.evaluate_script('jQuery.ajax("/test/base")')
17
+ page.should have_selector('meta[name=edifice-view_name][content=empty]')
18
+ end
19
+
20
+ it "should alter the body classes when using pjax" do
21
+ visit('/test/empty')
22
+ page.should have_selector('body.v_empty')
23
+
24
+ page.evaluate_script('jQuery.pjax({url: "/test/base", container: "body"})')
25
+ page.should have_selector('body.v_base')
26
+ end
27
+
28
+ it "should not alter the body classes otherwise" do
29
+ visit('/test/empty')
30
+ page.should have_selector('body.v_empty')
31
+
32
+ page.evaluate_script('jQuery.ajax("/test/base")')
33
+ page.should have_selector('body.v_empty')
34
+ end
35
+ end
@@ -2,3 +2,4 @@
2
2
  db/*.sqlite3
3
3
  log/*.log
4
4
  tmp/
5
+ .sass-cache/
@@ -0,0 +1,10 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require jquery
8
+ //= require jquery_ujs
9
+ //= require edifice
10
+ //= require_tree .
@@ -0,0 +1,11 @@
1
+ (function($) {
2
+ window.testBase = {
3
+ onReady: function() {
4
+ $('body').append('<h1 class="ready">');
5
+ },
6
+
7
+ onLoad: function() {
8
+ $('body').append('<h1 class="load">');
9
+ }
10
+ }
11
+ }(jQuery));
@@ -0,0 +1,264 @@
1
+ // jquery.pjax.js
2
+ // copyright chris wanstrath
3
+ // https://github.com/defunkt/jquery-pjax
4
+
5
+ (function($){
6
+
7
+ // When called on a link, fetches the href with ajax into the
8
+ // container specified as the first parameter or with the data-pjax
9
+ // attribute on the link itself.
10
+ //
11
+ // Tries to make sure the back button and ctrl+click work the way
12
+ // you'd expect.
13
+ //
14
+ // Accepts a jQuery ajax options object that may include these
15
+ // pjax specific options:
16
+ //
17
+ // container - Where to stick the response body. Usually a String selector.
18
+ // $(container).html(xhr.responseBody)
19
+ // push - Whether to pushState the URL. Defaults to true (of course).
20
+ // replace - Want to use replaceState instead? That's cool.
21
+ //
22
+ // For convenience the first parameter can be either the container or
23
+ // the options object.
24
+ //
25
+ // Returns the jQuery object
26
+ $.fn.pjax = function( container, options ) {
27
+ if ( options )
28
+ options.container = container
29
+ else
30
+ options = $.isPlainObject(container) ? container : {container:container}
31
+
32
+ // We can't persist $objects using the history API so we must use
33
+ // a String selector. Bail if we got anything else.
34
+ if ( options.container && typeof options.container !== 'string' ) {
35
+ throw "pjax container must be a string selector!"
36
+ return false
37
+ }
38
+
39
+ return this.live('click', function(event){
40
+ // Middle click, cmd click, and ctrl click should open
41
+ // links in a new tab as normal.
42
+ if ( event.which > 1 || event.metaKey )
43
+ return true
44
+
45
+ var defaults = {
46
+ url: this.href,
47
+ container: $(this).attr('data-pjax'),
48
+ clickedElement: $(this),
49
+ fragment: null
50
+ }
51
+
52
+ $.pjax($.extend({}, defaults, options))
53
+
54
+ event.preventDefault()
55
+ })
56
+ }
57
+
58
+
59
+ // Loads a URL with ajax, puts the response body inside a container,
60
+ // then pushState()'s the loaded URL.
61
+ //
62
+ // Works just like $.ajax in that it accepts a jQuery ajax
63
+ // settings object (with keys like url, type, data, etc).
64
+ //
65
+ // Accepts these extra keys:
66
+ //
67
+ // container - Where to stick the response body. Must be a String.
68
+ // $(container).html(xhr.responseBody)
69
+ // push - Whether to pushState the URL. Defaults to true (of course).
70
+ // replace - Want to use replaceState instead? That's cool.
71
+ //
72
+ // Use it just like $.ajax:
73
+ //
74
+ // var xhr = $.pjax({ url: this.href, container: '#main' })
75
+ // console.log( xhr.readyState )
76
+ //
77
+ // Returns whatever $.ajax returns.
78
+ var pjax = $.pjax = function( options ) {
79
+ var $container = $(options.container),
80
+ success = options.success || $.noop
81
+
82
+ // We don't want to let anyone override our success handler.
83
+ delete options.success
84
+
85
+ // We can't persist $objects using the history API so we must use
86
+ // a String selector. Bail if we got anything else.
87
+ if ( typeof options.container !== 'string' )
88
+ throw "pjax container must be a string selector!"
89
+
90
+ options = $.extend(true, {}, pjax.defaults, options)
91
+
92
+ if ( $.isFunction(options.url) ) {
93
+ options.url = options.url()
94
+ }
95
+
96
+ options.context = $container
97
+
98
+ options.success = function(data){
99
+ if ( options.fragment ) {
100
+ // If they specified a fragment, look for it in the response
101
+ // and pull it out.
102
+ var $fragment = $(data).find(options.fragment)
103
+ if ( $fragment.length )
104
+ data = $fragment.children()
105
+ else
106
+ return window.location = options.url
107
+ } else {
108
+ // If we got no data or an entire web page, go directly
109
+ // to the page and let normal error handling happen.
110
+ if ( !$.trim(data) || /<html/i.test(data) )
111
+ return window.location = options.url
112
+ }
113
+
114
+ // Make it happen.
115
+ this.html(data)
116
+
117
+ // If there's a <title> tag in the response, use it as
118
+ // the page's title.
119
+ var oldTitle = document.title,
120
+ title = $.trim( this.find('title').remove().text() )
121
+ if ( title ) document.title = title
122
+
123
+ // No <title>? Fragment? Look for data-title and title attributes.
124
+ if ( !title && options.fragment ) {
125
+ title = $fragment.attr('title') || $fragment.data('title')
126
+ }
127
+
128
+ var state = {
129
+ pjax: options.container,
130
+ fragment: options.fragment,
131
+ timeout: options.timeout
132
+ }
133
+
134
+ // If there are extra params, save the complete URL in the state object
135
+ var query = $.param(options.data)
136
+ if ( query != "_pjax=true" )
137
+ state.url = options.url + (/\?/.test(options.url) ? "&" : "?") + query
138
+
139
+ if ( options.replace ) {
140
+ window.history.replaceState(state, document.title, options.url)
141
+ } else if ( options.push ) {
142
+ // this extra replaceState before first push ensures good back
143
+ // button behavior
144
+ if ( !pjax.active ) {
145
+ window.history.replaceState($.extend({}, state, {url:null}), oldTitle)
146
+ pjax.active = true
147
+ }
148
+
149
+ window.history.pushState(state, document.title, options.url)
150
+ }
151
+
152
+ // Google Analytics support
153
+ if ( (options.replace || options.push) && window._gaq )
154
+ _gaq.push(['_trackPageview'])
155
+
156
+ // If the URL has a hash in it, make sure the browser
157
+ // knows to navigate to the hash.
158
+ var hash = window.location.hash.toString()
159
+ if ( hash !== '' ) {
160
+ window.location.href = hash
161
+ }
162
+
163
+ // Invoke their success handler if they gave us one.
164
+ success.apply(this, arguments)
165
+ }
166
+
167
+ // Cancel the current request if we're already pjaxing
168
+ var xhr = pjax.xhr
169
+ if ( xhr && xhr.readyState < 4) {
170
+ xhr.onreadystatechange = $.noop
171
+ xhr.abort()
172
+ }
173
+
174
+ pjax.options = options
175
+ pjax.xhr = $.ajax(options)
176
+ $(document).trigger('pjax', [pjax.xhr, options])
177
+
178
+ return pjax.xhr
179
+ }
180
+
181
+
182
+ pjax.defaults = {
183
+ timeout: 650,
184
+ push: true,
185
+ replace: false,
186
+ // We want the browser to maintain two separate internal caches: one for
187
+ // pjax'd partial page loads and one for normal page loads. Without
188
+ // adding this secret parameter, some browsers will often confuse the two.
189
+ data: { _pjax: true },
190
+ type: 'GET',
191
+ dataType: 'html',
192
+ beforeSend: function(xhr){
193
+ this.trigger('pjax:start', [xhr, pjax.options])
194
+ // start.pjax is deprecated
195
+ this.trigger('start.pjax', [xhr, pjax.options])
196
+ xhr.setRequestHeader('X-PJAX', 'true')
197
+ },
198
+ error: function(xhr, textStatus, errorThrown){
199
+ if ( textStatus !== 'abort' )
200
+ window.location = pjax.options.url
201
+ },
202
+ complete: function(xhr){
203
+ this.trigger('pjax:end', [xhr, pjax.options])
204
+ // end.pjax is deprecated
205
+ this.trigger('end.pjax', [xhr, pjax.options])
206
+ }
207
+ }
208
+
209
+
210
+ // Used to detect initial (useless) popstate.
211
+ // If history.state exists, assume browser isn't going to fire initial popstate.
212
+ var popped = ('state' in window.history), initialURL = location.href
213
+
214
+
215
+ // popstate handler takes care of the back and forward buttons
216
+ //
217
+ // You probably shouldn't use pjax on pages with other pushState
218
+ // stuff yet.
219
+ $(window).bind('popstate', function(event){
220
+ // Ignore inital popstate that some browsers fire on page load
221
+ var initialPop = !popped && location.href == initialURL
222
+ popped = true
223
+ if ( initialPop ) return
224
+
225
+ var state = event.state
226
+
227
+ if ( state && state.pjax ) {
228
+ var container = state.pjax
229
+ if ( $(container+'').length )
230
+ $.pjax({
231
+ url: state.url || location.href,
232
+ fragment: state.fragment,
233
+ container: container,
234
+ push: false,
235
+ timeout: state.timeout
236
+ })
237
+ else
238
+ window.location = location.href
239
+ }
240
+ })
241
+
242
+
243
+ // Add the state property to jQuery's event object so we can use it in
244
+ // $(window).bind('popstate')
245
+ if ( $.inArray('state', $.event.props) < 0 )
246
+ $.event.props.push('state')
247
+
248
+
249
+ // Is pjax supported by this browser?
250
+ $.support.pjax =
251
+ window.history && window.history.pushState && window.history.replaceState
252
+ // pushState isn't reliable on iOS yet.
253
+ && !navigator.userAgent.match(/(iPod|iPhone|iPad|WebApps\/.+CFNetwork)/)
254
+
255
+
256
+ // Fall back to normalcy for older browsers.
257
+ if ( !$.support.pjax ) {
258
+ $.pjax = function( options ) {
259
+ window.location = $.isFunction(options.url) ? options.url() : options.url
260
+ }
261
+ $.fn.pjax = function() { return this }
262
+ }
263
+
264
+ })(jQuery);
@@ -0,0 +1,7 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require_tree .
7
+ */