pagelet_rails 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +17 -0
  3. data/.travis.yml +14 -0
  4. data/Appraisals +14 -0
  5. data/CHANGELOG.md +35 -0
  6. data/Gemfile +7 -0
  7. data/LICENSE +21 -0
  8. data/README.md +48 -40
  9. data/app/assets/javascripts/pagelet_rails.js +4 -8
  10. data/app/controllers/pagelet_controller.rb +0 -1
  11. data/app/helpers/pagelets_helper.rb +9 -2
  12. data/bin/rails +13 -0
  13. data/gemfiles/rails_4.2.8.gemfile +12 -0
  14. data/gemfiles/rails_5.0.2.gemfile +12 -0
  15. data/gemfiles/rails_5.1.0.gemfile +12 -0
  16. data/lib/pagelet_rails/concerns/cache.rb +13 -11
  17. data/lib/pagelet_rails/concerns/controller.rb +1 -1
  18. data/lib/pagelet_rails/encryptor.rb +1 -1
  19. data/lib/pagelet_rails/version.rb +1 -1
  20. data/pagelet_rails.gemspec +31 -0
  21. data/test/benchmarks/ssi_benchmark.rb +47 -0
  22. data/test/dummy/Rakefile +6 -0
  23. data/test/dummy/app/assets/config/manifest.js +4 -0
  24. data/test/dummy/app/assets/images/.keep +0 -0
  25. data/test/dummy/app/assets/javascripts/application.js +13 -0
  26. data/test/dummy/app/assets/javascripts/cable.js +13 -0
  27. data/test/dummy/app/assets/javascripts/channels/.keep +0 -0
  28. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  29. data/test/dummy/app/channels/application_cable/channel.rb +4 -0
  30. data/test/dummy/app/channels/application_cable/connection.rb +4 -0
  31. data/test/dummy/app/controllers/application_controller.rb +3 -0
  32. data/test/dummy/app/controllers/concerns/.keep +0 -0
  33. data/test/dummy/app/controllers/dyno_controller.rb +13 -0
  34. data/test/dummy/app/controllers/pagelet_controller.rb +3 -0
  35. data/test/dummy/app/helpers/application_helper.rb +2 -0
  36. data/test/dummy/app/jobs/application_job.rb +2 -0
  37. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  38. data/test/dummy/app/models/application_record.rb +3 -0
  39. data/test/dummy/app/models/concerns/.keep +0 -0
  40. data/test/dummy/app/pagelets/params_example/params_example_controller.rb +7 -0
  41. data/test/dummy/app/pagelets/params_example/views/show.html.erb +3 -0
  42. data/test/dummy/app/pagelets/render_inline/render_inline_controller.rb +8 -0
  43. data/test/dummy/app/pagelets/static_text/static_text_controller.rb +12 -0
  44. data/test/dummy/app/pagelets/static_text/views/show.html.erb +1 -0
  45. data/test/dummy/app/views/dyno/benchmark.html.erb +4 -0
  46. data/test/dummy/app/views/dyno/params_example.html.erb +1 -0
  47. data/test/dummy/app/views/dyno/ssi.html.erb +2 -0
  48. data/test/dummy/app/views/dyno/static_text.html.erb +1 -0
  49. data/test/dummy/app/views/dyno/static_text_ajax.html.erb +1 -0
  50. data/test/dummy/app/views/dyno/test.html.erb +3 -0
  51. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  52. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  53. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  54. data/test/dummy/bin/bundle +3 -0
  55. data/test/dummy/bin/rails +4 -0
  56. data/test/dummy/bin/rake +4 -0
  57. data/test/dummy/bin/setup +34 -0
  58. data/test/dummy/bin/update +29 -0
  59. data/test/dummy/config.ru +5 -0
  60. data/test/dummy/config/application.rb +15 -0
  61. data/test/dummy/config/boot.rb +5 -0
  62. data/test/dummy/config/cable.yml +9 -0
  63. data/test/dummy/config/database.yml +25 -0
  64. data/test/dummy/config/environment.rb +5 -0
  65. data/test/dummy/config/environments/development.rb +54 -0
  66. data/test/dummy/config/environments/production.rb +86 -0
  67. data/test/dummy/config/environments/test.rb +49 -0
  68. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  69. data/test/dummy/config/initializers/assets.rb +11 -0
  70. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  71. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  72. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  73. data/test/dummy/config/initializers/inflections.rb +16 -0
  74. data/test/dummy/config/initializers/mime_types.rb +4 -0
  75. data/test/dummy/config/initializers/new_framework_defaults.rb +29 -0
  76. data/test/dummy/config/initializers/session_store.rb +3 -0
  77. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  78. data/test/dummy/config/locales/en.yml +23 -0
  79. data/test/dummy/config/puma.rb +47 -0
  80. data/test/dummy/config/routes.rb +7 -0
  81. data/test/dummy/config/secrets.yml +22 -0
  82. data/test/dummy/config/spring.rb +6 -0
  83. data/test/dummy/db/schema.rb +15 -0
  84. data/test/dummy/lib/assets/.keep +0 -0
  85. data/test/dummy/log/.keep +0 -0
  86. data/test/dummy/public/404.html +67 -0
  87. data/test/dummy/public/422.html +67 -0
  88. data/test/dummy/public/500.html +66 -0
  89. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  90. data/test/dummy/public/apple-touch-icon.png +0 -0
  91. data/test/dummy/public/favicon.ico +0 -0
  92. data/test/integration/dyno_test.rb +20 -0
  93. data/test/integration/navigation_test.rb +8 -0
  94. data/test/lib/options_test.rb +62 -0
  95. data/test/pagelet_rails_test.rb +7 -0
  96. data/test/test_helper.rb +30 -0
  97. metadata +252 -5
  98. data/MIT-LICENSE +0 -20
data/bin/rails ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
6
+ ENGINE_PATH = File.expand_path('../../lib/pagelet_rails/engine', __FILE__)
7
+
8
+ # Set up gems listed in the Gemfile.
9
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
10
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
11
+
12
+ require 'rails/all'
13
+ require 'rails/engine/commands'
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "4.2.8"
6
+ gem "minitest", "~> 5.10", "!= 5.10.2"
7
+
8
+ group :test do
9
+ gem "codeclimate-test-reporter", require: nil
10
+ end
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "5.0.2"
6
+ gem "minitest", "~> 5.10", "!= 5.10.2"
7
+
8
+ group :test do
9
+ gem "codeclimate-test-reporter", require: nil
10
+ end
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "5.1.0"
6
+ gem "minitest", "~> 5.10", "!= 5.10.2"
7
+
8
+ group :test do
9
+ gem "codeclimate-test-reporter", require: nil
10
+ end
11
+
12
+ gemspec path: "../"
@@ -26,17 +26,19 @@ module PageletRails::Concerns::Cache
26
26
 
27
27
  cache_path = pagelet_options.cache_path || cache_defaults[:cache_path]
28
28
 
29
- cache_path = if cache_path.is_a?(Proc)
30
- self.instance_exec(self, &cache_path)
31
- elsif cache_path.respond_to?(:call)
32
- cache_path.call(self)
33
- elsif cache_path.is_a?(String)
34
- {
35
- custom: cache_path
36
- }
37
- else
38
- cache_path
39
- end
29
+ cache_path =
30
+ if cache_path.is_a?(Proc)
31
+ self.instance_exec(self, &cache_path)
32
+ elsif cache_path.respond_to?(:call)
33
+ cache_path.call(self)
34
+ elsif cache_path.is_a?(String)
35
+ {
36
+ custom: cache_path
37
+ }
38
+ else
39
+ cache_path
40
+ end
41
+
40
42
  cache_path ||= {}
41
43
  cache_path[:controller] = params[:controller]
42
44
  cache_path[:action] = params[:action]
@@ -39,7 +39,7 @@ module PageletRails::Concerns::Controller
39
39
  # lookup_context.prefixes.clear
40
40
  view = "#{controller_name}/views"
41
41
  if lookup_context.prefixes.exclude?(view)
42
- lookup_context.prefixes.unshift "#{controller_name}/views"
42
+ lookup_context.prefixes.unshift view
43
43
  end
44
44
 
45
45
  # https://github.com/rails/actionpack-action_caching/issues/32
@@ -41,7 +41,7 @@ class PageletRails::Encryptor
41
41
  def encryptor
42
42
  @encryptor ||= begin
43
43
  key = self.class.get_key secret, salt
44
-
44
+ key = key[0..31]
45
45
  ActiveSupport::MessageEncryptor.new(key)
46
46
  end
47
47
  end
@@ -1,3 +1,3 @@
1
1
  module PageletRails
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'pagelet_rails/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'pagelet_rails'
7
+ s.version = PageletRails::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Anton Katunin']
10
+ s.email = ['antulik@gmail.com']
11
+ s.homepage = 'https://github.com/antulik/pagelet_rails'
12
+ s.summary = 'Improve perceived performance of your rails application with minimum effort'
13
+ s.description = 'Improve perceived performance of your rails application with minimum effort'
14
+ s.license = 'MIT'
15
+
16
+ s.add_dependency 'rails', '>= 4.0.0'
17
+ s.add_dependency 'ejs'
18
+
19
+ s.add_development_dependency 'sqlite3'
20
+ s.add_development_dependency 'rake'
21
+ s.add_development_dependency 'simplecov'
22
+ s.add_development_dependency 'appraisal'
23
+ s.add_development_dependency 'pry-rails'
24
+ s.add_development_dependency 'binding_of_caller'
25
+ s.add_development_dependency 'better_errors'
26
+
27
+ s.files = `git ls-files`.split("\n")
28
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
29
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
30
+ s.require_paths = ['lib']
31
+ end
@@ -0,0 +1,47 @@
1
+
2
+ require 'active_support/all'
3
+ require 'csv'
4
+ require 'pp'
5
+
6
+ root_url = 'http://local.dev/dyno/benchmark.html'
7
+
8
+ delays = [0, 10, 20, 30, 50, 100, 200]
9
+ sizes = (1..10).to_a
10
+ modes = ['inline']
11
+
12
+ rows = []
13
+ sizes.map do |size|
14
+
15
+ delays.each do |delay|
16
+ r = []
17
+ r << size
18
+ r << delay
19
+
20
+ modes.each do |mode|
21
+ params = {
22
+ remote: mode,
23
+ sleep: delay,
24
+ size: size
25
+ }
26
+ url = "#{root_url}?#{params.to_query}"
27
+
28
+ args = %W(ab -n 50 -e output.csv -l #{url})
29
+ # puts args
30
+ system(*args)
31
+
32
+ sleep 1
33
+ arr_of_arrs = CSV.read("./output.csv")
34
+ last_row = arr_of_arrs.last(10).first
35
+ time = last_row.last
36
+
37
+ # File.delete('./output.csv')
38
+ # puts time
39
+ r << time
40
+ end
41
+
42
+ rows << r.join("\t")
43
+ end
44
+
45
+ end
46
+
47
+ puts rows
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,4 @@
1
+
2
+ //= link_tree ../images
3
+ //= link_directory ../javascripts .js
4
+ //= link_directory ../stylesheets .css
File without changes
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ // require_tree .
@@ -0,0 +1,13 @@
1
+ // Action Cable provides the framework to deal with WebSockets in Rails.
2
+ // You can generate new channels where WebSocket features live using the rails generate channel command.
3
+ //
4
+ //= require action_cable
5
+ //= require_self
6
+ //= require_tree ./channels
7
+
8
+ (function() {
9
+ this.App || (this.App = {});
10
+
11
+ App.cable = ActionCable.createConsumer();
12
+
13
+ }).call(this);
File without changes
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Channel < ActionCable::Channel::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Connection < ActionCable::Connection::Base
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery with: :exception
3
+ end
File without changes
@@ -0,0 +1,13 @@
1
+ class DynoController < ApplicationController
2
+
3
+ def show
4
+ render pagelet_params[:id]
5
+ end
6
+
7
+ private
8
+
9
+ def pagelet_params
10
+ params.permit(:id)
11
+ end
12
+
13
+ end
@@ -0,0 +1,3 @@
1
+ class PageletController < ApplicationController
2
+ include PageletRails::Concerns::Controller
3
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
File without changes
@@ -0,0 +1,7 @@
1
+ class ParamsExample::ParamsExampleController < ::PageletController
2
+
3
+ pagelet_resource only: [:show]
4
+
5
+ def show
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ <div>
2
+ color:<%= params[:color] %>
3
+ </div>
@@ -0,0 +1,8 @@
1
+ class RenderInline::RenderInlineController < ::PageletController
2
+
3
+ pagelet_resource only: [:show]
4
+
5
+ def show
6
+ render body: 'Inline render text'
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ class StaticText::StaticTextController < ::PageletController
2
+
3
+ pagelet_resource only: [:show]
4
+
5
+ def show
6
+ delay = pagelet_options.sleep
7
+
8
+ if delay
9
+ sleep delay
10
+ end
11
+ end
12
+ end
@@ -0,0 +1 @@
1
+ <div>Static text</div>
@@ -0,0 +1,4 @@
1
+ <% delay = params[:sleep].to_i / 1000.0 %>
2
+ <% params[:size].to_i.times do %>
3
+ <%= pagelet :pagelets_static_text, remote: params[:remote].to_sym, sleep: delay %>
4
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= pagelet :pagelets_params_example, params: {color: 'red'} %>
@@ -0,0 +1,2 @@
1
+ <%= pagelet :pagelets_static_text, remote: :ssi, sleep: 1 %>
2
+ <%= pagelet :pagelets_static_text, remote: :ssi, sleep: 1 %>
@@ -0,0 +1 @@
1
+ <%= pagelet :pagelets_static_text %>
@@ -0,0 +1 @@
1
+ <%= pagelet :pagelets_static_text, remote: true %>
@@ -0,0 +1,3 @@
1
+ <% params[:size].to_i.times do %>
2
+ <%= pagelet :pagelets_static_text %>
3
+ <% end %>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= csrf_meta_tags %>
6
+
7
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
8
+ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
9
+ </head>
10
+
11
+ <body>
12
+ <%= yield %>
13
+ </body>
14
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run