xing-dev-assets 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8bdac05d590be2ce04b7efd3fa7c8db59a071bad
4
+ data.tar.gz: a773c283f92f0270b5b8662664ef6c3dc1c01363
5
+ SHA512:
6
+ metadata.gz: 558d585aeb9dd486efe18d5100f507a6a5127e6445f08d50aa6f5036b85e42df599655e3af6da01fc7cf3768b0edd0e785822c4f705e911054994f9d42265e9f
7
+ data.tar.gz: 6837a86dd89c7ede343d5e2b667ff5d05367d6b01375f572e687a7cebc909370553583fec6a124b7f12aa75a7e37b6ed5adfc0ec1f7a059b2a7691a4a3694e01
@@ -0,0 +1 @@
1
+ require 'xing/dev-assets/rack_app'
@@ -0,0 +1,17 @@
1
+ module Xing
2
+ module DevAssets
3
+ class CookieSetter
4
+ def initialize(app, name, value)
5
+ @name = name
6
+ @value = value
7
+ @app = app
8
+ end
9
+
10
+ def call(env)
11
+ status, headers, body = @app.call(env)
12
+ headers["Set-Cookie"] = [(headers["Set-Cookie"]), "#@name=#@value"].compact.join("\n") unless @name.nil? or @value.nil?
13
+ [ status, headers, body ]
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Xing
2
+ module DevAssets
3
+ class Dumper
4
+ def initialize(app)
5
+ require 'pp'
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ res = @app.call(env)
11
+ pp env
12
+ pp res
13
+ return res
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module Xing
2
+ module DevAssets
3
+ class EmptyFile
4
+ BLANKNESS = [ 200, {"Content-Length" => "0"}, [""]].freeze
5
+
6
+ def call(env)
7
+ return BLANKNESS
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ module Xing
2
+ module DevAssets
3
+ class GotoParam
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ status, headers, body = @app.call(env)
10
+ default = [ status, headers, body ]
11
+ request_path = env["SCRIPT_NAME"] + env["PATH_INFO"]
12
+ unless env["QUERY_STRING"].nil? or env["QUERY_STRING"].empty?
13
+ request_path += "&#{env["QUERY_STRING"]}"
14
+ end
15
+
16
+ return default unless status == 404
17
+ return default if %r(\A/(assets|fonts|system)) =~ request_path
18
+ return default if /\.(xml|html|ico|txt)\z/ =~ request_path
19
+ return default if /goto=/ =~ env["QUERY_STRING"]
20
+
21
+ return [ 301, headers.merge("Location" => "/?goto=#{request_path}", "Content-Length" => "0"), [] ]
22
+ rescue => ex
23
+ require 'pp'
24
+ pp ex
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ module Xing
2
+ module DevAssets
3
+ require 'logger'
4
+ class Logger < ::Logger
5
+ # needed to use stdlib logger with Rack < 1.6.0
6
+ def write(msg)
7
+ self.<<(msg)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,119 @@
1
+ require 'xing/dev-assets/cookie_setter'
2
+ require 'xing/dev-assets/goto_param'
3
+ require 'xing/dev-assets/logger'
4
+ require 'xing/dev-assets/empty_file'
5
+ require 'xing/dev-assets/strip_incoming_cache_headers'
6
+
7
+ module Xing
8
+ module DevAssets
9
+ class RackApp
10
+ def self.build(root_path, backend_port)
11
+ rack_app = new
12
+ rack_app.root_path = root_path
13
+ rack_app.backend_port = backend_port
14
+ yield rack_app if block_given?
15
+ rack_app.build
16
+ end
17
+
18
+ attr_accessor :root_path, :backend_port, :builder
19
+ attr_writer :builder, :backend_url, :env, :logger, :out_stream
20
+
21
+ # Should be override by client app. Ironically, override with exactly
22
+ # this definition will usually work.
23
+ # (because this will log into a dir in the gem, but copied into subclass
24
+ # will be relative to that file and therefore into the project)
25
+ def log_root
26
+ File.expand_path("../../log", __FILE__)
27
+ end
28
+
29
+ def logpath_for_env
30
+ File.join( log_root, "#{env}_static.log")
31
+ end
32
+
33
+ def out_stream
34
+ @out_stream ||= $stdout
35
+ end
36
+
37
+ def backend_url
38
+ @backend_url ||= ENV["XING_BACKEND_URL"] || ENV["LRD_BACKEND_URL"] || "http://localhost:#{backend_port}/"
39
+ end
40
+
41
+ def env
42
+ @env ||= ENV['RAILS_ENV'] || 'development'
43
+ end
44
+
45
+ def logger
46
+ @logger ||= Logger.new(logpath_for_env)
47
+ end
48
+
49
+ def report_startup
50
+ out_stream.puts "Setting up static app:"
51
+ out_stream.puts " serving files from #{root_path}"
52
+ out_stream.puts " using #{backend_url} for API"
53
+ out_stream.puts " logging to #{logpath_for_env}"
54
+ end
55
+
56
+ def goto_redirect
57
+ builder.use GotoParam
58
+ end
59
+
60
+ def cookies
61
+ builder.use CookieSetter, "lrdBackendUrl", backend_url
62
+ builder.use CookieSetter, "xingBackendUrl", backend_url
63
+ end
64
+
65
+ def disable_caching
66
+ builder.use StripIncomingCacheHeaders
67
+ end
68
+
69
+ def logging
70
+ builder.use Rack::CommonLogger, logger
71
+ end
72
+
73
+ def shortcut_livereload
74
+ if env != "development"
75
+ builder.map "/assets/livereload.js" do
76
+ run EmptyFile.new
77
+ end
78
+ end
79
+ end
80
+
81
+ def static_assets
82
+ builder.use Rack::Static, {
83
+ :urls => [""],
84
+ :root => root_path,
85
+ :index => "index.html",
86
+ :header_rules => {
87
+ :all => {"Cache-Control" => "no-cache, max-age=0" } #no caching development assets
88
+ }
89
+ }
90
+ end
91
+
92
+ def stub_application
93
+ builder.run proc{ [500, {}, ["Something went wrong"]] }
94
+ end
95
+
96
+ def setup_middleware
97
+ goto_redirect
98
+ cookies
99
+ disable_caching
100
+ logging
101
+ shortcut_livereload
102
+ static_assets
103
+ end
104
+
105
+ def builder
106
+ @builder ||= Rack::Builder.new
107
+ end
108
+
109
+ def build
110
+ report_startup
111
+
112
+ setup_middleware
113
+ stub_application
114
+
115
+ builder
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,14 @@
1
+ module Xing
2
+ module DevAssets
3
+ class StripIncomingCacheHeaders
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ env.delete('HTTP_IF_MODIFIED_SINCE')
10
+ @app.call(env)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ puts Dir::pwd
2
+ require 'test/unit'
3
+ begin
4
+ require 'spec'
5
+ rescue LoadError
6
+ false
7
+ end
8
+
9
+ class RSpecTest < Test::Unit::TestCase
10
+ def test_that_rspec_is_available
11
+ assert_nothing_raised("\n\n * RSpec isn't available - please run: gem install rspec *\n\n"){ ::Spec }
12
+ end
13
+
14
+ def test_that_specs_pass
15
+ assert(system(*%w{spec -f e -p **/*.rb spec}),"\n\n * Specs failed *\n\n")
16
+ end
17
+ end
File without changes
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xing-dev-assets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Judson Lester
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ description: ''
28
+ email:
29
+ - nyarly@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/xing/dev-assets.rb
35
+ - lib/xing/dev-assets/cookie_setter.rb
36
+ - lib/xing/dev-assets/dumper.rb
37
+ - lib/xing/dev-assets/empty_file.rb
38
+ - lib/xing/dev-assets/goto_param.rb
39
+ - lib/xing/dev-assets/logger.rb
40
+ - lib/xing/dev-assets/rack_app.rb
41
+ - lib/xing/dev-assets/strip_incoming_cache_headers.rb
42
+ - spec_help/gem_test_suite.rb
43
+ - spec_help/spec_helper.rb
44
+ homepage: http://nyarly.github.com/xing-dev-assets
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options:
50
+ - "--inline-source"
51
+ - "--main"
52
+ - doc/README
53
+ - "--title"
54
+ - xing-dev-assets-0.0.1 Documentation
55
+ require_paths:
56
+ - lib/
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project: xing-dev-assets
69
+ rubygems_version: 2.4.8
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: ''
73
+ test_files:
74
+ - spec_help/gem_test_suite.rb