Skip to content

Commit fbe160f

Browse files
committed
Parse & build icon attributes
Parse the attributes `ICON` & `ICON_URI` which are distinct attribute names to include the favicon in files generated by major browsers.
1 parent 2629a87 commit fbe160f

File tree

8 files changed

+40
-12
lines changed

8 files changed

+40
-12
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,16 @@ spec/reports
1515
test/tmp
1616
test/version_tmp
1717
tmp
18+
19+
### RubyMine+all Patch ###
20+
# Ignore everything but code style settings and run configurations
21+
# that are supposed to be shared within teams.
22+
.idea/*
23+
24+
!.idea/codeStyles
25+
!.idea/runConfigurations
26+
!.idea/jsLinters
27+
28+
# JIRA plugin
29+
atlassian-ide-plugin.xml
30+
### END RubyMine+all ###

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ bookmarks.each do |b|
3838
b.add_date # DateTime
3939
b.last_visit # DateTime
4040
b.last_modified # DateTime
41+
b.icon # String
42+
b.icon_uri # String
4143
end
4244
```
4345

@@ -47,17 +49,14 @@ end
4749
builder = Markio::Builder.new
4850
builder.bookmarks << Markio::Bookmark.create({
4951
:title => "Google",
50-
:href => "http://google.com"
52+
:href => "http://google.com",
53+
:icon => "data:image/png;base64,iVBORw==",
54+
:icon_uri => "https://awesome.com/favicon.ico"
5155
})
5256
file_contents = builder.build_string
5357
File.open('/path/to/bookmarks.html', 'w') { |f| f.write file_contents }
5458
```
5559

56-
## TODO
57-
58-
- Builder output to file
59-
- Builder should not ignore bookmark folders
60-
6160
## Contributing
6261

6362
1. Fork it

lib/markio/bookmark.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'date'
22
class Markio::Bookmark
33

4-
attr_accessor :title, :href, :add_date, :last_visit, :last_modified, :folders
4+
attr_accessor :title, :href, :add_date, :last_visit, :last_modified, :folders, :icon_uri, :icon
55

66
def self.create data
77
bookmark = new
@@ -11,6 +11,8 @@ def self.create data
1111
bookmark.last_visit = data[:add_date]
1212
bookmark.last_modified = data[:last_modified]
1313
bookmark.folders = data[:folders] || []
14+
bookmark.icon_uri = data[:icon_uri]
15+
bookmark.icon = data[:icon]
1416
bookmark
1517
end
1618

lib/markio/builder.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def build_bookmark(html, b)
7474
params[:add_date] = b.add_date.to_time.to_i if b.add_date
7575
params[:last_visit] = b.last_visit.to_time.to_i if b.last_visit
7676
params[:last_modified] = b.last_modified.to_time.to_i if b.last_modified
77+
params[:icon_uri] = b.icon_uri if b.icon_uri
78+
params[:icon] = b.icon if b.icon
7779
html.a(b.title, params)
7880
}
7981
end

lib/markio/parser.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def parse_bookmark(node, folders)
4848
bookmark.add_date = parse_timestamp data['add_date']
4949
bookmark.last_visit = parse_timestamp data['last_visit']
5050
bookmark.last_modified = parse_timestamp data['last_modified']
51+
bookmark.icon = data['icon']
52+
bookmark.icon_uri = data['icon_uri']
5153
bookmark
5254
end
5355

spec/assets/one_bookmark.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/builder_spec.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ module Markio
1717
:href => "http://test.com",
1818
:add_date => Date.parse('2012-01-12 11:22:33').to_datetime,
1919
:last_visit => Date.parse('2012-01-13 10:20:30').to_datetime,
20-
:last_modified => Date.parse('2012-01-14 10:21:31').to_datetime
20+
:last_modified => Date.parse('2012-01-14 10:21:31').to_datetime,
21+
:icon => "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==",
22+
:icon_uri => "http://www.mozilla.org/2005/made-up-favicon/0-1350925942950"
2123
})
2224
file_contents = builder.build_string
2325
file_contents.length.should_not be_nil
@@ -26,6 +28,8 @@ module Markio
2628
file_contents.should match "add_date"
2729
file_contents.should match "last_visit"
2830
file_contents.should match "last_modified"
31+
file_contents.should match "icon"
32+
file_contents.should match "icon_uri"
2933
end
3034

3135

@@ -40,7 +44,9 @@ module Markio
4044
:href => "http://test2.com",
4145
:add_date => Date.parse('2012-01-12 11:22:33').to_datetime,
4246
:last_visit => Date.parse('2012-01-13 10:20:30').to_datetime,
43-
:last_modified => Date.parse('2012-01-14 10:21:31').to_datetime
47+
:last_modified => Date.parse('2012-01-14 10:21:31').to_datetime,
48+
:icon => "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==",
49+
:icon_uri => "http://www.mozilla.org/2005/made-up-favicon/0-1350925942950"
4450
})
4551
file_contents = builder.build_string
4652
bookmarks = Markio.parse file_contents
@@ -61,7 +67,9 @@ module Markio
6167
:href => "http://test2.com",
6268
:add_date => Date.parse('2012-01-12 11:22:33').to_datetime,
6369
:last_visit => Date.parse('2012-01-13 10:20:30').to_datetime,
64-
:last_modified => Date.parse('2012-01-14 10:21:31').to_datetime
70+
:last_modified => Date.parse('2012-01-14 10:21:31').to_datetime,
71+
:icon => "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==",
72+
:icon_uri => "http://www.mozilla.org/2005/made-up-favicon/0-1350925942950"
6573
})
6674
file_contents = builder.build_string
6775
bookmarks = Markio.parse file_contents

spec/parser_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ module Markio
1919
bookmark.add_date.class.should be DateTime
2020
bookmark.last_visit.class.should be DateTime
2121
bookmark.last_modified.class.should be DateTime
22+
bookmark.icon.should eq "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQD"\
23+
"wAEhQGAhKmMIQAAAABJRU5ErkJggg=="
24+
bookmark.icon_uri.should eq "http://www.mozilla.org/2005/made-up-favicon/0-1350925942950"
2225
end
2326

2427
it 'should parse multiple bookmarks' do
@@ -53,6 +56,5 @@ module Markio
5356
bookmarks = Markio.parse File.open "spec/assets/corrupted.html"
5457
bookmarks.should eq []
5558
end
56-
5759
end
5860
end

0 commit comments

Comments
 (0)