File tree 7 files changed +100
-0
lines changed
7 files changed +100
-0
lines changed Original file line number Diff line number Diff line change
1
+ pkg /*
2
+ * .gem
3
+ .bundle
Original file line number Diff line number Diff line change
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in webloc.gemspec
4
+ gemspec
Original file line number Diff line number Diff line change
1
+ # webloc
2
+
3
+ * webloc* is a Ruby library that can read from and write to <tt >.webloc</tt > files as used on OS X.
4
+
5
+ It works on both Ruby 1.9.2 and 1.8.7 (though development is focused on 1.9.2).
6
+
7
+ ## Installation
8
+
9
+ gem install webloc
10
+
11
+ ## Usage
12
+
13
+ It's pretty simple.
14
+
15
+ Reading a .webloc file:
16
+
17
+ Webloc.load(ARGV.first).url
18
+
19
+ Writing to a .webloc file:
20
+
21
+ Webloc.new('http://peterc.org/').save('peterc.webloc')
22
+
23
+ ## License
24
+
25
+ Copyright (C) 2011 Peter Cooper
26
+
27
+ webloc is licensed under the terms of the MIT License
Original file line number Diff line number Diff line change
1
+ require 'bundler'
2
+ Bundler ::GemHelper . install_tasks
Original file line number Diff line number Diff line change
1
+ require 'plist'
2
+
3
+ class Webloc
4
+ attr_accessor :url
5
+
6
+ def initialize ( url )
7
+ @url = url
8
+ end
9
+
10
+ def self . load ( filename )
11
+ data = File . read ( filename )
12
+ data = data . force_encoding ( 'binary' ) rescue data
13
+
14
+ if data !~ /\< plist/
15
+ offset = ( data =~ /SURL_/ )
16
+ length = data [ offset + 6 ]
17
+ length = length . ord rescue length
18
+ url = data [ offset + 7 , length ]
19
+ else
20
+ url = Plist ::parse_xml ( filename ) [ 'URL' ] rescue nil
21
+ end
22
+
23
+ raise ArgumentError unless url
24
+ new ( url )
25
+ end
26
+
27
+ def data
28
+ @data = "\x62 \x70 \x6C \x69 \x73 \x74 \x30 \x30 \xD1 \x01 \x02 \x53 \x55 \x52 \x4C \x5F \x10 "
29
+ @data += @url . length . chr
30
+ @data += @url
31
+ @data += "\x08 \x0B \x0F \x00 \x00 \x00 \x00 \x00 \x00 \x01 \x01 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x03 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 "
32
+ @data += ( @url . length + 18 ) . chr
33
+ end
34
+
35
+ def save ( filename )
36
+ File . open ( filename , 'w:binary' ) { |f | f . print data }
37
+ end
38
+ end
Original file line number Diff line number Diff line change
1
+ class Webloc
2
+ VERSION = "0.0.1"
3
+ end
Original file line number Diff line number Diff line change
1
+ # -*- encoding: utf-8 -*-
2
+ $:. push File . expand_path ( "../lib" , __FILE__ )
3
+ require "webloc/version"
4
+
5
+ Gem ::Specification . new do |s |
6
+ s . name = "webloc"
7
+ s . version = Webloc ::VERSION
8
+ s . platform = Gem ::Platform ::RUBY
9
+ s . authors = [ "Peter Cooper" ]
10
+ s . email = [ "peter@petercooper.co.uk" ]
11
+ s . homepage = "http://github.com/peterc/webloc"
12
+ s . summary = %q{Reads and writes .webloc files on OS X}
13
+ s . description = %q{Webloc reads and writes .webloc files on OS X}
14
+
15
+ s . rubyforge_project = "webloc"
16
+
17
+ s . files = `git ls-files` . split ( "\n " )
18
+ s . test_files = `git ls-files -- {test,spec,features}/*` . split ( "\n " )
19
+ s . executables = `git ls-files -- bin/*` . split ( "\n " ) . map { |f | File . basename ( f ) }
20
+ s . require_paths = [ "lib" ]
21
+
22
+ s . add_dependency 'plist'
23
+ end
You can’t perform that action at this time.
0 commit comments