sharkey-web 3.3.1 → 3.3.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f53d2ea02c3428a8b79fa0d255f81d79df9e5961
4
- data.tar.gz: b318484b07be8b692ea824d7e472304feb27c160
3
+ metadata.gz: 06c859fd93f5ac733140dd9cb2d3662e99c11d25
4
+ data.tar.gz: 41e261fb32b555653c430a6c2e6a36e00da25ee2
5
5
  SHA512:
6
- metadata.gz: b70b6a52387f1bd8f730d277c3eb2239609b6267bf87dc6a2eb958c220317dd351c0128cd2d3893c2f4c3b98125ec955a0bcb71c25a6ee5477dcc92f24052650
7
- data.tar.gz: 3b16133fe035b6f9a219873c2db09d2056d330e0ccf2d522c86b9eaa6fa14efad4c1fed3ffd85f6431c7ad88fe33f6baecc83b4ae8019e44f6ccab936c70136d
6
+ metadata.gz: 6040314cc0df0c3e8b172651782d85f381469c707744440683226a5137c479ee1a067058f8bb04945f36d9a2f96b3eb27309ff1bbc17fd19a4db62acf2a60233
7
+ data.tar.gz: 2b34103961644e0d9ec3434f144a41b679a0fe52547542105481566435a97e2e21dc4d9c1664786ab67bd22ac4f5091b2e85dda9c600d3a445e07cc186b662cf
@@ -0,0 +1,9 @@
1
+ require "deps/markio/version"
2
+ require "deps/markio/bookmark"
3
+ require "deps/markio/parser"
4
+ require "deps/markio/builder"
5
+ module Markio
6
+ def self.parse(data)
7
+ Parser.new(data).parse
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ require 'date'
2
+ class Markio::Bookmark
3
+
4
+ attr_accessor :title, :href, :add_date, :last_visit, :last_modified, :folders, :tags
5
+
6
+ def self.create data
7
+ bookmark = new
8
+ bookmark.title = data[:title]
9
+ bookmark.href = data[:href]
10
+ bookmark.add_date = data[:add_date] || DateTime.now
11
+ bookmark.last_visit = data[:add_date]
12
+ bookmark.last_modified = data[:last_modified]
13
+ bookmark.folders = data[:folders] || []
14
+ bookmark.tags = data[:tags] || []
15
+ bookmark
16
+ end
17
+
18
+ def == other
19
+ unless other.nil? or other.class != self.class
20
+ other.href == href and other.title == title
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,80 @@
1
+ require 'nokogiri'
2
+
3
+ class Markio::Builder
4
+
5
+ attr_accessor :bookmarks
6
+
7
+ def initialize(options = {})
8
+ @title = options[:title] || 'Bookmarks'
9
+ @bookmarks = []
10
+ end
11
+
12
+ def build_string
13
+ build
14
+ end
15
+
16
+ def build_file(file)
17
+ File.new(file, 'w') do |f|
18
+ f.write build
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def build
25
+
26
+ bookmarks = { nil => [] }
27
+ @bookmarks.each do |b|
28
+
29
+ if b.folders.any?
30
+ b.folders.each do |f|
31
+ bookmarks[f] ||= []
32
+ bookmarks[f] << b
33
+ end
34
+ else
35
+ bookmarks[nil] << b
36
+ end
37
+ end
38
+
39
+ docparts = Nokogiri::HTML::DocumentFragment.parse ''
40
+ Nokogiri::HTML::Builder.with(docparts) do |html|
41
+ html.comment <<END
42
+ This is an automatically generated file.
43
+ It will be read and overwritten.
44
+ DO NOT EDIT!
45
+ END
46
+ html.meta('HTTP-EQUIV' => 'Content-Type', 'CONTENT' => 'text/html; charset=UTF-8')
47
+ html.title @title
48
+ html.dl {
49
+ html.p
50
+ bookmarks.keys.each do |f|
51
+ unless f.nil?
52
+ html.dt {
53
+ html.h3 f
54
+ html.dl {
55
+ html.p
56
+ bookmarks[f].each { |b| build_bookmark html, b }
57
+ }
58
+ }
59
+ else
60
+ bookmarks[nil].each { |b| build_bookmark html, b }
61
+ end
62
+ end
63
+ }
64
+ end
65
+
66
+ "<!DOCTYPE NETSCAPE-Bookmark-file-1>\n" << docparts.to_html
67
+ end
68
+
69
+ private
70
+
71
+ def build_bookmark(html, b)
72
+ html.dt {
73
+ params = { :href => b.href }
74
+ params[:add_date] = b.add_date.to_time.to_i if b.add_date
75
+ params[:last_visit] = b.last_visit.to_time.to_i if b.last_visit
76
+ params[:last_modified] = b.last_modified.to_time.to_i if b.last_modified
77
+ html.a(b.title, params)
78
+ }
79
+ end
80
+ end
@@ -0,0 +1,82 @@
1
+ require 'nokogiri'
2
+ require 'date'
3
+ module Markio
4
+ class Parser
5
+
6
+ def initialize data
7
+ @document = Nokogiri::HTML data
8
+ end
9
+
10
+ def parse
11
+ bookmarks = []
12
+ traverse(@document, []) do |bookmark|
13
+ bookmarks << bookmark
14
+ end
15
+ consolidate bookmarks
16
+ end
17
+
18
+ private
19
+
20
+ def traverse node, folders, &block
21
+ node.xpath("./*").each do |child|
22
+ case child.name.downcase
23
+ when 'dl'
24
+ traverse child, folders, &block
25
+ folders.pop
26
+ when 'a'
27
+ yield parse_bookmark(child, folders)
28
+ when 'h3'
29
+ folders << child.text
30
+ else
31
+ if child.children.any?
32
+ traverse child, folders, &block
33
+ end
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ def parse_bookmark(node, folders)
40
+ data = {}
41
+ node.attributes.each do |k, a|
42
+ data[k.downcase] = a.value
43
+ end
44
+ bookmark = Bookmark.new
45
+ bookmark.href = data['href']
46
+ bookmark.title = node.text
47
+ bookmark.folders = Array.new(folders)
48
+ bookmark.tags = parse_tags(data['tags'])
49
+ bookmark.add_date = parse_timestamp data['add_date']
50
+ bookmark.last_visit = parse_timestamp data['last_visit']
51
+ bookmark.last_modified = parse_timestamp data['last_modified']
52
+ bookmark
53
+ end
54
+
55
+ def parse_timestamp(timestamp)
56
+ Time.at(timestamp.to_i).to_datetime if timestamp
57
+ end
58
+
59
+ def parse_tags(tags)
60
+ tags ? tags.split(/,/x) : []
61
+ end
62
+
63
+ # Makes sure there are no repeated links on the
64
+ # final bookmarks.
65
+ #
66
+ def consolidate(bookmarks)
67
+ consolidated = []
68
+
69
+ # Will only add to the final Array
70
+ # links that are unique within the set
71
+ bookmarks.each do |b|
72
+ index = consolidated.index b
73
+
74
+ consolidated << b if index.nil?
75
+ end
76
+
77
+ consolidated
78
+ end
79
+
80
+ end
81
+ end
82
+
@@ -0,0 +1,3 @@
1
+ module Markio
2
+ VERSION = "0.1.1"
3
+ end
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Sharkey
3
- VERSION = '3.3.1'
3
+ VERSION = '3.3.2'
4
4
  end
5
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sharkey-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 3.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Dantas
@@ -210,6 +210,11 @@ files:
210
210
  - Rakefile
211
211
  - bin/sharkey-web
212
212
  - config.ru
213
+ - lib/deps/markio.rb
214
+ - lib/deps/markio/bookmark.rb
215
+ - lib/deps/markio/builder.rb
216
+ - lib/deps/markio/parser.rb
217
+ - lib/deps/markio/version.rb
213
218
  - lib/sharkey.rb
214
219
  - lib/sharkey/app.rb
215
220
  - lib/sharkey/importerexporter.rb