publicious 0.1.0 → 0.2.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.
data/Rakefile CHANGED
@@ -10,16 +10,6 @@ Rake::TestTask.new(:test) do |t|
10
10
  t.pattern = 'test/*_test.rb'
11
11
  end
12
12
 
13
- require 'jeweler'
14
- Jeweler::Tasks.new do |gemspec|
15
- gemspec.name = "publicious"
16
- gemspec.summary = "A Rails gem plugin for plugins to serve images, javascripts and stylesheets from thier own public directory"
17
- gemspec.description = "A Rails gem plugin for plugins to serve images, javascripts and stylesheets from thier own public directory"
18
- gemspec.email = "justin@indent.com.au"
19
- gemspec.homepage = "http://github.com/justinfrench/publicious"
20
- gemspec.authors = ["Justin French", "Daniel Neighman"]
21
- end
22
-
23
13
  desc 'Generate documentation for the Publicious plugin.'
24
14
  Rake::RDocTask.new(:rdoc) do |rdoc|
25
15
  rdoc.rdoc_dir = 'rdoc'
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Rails::Application.routes.draw do |map|
2
+ match "/stylesheets/*path" => Publicious::Responder
3
+ match "/images/*path" => Publicious::Responder
4
+ match "/javascripts/*path" => Publicious::Responder
5
+ end
data/lib/publicious.rb CHANGED
@@ -1 +1,13 @@
1
- require File.join(File.dirname(__FILE__), "../rails/init")
1
+ Mime::Type.register "image/jpeg", :jpg
2
+ Mime::Type.register "image/gif", :gif
3
+ Mime::Type.register "image/png", :png
4
+
5
+ module Publicious
6
+ class Engine < Rails::Engine
7
+ engine_name :publicious
8
+ end
9
+ end
10
+
11
+ require "publicious/responder"
12
+
13
+
@@ -0,0 +1,51 @@
1
+ module Publicious
2
+ class Responder
3
+
4
+ def self.call(env)
5
+ request = Rack::Request.new(env)
6
+ if request.path_info =~ %r{^\/(#{allowed_dirs.join("|")})}
7
+ file_name = nil
8
+ path = nil
9
+
10
+ public_paths.detect do |pub_path|
11
+ path = pub_path
12
+ fp = File.join(pub_path, request.path_info)
13
+ file_name = fp if File.file?(fp)
14
+ end
15
+
16
+ return respond_not_found! unless file_name
17
+
18
+ # Make sure pricks aren't ../../config/database.yml ing us
19
+ respond_not_found! unless file_name.gsub(%r[^#{path}], "") == request.path_info
20
+
21
+ Rack::Response.new(
22
+ File.open(file_name),
23
+ 200,'Content-Type' => content_type_for_file(file_name)
24
+ ).finish
25
+ else
26
+ respond_not_found!
27
+ end
28
+ end
29
+
30
+ def self.respond_not_found!
31
+ Rack::Response.new("Not Found", 404).finish
32
+ end
33
+
34
+ def self.allowed_dirs
35
+ %w(stylesheets javascripts images)
36
+ end
37
+
38
+ def self.content_type_for_file(name)
39
+ file_name = File.basename(name).split(".").last.to_s
40
+ Mime::Type.lookup_by_extension(file_name).to_s
41
+ end
42
+
43
+ def self.public_paths
44
+ ::Rails::Engine.subclasses.map { |klass|
45
+ klass.config.paths.public.paths.first
46
+ }.flatten.compact.reject { |path| path =~ /publicious/}
47
+ end
48
+
49
+ end
50
+
51
+ end
Binary file
@@ -0,0 +1,29 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{publicious}
3
+ s.version = "0.2.1"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["Justin French", "Daniel Neighman"]
7
+ s.date = %q{2010-07-02}
8
+ s.description = %q{A Rails 3 gem plugin for plugins to serve images, javascripts and stylesheets from thier own public directory}
9
+ s.summary = %q{A Rails gem plugin for plugins to serve images, javascripts and stylesheets from thier own public directory}
10
+ s.email = %q{justin@indent.com.au}
11
+ s.homepage = %q{http://github.com/justinfrench/publicious}
12
+ s.extra_rdoc_files = [
13
+ "README.textile"
14
+ ]
15
+ s.files = Dir["**/*"]
16
+ s.rdoc_options = ["--charset=UTF-8"]
17
+ s.require_paths = ["lib"]
18
+ s.rubygems_version = %q{1.3.5}
19
+
20
+ if s.respond_to? :specification_version then
21
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
25
+ else
26
+ end
27
+ else
28
+ end
29
+ end
@@ -33,19 +33,7 @@ class MultipleMatchesTest < Test::Unit::TestCase
33
33
  def test_should_respond_with_success
34
34
  assert last_response.ok?
35
35
  end
36
-
37
- def test_view_paths_should_contain_three_items
38
- assert_equal 4, ActionController::Base.view_paths.size
39
- end
40
-
41
- def test_public_paths_should_contain_two_items
42
- assert_equal 3, app.public_paths.size # one less that view_paths
43
- end
44
-
45
- def test_public_paths_should_contain_the_plugins_public_dir
46
- assert_equal "/tmp/vendor/my_plugin/public", app.public_paths.second
47
- end
48
-
36
+
49
37
  def test_should_respond_with_first_file_contents
50
38
  assert_equal File.read(@filename_1), last_response.body
51
39
  assert_equal @filecontents_1, last_response.body
@@ -23,19 +23,7 @@ class SingleMatchTest < Test::Unit::TestCase
23
23
  def test_should_respond_with_success
24
24
  assert last_response.ok?
25
25
  end
26
-
27
- def test_view_paths_should_contain_three_items
28
- assert_equal 2, ActionController::Base.view_paths.size
29
- end
30
-
31
- def test_public_paths_should_contain_two_items
32
- assert_equal 1, app.public_paths.size # one less that view_paths
33
- end
34
-
35
- def test_public_paths_should_contain_the_plugins_public_dir
36
- assert_equal "/tmp/vendor/my_plugin/public", app.public_paths.first
37
- end
38
-
26
+
39
27
  def test_should_respond_with_first_file_contents
40
28
  assert_equal File.read(@filename), last_response.body
41
29
  assert_equal @filecontents, last_response.body
data/test/test_helper.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
3
  require "rack/test"
4
+ require "rails"
4
5
  require "action_controller"
5
- require File.join(File.dirname(__FILE__), "../app/metal/publicious_metal")
6
- require File.join(File.dirname(__FILE__), "../rails/init")
6
+ require "publicious"
7
7
 
8
8
  RAILS_ROOT = "/tmp"
9
9
 
@@ -11,7 +11,7 @@ module TestHelper
11
11
  include Rack::Test::Methods
12
12
 
13
13
  def app
14
- PubliciousMetal
14
+ Publicious::Responder
15
15
  end
16
16
 
17
17
  def setup_vendor_dir
@@ -49,8 +49,16 @@ module TestHelper
49
49
  plugin_names.each do |plugin_name|
50
50
  plugin_name = plugin_name.to_s
51
51
 
52
- ActionController::Base.view_paths << File.join(@vendor_dir, plugin_name, 'app', 'views')
53
-
52
+ class_eval "
53
+ module ::#{plugin_name.classify}
54
+ class Engine < ::Rails::Engine
55
+ #engine_name :#{plugin_name}
56
+ paths.public = '#{@vendor_dir}/#{plugin_name}/public'
57
+ end
58
+ end"
59
+
60
+ #ActionController::Base.view_paths << File.join(@vendor_dir, plugin_name, 'app', 'views')
61
+
54
62
  FileUtils.mkdir(File.join(@vendor_dir, plugin_name))
55
63
  FileUtils.mkdir(File.join(@vendor_dir, plugin_name, 'public'))
56
64
  FileUtils.mkdir(File.join(@vendor_dir, plugin_name, 'public', 'stylesheets'))
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: publicious
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 1
9
+ version: 0.2.1
5
10
  platform: ruby
6
11
  authors:
7
12
  - Justin French
@@ -10,11 +15,11 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2009-11-23 00:00:00 +11:00
18
+ date: 2010-07-02 00:00:00 +10:00
14
19
  default_executable:
15
20
  dependencies: []
16
21
 
17
- description: A Rails gem plugin for plugins to serve images, javascripts and stylesheets from thier own public directory
22
+ description: A Rails 3 gem plugin for plugins to serve images, javascripts and stylesheets from thier own public directory
18
23
  email: justin@indent.com.au
19
24
  executables: []
20
25
 
@@ -23,13 +28,14 @@ extensions: []
23
28
  extra_rdoc_files:
24
29
  - README.textile
25
30
  files:
31
+ - config/routes.rb
32
+ - lib/publicious/responder.rb
33
+ - lib/publicious.rb
26
34
  - MIT-LICENSE
27
- - README.textile
35
+ - publicious-0.2.0.gem
36
+ - publicious.gemspec
28
37
  - Rakefile
29
- - VERSION
30
- - app/metal/publicious_metal.rb
31
- - lib/publicious.rb
32
- - rails/init.rb
38
+ - README.textile
33
39
  - test/css_test.rb
34
40
  - test/image_test.rb
35
41
  - test/javascript_test.rb
@@ -50,26 +56,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
50
56
  requirements:
51
57
  - - ">="
52
58
  - !ruby/object:Gem::Version
59
+ segments:
60
+ - 0
53
61
  version: "0"
54
- version:
55
62
  required_rubygems_version: !ruby/object:Gem::Requirement
56
63
  requirements:
57
64
  - - ">="
58
65
  - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
59
68
  version: "0"
60
- version:
61
69
  requirements: []
62
70
 
63
71
  rubyforge_project:
64
- rubygems_version: 1.3.5
72
+ rubygems_version: 1.3.6
65
73
  signing_key:
66
74
  specification_version: 3
67
75
  summary: A Rails gem plugin for plugins to serve images, javascripts and stylesheets from thier own public directory
68
- test_files:
69
- - test/css_test.rb
70
- - test/image_test.rb
71
- - test/javascript_test.rb
72
- - test/multiple_match_test.rb
73
- - test/no_match_test.rb
74
- - test/single_match_test.rb
75
- - test/test_helper.rb
76
+ test_files: []
77
+
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.0
@@ -1,49 +0,0 @@
1
- class PubliciousMetal
2
-
3
- def self.call(env)
4
- request = Rack::Request.new(env)
5
- if request.path_info =~ %r{^\/(#{allowed_dirs.join("|")})}
6
- file_name = nil
7
- path = nil
8
-
9
- public_paths.detect do |pub_path|
10
- path = pub_path
11
- fp = File.join(pub_path, request.path_info)
12
- file_name = fp if File.file?(fp)
13
- end
14
-
15
- return respond_not_found! unless file_name
16
-
17
- # Make sure pricks aren't ../../config/database.yml ing us
18
- respond_not_found! unless file_name.gsub(%r[^#{path}], "") == request.path_info
19
-
20
- Rack::Response.new(
21
- File.open(file_name),
22
- 200,'Content-Type' => content_type_for_file(file_name)
23
- ).finish
24
- else
25
- respond_not_found!
26
- end
27
- end
28
-
29
- def self.respond_not_found!
30
- Rack::Response.new("Not Found", 404).finish
31
- end
32
-
33
- def self.allowed_dirs
34
- %w(stylesheets javascripts images)
35
- end
36
-
37
- def self.content_type_for_file(name)
38
- file_name = File.basename(name).split(".").last.to_s
39
- Mime::Type.lookup_by_extension(file_name).to_s
40
- end
41
-
42
- def self.public_paths
43
- ActionController::Base.view_paths.map do |vp|
44
- full_path = File.expand_path(vp.to_s, RAILS_ROOT)
45
- full_path.sub("app/views", "public") if full_path =~ /vendor/
46
- end.compact
47
- end
48
-
49
- end
data/rails/init.rb DELETED
@@ -1,3 +0,0 @@
1
- Mime::Type.register "image/jpeg", :jpg
2
- Mime::Type.register "image/gif", :gif
3
- Mime::Type.register "image/png", :png