flammarion_rails 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71625fc08d749a8dfe8dfc6f7b5ef770e5700f23
4
- data.tar.gz: d6208f1d93881a2ceb3622abede691f9a9380ef9
3
+ metadata.gz: c0980270558683db4a166526a1f22304ce585888
4
+ data.tar.gz: 1cf80fb2374d31c489ec00e370a35d947d8bf5ee
5
5
  SHA512:
6
- metadata.gz: d6cdb11f7de83f5b5770854eac952a2bc2a6670c3e474e2e25947910782d2be9a67465d08ab5236a7c22d309c1617113864eeab68b773f5282ce1bfdeba5a130
7
- data.tar.gz: 79321714b0fca0ebf85470889d5b77609affb4de5bb6636e4f5d1b72e91aa8b0614eee8d9b98520c3d0de8d625096833faa10696be61dfdb98b98bb6060259f3
6
+ metadata.gz: 3993f0c63e101013adb0fe1503a7f484f147e102b769bc60385ad6325d5a873527d2cd8e16916375f69c6451ec7b36a28db7c87a0ad2220626c3f52142f07cf6
7
+ data.tar.gz: c77d8b947c93e5007a573de543bcaeb793bc3db56ae302afc09451f776ffbe231039cded82aa2f389351b47899d0c9ff89f5f904a2509500a65c8888df25367e
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # FlammarionRails
2
2
 
3
- * TODO: custom rake task actions
3
+ * TODO: accept + mime + content_type + session + referer + pjax + csrf... or reuse middlewares?
4
+
5
+ * TODO: change before actions for an array of hashes
4
6
 
5
7
  * TODO: app packaging / installation procedure
6
8
 
@@ -5,13 +5,13 @@ module Flammarion
5
5
 
6
6
  attr_accessor :on_disconnect, :on_connect, :sockets, :request, :status, :headers, :response
7
7
 
8
+ PROTOCOL = /^.*:\/{2}(:\d{0,4})?/i
9
+
8
10
  # Creates a new Engraving (i.e., a new display window)
9
11
  # @option options [Proc] :on_connect Called when the display window is
10
12
  # connected (i.e., displayed)
11
13
  # @option options [Proc] :on_disconnect Called when the display windows is
12
14
  # disconnected (i.e., closed)
13
- # @option options [Boolean] :exit_on_disconnect (false) Will call +exit+
14
- # when the widow is closed if this option is true.
15
15
  # @raise {SetupError} if chrome is not set up correctly and
16
16
  # and Flammarion is unable to display the engraving.
17
17
  def initialize(**options)
@@ -19,7 +19,6 @@ module Flammarion
19
19
  @sockets = []
20
20
  @on_connect = options[:on_connect]
21
21
  @on_disconnect = options[:on_disconnect]
22
- @exit_on_disconnect = options.fetch(:exit_on_disconnect, false)
23
22
 
24
23
  start_server
25
24
  @window_id = @@server.register_window(self)
@@ -35,7 +34,7 @@ module Flammarion
35
34
 
36
35
  def disconnect(ws)
37
36
  @sockets.delete ws
38
- exit 0 if @exit_on_disconnect
37
+ exit 0
39
38
  @on_disconnect.call if @on_disconnect
40
39
  end
41
40
 
@@ -45,7 +44,7 @@ module Flammarion
45
44
  dispatch(params)
46
45
 
47
46
  if status == 302
48
- dispatch(url: headers['Location'].sub(/^.*:\/{2}(:\d{0,4})?/i, ''), session: response.request.session)
47
+ dispatch(url: headers['Location'].sub(PROTOCOL, ''), session: response.request.session)
49
48
  render(action: 'page', body: response.body)
50
49
  elsif headers['Content-Transfer-Encoding'] == 'binary'
51
50
  filename = headers['Content-Disposition'].sub(/.*filename=/, '').gsub(/(^"|"$)/, '')
@@ -67,11 +66,12 @@ module Flammarion
67
66
  url = params.delete(:url)
68
67
  uri = URI.parse(url)
69
68
  query_params = Rack::Utils.parse_nested_query(uri.query)
69
+ request_params = {}
70
70
 
71
71
  if params.key?(:form)
72
72
  params[:method] = 'post'
73
- params[params.delete(:button)] = ''
74
- params.merge!(Rack::Utils.parse_nested_query(params.delete(:form)))
73
+ request_params = Rack::Utils.parse_nested_query(params.delete(:form))
74
+ request_params[params.delete(:button)] = ''
75
75
  end
76
76
  if params.key?(:_method)
77
77
  params[:method] = params[:_method]
@@ -88,9 +88,15 @@ module Flammarion
88
88
  action = path_params[:action] || 'index'
89
89
  request_env = {
90
90
  'rack.input' => '',
91
+ 'QUERY_STRING' => uri.query,
91
92
  'REQUEST_METHOD' => http_method,
92
- 'action_dispatch.request.parameters' => params.merge!(path_params),
93
+ 'REQUEST_PATH' => uri.path,
94
+ 'REQUEST_URI' => url,
95
+ 'PATH_INFO' => uri.path,
96
+ 'action_dispatch.request.query_parameters' => query_params,
97
+ 'action_dispatch.request.request_parameters' => request_params,
93
98
  'action_dispatch.request.path_parameters' => path_params,
99
+ 'action_dispatch.request.parameters' => params.merge!(request_params).merge!(path_params),
94
100
  }
95
101
  request_env['rack.session'] = session if session
96
102
  self.request = ActionDispatch::Request.new(request_env)
@@ -2,12 +2,8 @@ module Flammarion
2
2
  class SetupError < StandardError; end
3
3
 
4
4
  module Revelator
5
- CHROME_PATH = ENV["FLAMMARION_REVELATOR_PATH"] || 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
6
-
7
5
  def open_a_window(**options)
8
6
  index_path = FlammarionRails::Engine.root.join('public', 'index.html')
9
- index_path = `cygpath -w '#{index_path}'`.strip if RbConfig::CONFIG["host_os"] == "cygwin"
10
-
11
7
  url = "file://#{index_path}?" + { port: server.port, path: @window_id, boot: FlammarionRails.config.boot_path }.to_query
12
8
  @browser_options = options.merge(url: url)
13
9
  @requested_browser = ENV["FLAMMARION_BROWSER"] || options[:browser]
@@ -47,14 +43,9 @@ module Flammarion
47
43
 
48
44
  browser :chrome_windows do |options|
49
45
  return false unless RbConfig::CONFIG["host_os"] =~ /cygwin|mswin|mingw/
50
- file_path = File.absolute_path(File.join(File.dirname(__FILE__), ".."))
51
- file_path = `cygpath -w '#{file_path}'`.strip if RbConfig::CONFIG["host_os"] == "cygwin"
52
- resource = %[file\://#{file_path}/html/build/index.html]
53
- resource = "http://localhost:4567/" if options[:development_mode]
54
- chrome_path = CHROME_PATH
55
- chrome_path = `cygpath -u '#{CHROME_PATH}'`.strip if RbConfig::CONFIG["host_os"] == "cygwin"
56
- return false unless File.exist?(chrome_path)
57
- Process.detach(spawn(chrome_path, %[--app=#{resource}?path=#{@window_id}&port=#{server.port}]))
46
+ executable = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
47
+ return false unless File.exist?(executable)
48
+ Process.detach(spawn(executable, %[--app=#{options[:url]}]))
58
49
  end
59
50
 
60
51
  browser :chrome do |options|
@@ -1,3 +1,3 @@
1
1
  module FlammarionRails
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -4,5 +4,5 @@ APP_PATH = File.expand_path('../config/application', __dir__)
4
4
  require APP_PATH
5
5
  Rails.application.require_environment!
6
6
 
7
- f = Flammarion::Engraving.new(exit_on_disconnect:true)
7
+ f = Flammarion::Engraving.new
8
8
  f.wait_until_closed
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flammarion_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrice Lebel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-11 00:00:00.000000000 Z
11
+ date: 2016-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails