citrusbyte-milton 0.1.5 → 0.1.7

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/README CHANGED
@@ -3,6 +3,12 @@
3
3
  Milton is an extensible attachment handling plugin that makes few assumptions
4
4
  but provides a lot of power.
5
5
 
6
+ == More Info
7
+
8
+ http://labs.citrusbyte.com/milton
9
+
10
+ http://github.com/citrusbyte/milton/wikis/home
11
+
6
12
  == Dependencies
7
13
  * ActiveRecord
8
14
  * Rails (for now?)
@@ -46,6 +46,19 @@ module Citrusbyte
46
46
  write_attribute :filename, AttachableFile.sanitize_filename(name)
47
47
  end
48
48
 
49
+ # Simple helper, same as path except returns the directory from
50
+ # .../public/ on, i.e. for showing images in your views.
51
+ #
52
+ # @asset.path => /var/www/site/public/assets/000/000/001/313/milton.jpg
53
+ # @asset.public_path => /assets/000/000/001/313/milton.jpg
54
+ #
55
+ # Can send a different base path than public if you want to give the
56
+ # path from that base on, useful if you change your root path to
57
+ # somewhere else.
58
+ def public_path(options={}, base='public')
59
+ path(options).gsub(/.*?\/#{base}/, '')
60
+ end
61
+
49
62
  # The path to the file, takes an optional hash of options which can be
50
63
  # used to determine a particular derivative of the file desired
51
64
  def path(options={})
@@ -126,7 +139,7 @@ module Citrusbyte
126
139
  def path(options={})
127
140
  options.empty? ? File.join(dirname, filename) : Derivative.new(filename, options).path
128
141
  end
129
-
142
+
130
143
  # Returns the full directory path up to the file, w/o the filename.
131
144
  def dirname
132
145
  File.join(root_path, partitioned_path)
@@ -33,7 +33,7 @@ module Citrusbyte
33
33
  def content_type=(type)
34
34
  write_attribute :content_type, type.to_s.strip
35
35
  end
36
-
36
+
37
37
  protected
38
38
  def attached_file
39
39
  @attached_file ||= ResizeableFile.new(self, filename)
@@ -48,4 +48,20 @@ describe Attachment do
48
48
  @image.path.should =~ /^.*\/#{Citrusbyte::Milton::AttachableFile.partition(@image.id)}\/#{@image.filename}$/
49
49
  end
50
50
  end
51
+
52
+ describe "public path helper" do
53
+ before :each do
54
+ @image = Image.new :file => upload('milton.jpg')
55
+ end
56
+
57
+ it "should give the path from public/ on to the filename" do
58
+ @image.stub!(:path).and_return('/root/public/assets/1/milton.jpg')
59
+ @image.public_path.should eql("/assets/1/milton.jpg")
60
+ end
61
+
62
+ it "should give the path from foo/ on to the filename" do
63
+ @image.stub!(:path).and_return('/root/foo/assets/1/milton.jpg')
64
+ @image.public_path({}, 'foo').should eql("/assets/1/milton.jpg")
65
+ end
66
+ end
51
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: citrusbyte-milton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Alavi