bookmarks 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bb320228bd68d2c679651f8b0bef8ed3be77526a
4
+ data.tar.gz: 6049fb5986c41ae4ffb2eaf5618e6046b39d3bd7
5
+ SHA512:
6
+ metadata.gz: 343aec86130060ee882d7eda260dbdbdd81fdddb525ac8e705d1f3978fe6a344083c60d56cf476ddf093064f7df8366d99c84a88e47c847be19aa74f5c60337e
7
+ data.tar.gz: 30fcb9a2a5bda9c3746758503cc183ef83da15b35ecb9b1312444a44449bc8ce025d379fc355fe994ea9c7b99ef74419fd8da3568bd3b0867b0ae488e9d94f86
@@ -0,0 +1,4 @@
1
+ version 0.1.0 (2013-xx-xx)
2
+ ===========================
3
+
4
+ First release.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
6
+ gem 'rspec'
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bookmarks (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coco (0.7.1)
10
+ diff-lcs (1.2.4)
11
+ rake (10.1.0)
12
+ rspec (2.14.0)
13
+ rspec-core (~> 2.14.0)
14
+ rspec-expectations (~> 2.14.0)
15
+ rspec-mocks (~> 2.14.0)
16
+ rspec-core (2.14.1)
17
+ rspec-expectations (2.14.0)
18
+ diff-lcs (>= 1.1.3, < 2.0)
19
+ rspec-mocks (2.14.1)
20
+ tomparse (0.4.2)
21
+ yard (0.8.6.2)
22
+ yard-tomdoc (0.7.1)
23
+ tomparse (>= 0.4.0)
24
+ yard
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bookmarks!
31
+ coco (>= 0.7.1)
32
+ rake
33
+ rspec
34
+ yard
35
+ yard-tomdoc
data/README.markdown ADDED
@@ -0,0 +1,70 @@
1
+ Bookmarks [![Build Status](https://travis-ci.org/lkdjiin/bookmarks.png)](https://travis-ci.org/lkdjiin/bookmarks)
2
+ ================
3
+
4
+ Description
5
+ -----------
6
+
7
+ Bookmarks is a library to parse or build a file of bookmarks, currently
8
+ only files in netscape format, like the ones exported by Delicious.
9
+
10
+ Install
11
+ -------------------------
12
+
13
+ On the CLI
14
+
15
+ gem install bookmarks
16
+
17
+ or in a Gemfile
18
+
19
+ gem 'bookmarks'
20
+
21
+ Usage
22
+ --------------------------
23
+
24
+ require 'bookmarks'
25
+
26
+ # To parse a document.
27
+ document = Document.new
28
+ document.parse 'bookmarks_file.html'
29
+ document.total # => Number of bookmarks.
30
+ first_bookmark = document.bookmarks.first
31
+ first_bookmark.class # => NetscapeBookmark
32
+ first_bookmark.url # => Url of the bookmark.
33
+ first_bookmark.title # => Title of the bookmark.
34
+ first_bookmark.tags # => Tags of the bookmark.
35
+ first_bookmark.date # => Date of the bookmark.
36
+ first_bookmark.description # => Description of the bookmark.
37
+
38
+ # To build a document.
39
+ # ary is an array of NetscapeBookmark.
40
+ document.build do
41
+ ary.each {|e| e }
42
+ end
43
+
44
+
45
+
46
+ Dependencies
47
+ --------------------------
48
+
49
+ * ruby >= 2.0.0
50
+
51
+ Contributing
52
+ -------------------------
53
+
54
+ 1. Fork it
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create new Pull Request
59
+
60
+
61
+ License
62
+ --------------------------
63
+
64
+
65
+
66
+ Questions and/or Comments
67
+ --------------------------
68
+
69
+ Feel free to email [Xavier Nayrac](mailto:xavier.nayrac@gmail.com)
70
+ with any questions, or contact me on [twitter](https://twitter.com/lkdjiin).
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'rake'
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc 'Test Bookmarks'
7
+ task :default => :spec
8
+
9
+ desc 'Test Bookmarks with rspec'
10
+ RSpec::Core::RakeTask.new(:spec) do |t|
11
+ t.rspec_opts = ['--color']
12
+ end
13
+
14
+ desc 'Check for code smells'
15
+ task :reek do
16
+ puts 'Checking for code smells...'
17
+ files = Dir.glob 'lib/**/*.rb'
18
+ args = files.join(' ')
19
+ sh "reek --quiet #{args} | ./reek.sed"
20
+ end
21
+
22
+ desc 'Generate documentation'
23
+ task :doc do
24
+ sh "yard --plugin tomdoc"
25
+ end
data/TODO ADDED
@@ -0,0 +1,3 @@
1
+
2
+ Vérifier
3
+ * gemspec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,104 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Bookmarks
4
+
5
+ # Public: Document is your main interface to the file of bookmarks
6
+ # (called «document»).
7
+ class Document
8
+
9
+ # Public: Init a new Document.
10
+ #
11
+ # format - The Symbol format of the document (Optional).
12
+ #
13
+ # Examples
14
+ #
15
+ # # The two following calls work the same way.
16
+ # Document.new
17
+ # Document.new format: :netscape
18
+ def initialize format: :netscape
19
+ @bookmarks_format = format
20
+ @document = ""
21
+ @bookmarks = []
22
+ @total = 0
23
+ end
24
+
25
+ # Public: Returns the Symbol format of the document. Currently
26
+ # there is only one format available: `:netscape`.
27
+ attr_reader :bookmarks_format
28
+
29
+ # Public: Returns the String document.
30
+ attr_reader :document
31
+
32
+ # Public: Returns an Array of NetscapeBookmark bookmarks.
33
+ attr_reader :bookmarks
34
+
35
+ # Public: Returns the Integer numbers of bookmarks in the document.
36
+ attr_reader :total
37
+
38
+ # Public: Build a document, ie build a file of bookmarks.
39
+ #
40
+ # block - A block that enumerate all NetscapeBookmark to put
41
+ # into the document.
42
+ #
43
+ # Examples
44
+ #
45
+ # # ary is an array of NetscapeBookmark.
46
+ # document.build do
47
+ # ary.each {|e| e }
48
+ # end
49
+ #
50
+ # Returns the String document.
51
+ def build &block
52
+ @document += FIRST_PART
53
+ block.call.each do |n|
54
+ @document += n.to_s + "\n"
55
+ @total += 1
56
+ end
57
+ @document += LAST_PART
58
+ end
59
+
60
+ # Public: Parse a file of bookmarks (netscape format). Bookmarks could
61
+ # then be retrieved with #bookmarks.
62
+ #
63
+ # file_path - Full String pathname of the file to parse.
64
+ #
65
+ # Returns the String document (see also #document).
66
+ def parse file_path
67
+ File.new(file_path).readlines.each {|line| parse_a_bookmark line }
68
+ @total = @bookmarks.size
69
+ end
70
+
71
+ private
72
+
73
+ # Parse a single line from a bookmarks file.
74
+ #
75
+ # line - String.
76
+ #
77
+ # Returns nothing.
78
+ def parse_a_bookmark line
79
+ if line =~ /^<DT>/
80
+ @bookmarks << NetscapeBookmark.from_string(line)
81
+ elsif line =~ /^<DD>/
82
+ @bookmarks.last.description = line[4..-1].chomp
83
+ end
84
+ end
85
+
86
+
87
+ # First part of a bookmark's file in netscape format.
88
+ FIRST_PART = <<CODE
89
+ <!DOCTYPE NETSCAPE-Bookmark-file-1>
90
+ <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
91
+ <!-- This is an automatically generated file.
92
+ It will be read and overwritten.
93
+ Do Not Edit! -->
94
+ <TITLE>Bookmarks</TITLE>
95
+ <H1>Bookmarks</H1>
96
+ <DL><p>
97
+ CODE
98
+
99
+ # Last part of a bookmark's file in netscape format.
100
+ LAST_PART = "</DL><p>\n"
101
+
102
+ end
103
+
104
+ end
@@ -0,0 +1,94 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Bookmarks
4
+
5
+ # Public: A single bookmark in netscape format.
6
+ class NetscapeBookmark
7
+
8
+ # Public: Init a new NetscapeBookmark.
9
+ #
10
+ # url - An optional String url.
11
+ # title - An optional String title.
12
+ # date - An optional Date/DateTime date.
13
+ # tags - An optional String tags. Tags are comma separated.
14
+ # description - An optional String description.
15
+ def initialize url: "", title: "", date: nil, tags: "", description: ""
16
+ @url = url
17
+ @title = title
18
+ @date = date
19
+ @tags = tags
20
+ @description = description
21
+ end
22
+
23
+ # Public: Initialize a new NetscapeBookmark object from a line from
24
+ # a bookmarks file.
25
+ #
26
+ # line - String line from a bookmarks file.
27
+ #
28
+ # Returns a new NetscapeBookmark object.
29
+ def self.from_string line
30
+ url = /HREF="(.*?)"/.match(line)[1]
31
+ title = /HREF=.*>(.*)<\/A>$/.match(line)[1]
32
+ date = /ADD_DATE="(.*?)"/.match(line)[1]
33
+ date = Time.at(date.to_i).to_s
34
+ tags = /TAGS="(.*?)"/.match(line)[1]
35
+ title = prettify_title title, url
36
+ new url: url, title: title, date: date, tags: tags
37
+ end
38
+
39
+
40
+ # Public: Set/get the String url.
41
+ attr_accessor :url
42
+
43
+ # Public: Set/get the String title.
44
+ attr_accessor :title
45
+
46
+ # Public: Set/get the Date/DateTime date.
47
+ attr_accessor :date
48
+
49
+ # Public: Set/get the String tags.
50
+ attr_accessor :tags
51
+
52
+ # Public: Set/get the String description.
53
+ attr_accessor :description
54
+
55
+ # Public: Returns the bookmark as a String.
56
+ def to_s
57
+ str = "<DT><A HREF=\"#{@url}\" " +
58
+ "ADD_DATE=\"#{@date.nil? ? "" : @date.to_time.to_i}\" " +
59
+ "TAGS=\"#{@tags}\">" +
60
+ (@title.empty? ? 'None' : @title) + "</A>"
61
+ if @description.empty?
62
+ str
63
+ else
64
+ str + "\n<DD>#{@description}"
65
+ end
66
+ end
67
+
68
+ # In some case (which?) Delicious miss the title and we have a crapy
69
+ # 'None' instead of the original title. Bad news is the original title
70
+ # is lost. And there is no good news :) In such case, we build a new
71
+ # title from the url.
72
+ #
73
+ # Examples
74
+ #
75
+ # # Before expand_title
76
+ # @title # => 'None'
77
+ # @url # => "http://designmodo.com/flat-design-colors/"
78
+ # # After expand_title
79
+ # @title # => 'flat design colors'
80
+ #
81
+ # Returns String prettified title.
82
+ def self.prettify_title title, url
83
+ return title unless title == '' || title == 'None'
84
+ title = url
85
+ # Remove '/' at the end if it exists.
86
+ title = title.gsub(/\/$/, '')
87
+ # Keep the last element of the url.
88
+ title = title.match(/^.*\/(.*)/)[1]
89
+ # Substitute each '-' by a space.
90
+ title = title.gsub('-', ' ')
91
+ end
92
+
93
+ end
94
+ end
data/lib/bookmarks.rb ADDED
@@ -0,0 +1,11 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $LOAD_PATH.unshift File.dirname(__FILE__)
4
+ $BOOKMARKS_PATH = File.expand_path(File.expand_path(File.dirname(__FILE__)) + '/..')
5
+
6
+ require 'bookmarks/document'
7
+ require 'bookmarks/netscape_bookmark'
8
+
9
+ # Public: Bookmarks is a library to parse or build a file of bookmarks.
10
+ module Bookmarks
11
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bookmarks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Xavier Nayrac
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coco
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.7.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.7.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard-tomdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: |-
70
+ Bookmarks is a library to parse or build a file of
71
+ bookmarks, currently only files in netscape format, like the ones
72
+ exported by Delicious.
73
+ email: xavier.nayrac@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - lib/bookmarks.rb
79
+ - lib/bookmarks/document.rb
80
+ - lib/bookmarks/netscape_bookmark.rb
81
+ - Changelog.markdown
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - README.markdown
85
+ - Rakefile
86
+ - TODO
87
+ - VERSION
88
+ homepage: https://github.com/lkdjiin/bookmarks
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: 2.0.0
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.0.3
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Bookmarks is a library to parse or build a file of bookmarks.
112
+ test_files: []
113
+ has_rdoc: