syclink 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 757f2615ff72bd3c25ef404172faa9308e2a0c7f
4
- data.tar.gz: a0a0ccac857393f6a4beae8a50a0f356e5faf578
3
+ metadata.gz: e8b94d17803bd5986b8a1d79e647adb2e41bb441
4
+ data.tar.gz: 69c75dd52d7a5f2876102c868ea3bdf7a54d58fe
5
5
  SHA512:
6
- metadata.gz: 737469dcc6463c9e13dc21b8cc310c93206bdd18f3a8a9a6ecaf5e164930a48291c4d42ecab3bbee81cc0e7a854cb6a66e27034cf73d14df068b4a16eb9ab48f
7
- data.tar.gz: 0dadc454dcba9d28a8b4123a680a109dc860b216274e3800ce6c94259b3f088f3b86e1f6a3e36fb415a8980f2248568b0fbc6607cbdb6af119aaa69a3cd74fe5
6
+ metadata.gz: ade5ed2673f8b88e1276babe265e339b61a6bcf3bc7b17602cc23a02aeaa999998a29c113d39598b6787371a5e77c5b17b41a9f5b19755b9fbbad597c563b8d2
7
+ data.tar.gz: 01cefbad2719b7633b572344d14b577e7f1dbbdaed6650eda5e200362bc2c2bcbdd8c1159f3c979a9f37b94fb1ba9d5a3313f5d44e1eed70ae0ac1a4d5ca3a69
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- syclink (0.0.2)
4
+ syclink (0.1.0)
5
5
  gli (= 2.13.1)
6
6
  sqlite3 (= 1.3.10)
7
7
 
data/README.md CHANGED
@@ -62,42 +62,60 @@ exist yet the user is asked whether to create it and whether to set it as the
62
62
  default website. This is done with commands that require a website to operate
63
63
  on.
64
64
 
65
- $ syclink -w my-new-website add "http://example.com"
65
+ $ syclink -w my-new-website add link "http://example.com"
66
66
 
67
- Before the command `add` is executed the website is created. In this
67
+ Before the command `add link` is executed the website is created. In this
68
68
  case a website called 'my-new-website' is created in the default directory at
69
69
  `~/.syc/syclink/websites/my-new-website.website
70
70
 
71
- Commands that require a website are `add`, `update`, `delete`, `list`, `find`
72
- and `website create`.
71
+ If an existing website is specified by the `-w` command and it is different
72
+ to the default command, the user is asked whether to set the selected
73
+ website as the default one.
74
+
75
+ Commands that require a website are `add`, `update`, `delete`, `list`, `find`,
76
+ merge, import, export and `website create`.
73
77
 
74
78
  If no website is specified the default website is used.
75
79
 
80
+ Link Commands
81
+ =============
82
+
76
83
  Add a link
77
84
  ----------
78
85
  A link may have a title, a description and a tag. Title, description and tag
79
86
  are optional but a link obviously has to be provided. If no title is given the
80
87
  link is used as the title.
81
88
 
82
- $ syclink add --title "Test page" --tag TEST \
83
- --description 'For testing purposes' http://example.com
89
+ $ syclink add link --title "Test page" --tag TEST \
90
+ --description 'For testing purposes' http://example.com
84
91
 
85
92
  It is also possible to add links from a file
86
93
 
87
- $ syclink file file-with-links
94
+ $ syclink add file file-with-links
88
95
 
89
96
  Update a link
90
97
  -------------
91
98
  To update a link the URL has to be specified. If more than one link has the
92
99
  same URL only the first link is updated.
93
100
 
94
- $ syclink update --title "Example" http://example.com
101
+ $ syclink update link --title "Example" http://example.com
102
+
103
+ It is also possible to update links with links saved to a file
104
+
105
+ $ syclink update file file-with-links
95
106
 
96
- Remove a Link
107
+ If many links have to be updated they can be exported to a csv file. Then
108
+ the changes are made in the csv file and finally the update command is called.
109
+
110
+ $ syclink export csv > exported-links
111
+ edit the links
112
+ $ syclink update file exported-links
113
+
114
+ Delete a Link
97
115
  -------------
98
- To remove one or more links the URLs have to be provided.
116
+ To delete one or more links the URLs have to be provided.
99
117
 
100
- $ syclink delete http://example.com,http://challenge.com
118
+ $ syclink delete http://example.com http://challenge.com
101
119
 
102
120
  List links
103
121
  ----------
@@ -111,12 +129,20 @@ listed. It is possible to specify the columns to print. Possible columns are
111
129
  -------------------+---------------------
112
130
  http://example.com | For testing purposes
113
131
 
132
+ The is a switch `--expand` and a flag `--width`. If no width is specified list
133
+ will print the complete content and probably mess up the table. With a width
134
+ specified the the columns are scaled so the overall width of the table will be
135
+ the size of width specified. The expand switch will expand the table to the
136
+ specified width if the table would be smaller than width.
137
+
138
+ $ syclink list --tag TEST --columns `url,description` --width 70 --expand
139
+
114
140
  Find links
115
141
  ----------
116
142
  It is also possible to search for links based on a search string. The find
117
143
  command searches all attributes of the links and is searching for the occurance
118
- of the search string within the attributes. So the search is not list only
119
- exact matches.
144
+ of the search string within the attributes. So the search does not list exact
145
+ matches only.
120
146
 
121
147
  $ syclink find --columns 'url,tag' 'example'
122
148
 
@@ -124,25 +150,146 @@ exact matches.
124
150
  -------------------+-----
125
151
  http://example.com | TEST
126
152
 
127
- List websites
153
+ The `--expand` switch and the `--width` flag are also available with the
154
+ `find` command. Details see at [List links](#list-links).
155
+
156
+ Merge Links
157
+ -----------
158
+ If there are multiple links with the same URL, these links can be merged. During a merge the first link found will be updated with the join of the values of the other links.
159
+
160
+ $ syclink add link --tag "Day" --name "Work" --description "Busy time" \
161
+ http://example.com
162
+ $ syclink add link --tag "Night" --name "Fun" --description "Fun time" \
163
+ http://example.com
164
+ $ syclink merge
165
+ $ syclink list
166
+
167
+ url | name | description | tag
168
+ -------------------|-----------|--------------------|---------
169
+ http://example.com | Day,Night | Busy time,Fun time | Work,Fun
170
+
171
+ Import Commands
172
+ ===============
173
+ Bookmarks can be imported from _Mozilla Firefox_, _Google Chrome_,
174
+ _Internet Explorer_ and from directories.
175
+
176
+ The command is `syclink import` followed by a sub-command indicating from which
177
+ web browser to import, or from which directory.
178
+
179
+ In case of importing from Internet Explorer and from a directory the parent
180
+ directories are used as tags beginning below the path to the Internet Explorer
181
+ directory or the standard directory. To control to which level the directory
182
+ should be used a `level` switch can be used.
183
+
184
+ $ syclink import dir --level 2
185
+
186
+ Will only use two parent directories as tags.
187
+
188
+ Firefox
189
+ -------
190
+ Firefox stores its bookmarks in a SQLite3 database called places.sqlite. With
191
+ Ubuntu this database is usually located in
192
+
193
+ '~/.mozilla/firefox/*.default/places.sqlite'.
194
+
195
+ If you are on Windows the file is located in the user's home directory
196
+
197
+ '~/AppData/Roaming/Mozilla/Profiles/*.default/places.sqlite'.
198
+
199
+ The bookmarks on Ubuntu can be imported with
200
+
201
+ $ syclink import mf ~/.mozilla/SOME_CRYPTIC_NAME.default/places.sqlite
202
+
203
+ Chrome
204
+ ------
205
+ Google Chrome stores its bookmarks in a JSON file called Bookmarks. With Ubuntu
206
+ this file is usually located in
207
+
208
+ '~/.config/chromium/Default/Bookmarks'.
209
+
210
+ If you are on Windows the file is located in the user's home directory
211
+
212
+ '~/AppData/Local/Google/Chrome/User Data/Bookmarks'.
213
+
214
+ The bookmarks on Ubuntu can be imported with
215
+
216
+ $ syclink import gc ~/.config/chromium/Default/Bookmarks
217
+
218
+ Internet Explorer
219
+ -----------------
220
+ Internet Explorer stores its bookmarks in a directory structure. The bookmarks
221
+ are located in the user's home directory
222
+
223
+ '~/AppData/Favorites'
224
+
225
+ The bookmarks (of course on Windows) can be imported with
226
+
227
+ $ syclink import ie ~/Appdata/Favorites
228
+
229
+ Directory
230
+ ---------
231
+ The PATH\_TO\_DIRECTORY can have patterns that allows to import specific
232
+ files.
233
+
234
+ Examples:
235
+
236
+ PATH_TO_DIRECTORY/**/*.pdf
237
+
238
+ will import all pdf-files in the directories and sub-directory
239
+
240
+ PATH_TO_DIRECTORY/**/*
241
+
242
+ will import all files in the specified directory and sub-directories
243
+
244
+ To import all files from `some-directory` call
245
+
246
+ $ syclink import dir ~/some-directory/**/*
247
+
248
+ If on Windows and the directory contains .URL-files the URL within the .URL-file
249
+ will be used as the link target.
250
+
251
+ Export Commands
252
+ ===============
253
+ If links have to be changed in a buld then it is easier to do so in a file and
254
+ when done updating the links from the file.
255
+
256
+ The links can be exported with
257
+
258
+ $ syclink export csv
259
+
260
+ This will print to the standard output. To save it to a file can be done as
261
+ follows
262
+
263
+ $ syclink export csv > my-links
264
+
265
+ Now we can edit the links in the file and when done updating them like so
266
+
267
+ $ sylinks update file my-links
268
+
269
+ Website Commands
270
+ ================
271
+
272
+ Show websites
128
273
  -------------
129
274
  The websites are saved to `~/.syc/syclink/websites/` and the html
130
275
  representations are saved to `~/.syc/syclink/html/`. When listing websites
131
276
  both _webstites_ and _html_ files are listed.
132
277
 
133
- The following command will list all websites
278
+ The following command will list all websites indicating the default website
134
279
 
135
- $ syclink website list
280
+ $ syclink website show
281
+ [default] ~/.syc/syclink/website/one.website
282
+ ~/.syc/syclink/website/two.website
136
283
 
137
284
  To list websites based on a search string the search string has to be send to
138
- the list command
285
+ the show command
139
286
 
140
- $ syclink website list "example"
287
+ $ syclink website show "example"
141
288
 
142
- If the `--exact` switch is given the command is only listing exact matches of
143
- the search string
289
+ If the `--exact` switch is given the command is listing exact matches of the
290
+ search string only
144
291
 
145
- $ syclink website list -e "http://example.com"
292
+ $ syclink website find -e "http://example.com"
146
293
 
147
294
  Remove websites
148
295
  ---------------
@@ -200,70 +347,7 @@ To create a website the steps are as follows
200
347
 
201
348
  Following is showing the above sequence in commands
202
349
 
203
- $ syclink -w example add "http://example.com" --tag EXAMPLE
204
- $ syclink add "http://github.com" --tag DEVELOPMENT
350
+ $ syclink -w example add link "http://example.com" --tag EXAMPLE
351
+ $ syclink add link "http://github.com" --tag DEVELOPMENT
205
352
  $ syclink website create
206
353
 
207
- Importing Bookmarks from Webrowsers
208
- ===================================
209
-
210
- Firefox
211
- -------
212
- The bookmarks of _Firefox_ are located in the user's home folder in
213
- `~/.mozilla/SOME_CRYPTIC_NAME.default/places.sqlite`.
214
-
215
- The database can be explored with _sqlite3_ from the command line
216
-
217
- $ cd ~/.mozilla/SOME_CRYPTIC_NAME.default/
218
- $ sqlite3 places.sqlite
219
- >
220
-
221
- We want to retrieve url, title, description, tag, key and bookmark. tag, key
222
- and bookmark are good candidates for tags for the application.
223
-
224
- At the command prompt of SQLite3 We can issue the query
225
-
226
- ````
227
- sqlite> select p.id, p.url, p.title, b.id, b.fk, b.parent, b.title,
228
- ...> k.keyword, a.content, b_t.title from moz_bookmarks b
229
- ...> left outer join moz_keywords k on b.keyword_id = k.id
230
- ...> left outer join moz_items_annos a on a.item_id = b.id
231
- ...> left outer join moz_bookmarks b_t on b.parent = b_t.id
232
- ...> join moz_places p on p.id = b.fk where p.url like "http%";
233
- 1|https://www.mozilla.org/en-US/firefox/central/||6|1|3|Getting Started|||\
234
- Bookmarks Toolbar
235
- 2|http://www.ubuntu.com/||8|2|7|Ubuntu|||Ubuntu and Free Software links
236
- 3|http://wiki.ubuntu.com/||9|3|7|Ubuntu Wiki (community-edited website)|||\
237
- Ubuntu and Free Software links
238
- 4|https://answers.launchpad.net/ubuntu/+addquestion||10|4|7|Make a Support \
239
- Request to the Ubuntu Community|||Ubuntu and Free Software links
240
- 5|http://www.debian.org/||11|5|7|Debian (Ubuntu is based on Debian)|||Ubuntu \
241
- and Free Software links
242
- 6|https://one.ubuntu.com/||12|6|7|Ubuntu One - The personal cloud that brings\
243
- your digital life together|||Ubuntu and Free Software links
244
- 7|https://www.mozilla.org/en-US/firefox/help/||14|7|13|Help and Tutorials|||\
245
- Mozilla Firefox
246
- 8|https://www.mozilla.org/en-US/firefox/customize/||15|8|13|Customize \
247
- Firefox|||Mozilla Firefox
248
- 9|https://www.mozilla.org/en-US/contribute/||16|9|13|Get Involved|||Mozilla \
249
- Firefox
250
- 10|https://www.mozilla.org/en-US/about/||17|10|13|About Us|||Mozilla Firefox
251
- 4717|http://codekata.com/|CodeKata|30|4717|5|CodeKata|liklo|How do you get \
252
- to be a great musician? It helps to know the theory,
253
- and to understand the mechanics of your instrument. It helps to have
254
- talent. But …|Unsorted Bookmarks
255
- 399|http://localhost:3000/|Secondhand | Home|34|399|2|Secondhand | Home|||\
256
- Bookmarks Menu
257
- 12870|https://www.sqlite.org/cli.html|Command Line Shell For SQLite|35|12870|\
258
- 5|Command Line Shell For SQLite|dark|What is this sqlite all about?|Unsorted \
259
- Bookmarks
260
- 4717|http://codekata.com/|CodeKata|37|4717|36||||wenga
261
- 12870|https://www.sqlite.org/cli.html|Command Line Shell For SQLite|39|12870|\
262
- 38||||lite
263
- 12883|http://ruby.bastardsbook.com/chapters/sql/#h-2-5|SQL | The Bastards \
264
- Book of Ruby|40|12883|5|SQL | The Bastards Book of Ruby|||Unsorted Bookmarks
265
- 12883|http://ruby.bastardsbook.com/chapters/sql/#h-2-5|SQL | The Bastards \
266
- Book of Ruby|42|12883|41||||Ruby
267
- sqlite>
268
- ````
269
-
data/bin/syclink CHANGED
@@ -20,7 +20,7 @@ WEBSITE_COMMANDS = [ :create, :link, :file, :update, :delete, :list, :find,
20
20
  # syclink's configuration directory
21
21
  syclink_directory = File.expand_path("~/.syc/syclink")
22
22
  # syclink's configuration file
23
- syclink_file = File.join(syclink_directory, "syclink.rc")
23
+ @syclink_file = File.join(syclink_directory, "syclink.rc")
24
24
  # syclink's template directory
25
25
  syclink_template_directory = File.join(syclink_directory, "templates/")
26
26
  # syclink's html template"
@@ -53,7 +53,7 @@ copy_file_if_missing(File.join(File.dirname(__FILE__),
53
53
  '../templates/stylesheets/style.css.scss'),
54
54
  syclink_stylesheets_directory)
55
55
 
56
- config = load_config(syclink_file)
56
+ config = load_config(@syclink_file)
57
57
 
58
58
  program_desc 'Create a link-list and display it as an html page'
59
59
 
@@ -228,7 +228,7 @@ end
228
228
 
229
229
  desc "Operate on websites"
230
230
  command :website do |c|
231
- c.desc 'Show all websites or search for websites'
231
+ c.desc 'Show all websites or search for websites with indication of default'
232
232
  c.arg_name 'WEBSITE'
233
233
  c.skips_pre
234
234
  c.skips_post
@@ -238,10 +238,18 @@ command :website do |c|
238
238
  s.switch [:e, :exact]
239
239
 
240
240
  s.action do |global_options,options,args|
241
- if options[:e]
242
- puts Dir.glob(yaml_file(syclink_website_directory, args[0]))
241
+ websites = if options[:e]
242
+ Dir.glob(yaml_file(syclink_website_directory, args[0]))
243
243
  else
244
- puts Dir.glob(File.join(syclink_website_directory, "*.website"))
244
+ Dir.glob(File.join(syclink_website_directory, "*.website"))
245
+ end
246
+
247
+ websites.each do |f|
248
+ if File.basename(f) =~ /#{config[:default_website]}\.website/
249
+ puts "[default] #{f}"
250
+ else
251
+ puts " #{f}"
252
+ end
245
253
  end
246
254
  end
247
255
  end
@@ -332,6 +340,16 @@ command :import do |c|
332
340
  c.arg_name 'PATH_TO_INTERNET_EXPLORER_BOOKMARKS'
333
341
  c.command :ie do |s|
334
342
 
343
+ s.desc 'Number of tags to consider'
344
+ s.long_desc <<-HERE.gsub(/^ {6}/, '')
345
+ Each parent directory starting at the PATH_TO_INTERNET_EXPLORER_BOOKMARKS
346
+ is considered a tag. If no level flag is specified all tags are imported.
347
+ Otherwise only the count of tags are imported that are specified by the
348
+ level flag. A level of 0 will import no tags.
349
+ HERE
350
+ s.arg_name 'LEVEL 0..N'
351
+ s.flag [:l, :level], :type => Integer
352
+
335
353
  s.action do |global_options,options,args|
336
354
  unless File.exists? args[0]
337
355
  STDERR.puts <<-HERE.gsub(/^ {10}/, '')
@@ -342,7 +360,8 @@ command :import do |c|
342
360
  HERE
343
361
  exit(0)
344
362
  else
345
- @designer.import_links(SycLink::InternetExplorer.new(args.shift))
363
+ @designer.import_links(SycLink::InternetExplorer.new(args.shift,
364
+ options))
346
365
  end
347
366
  end
348
367
  end
@@ -363,8 +382,19 @@ command :import do |c|
363
382
  c.arg_name 'PATH_TO_DIRECTORY'
364
383
  c.command :dir do |s|
365
384
 
385
+ s.desc 'Number of tags to consider'
386
+ s.long_desc <<-HERE.gsub(/^ {6}/, '')
387
+ Each parent directory starting at the PATH_TO_DIRECTORY is considered a
388
+ tag. If no level flag is specified all tags are imported. Otherwise only
389
+ the count of tags are imported that are specified by the level flag. A
390
+ level of 0 will import no tags.
391
+ HERE
392
+ s.arg_name 'LEVEL 0..N'
393
+ s.flag [:l, :level], :type => Integer
394
+
366
395
  s.action do |global_options,options,args|
367
- @designer.import_links(SycLink::FileImporter.new(args.shift))
396
+ @designer.import_links(SycLink::FileImporter.new(args.shift,
397
+ options))
368
398
  end
369
399
  end
370
400
  end
@@ -391,25 +421,19 @@ pre do |global,command,options,args|
391
421
  if File.exists? yaml_file(syclink_website_directory, global[:website])
392
422
  @designer.load_website(yaml_file(syclink_website_directory,
393
423
  global[:website]))
424
+
425
+ set_default_website(global[:website], config[:default_website])
426
+
394
427
  else
395
- print "Website #{global[:website]} doesn't exist. Create it (y/n)? "
428
+ print "Website '#{global[:website]}' doesn't exist. Create it (y/n)? "
396
429
  if STDIN.gets.chomp =~ /y/i
397
- puts; puts "Creating #{global[:website]}"
430
+ puts; puts "Creating '#{global[:website]}'"
398
431
  @designer.new_website(global[:website])
399
432
  else
400
433
  exit(0)
401
434
  end
402
435
 
403
- if (global[:website] != config[:default_website])
404
- print "Want to make #{global[:website]} the default (y/n)? "
405
- if STDIN.gets.chomp =~ /y/i
406
- puts; puts "Making #{global[:website]} the default website"
407
- File.open(syclink_file, 'w') do |f|
408
- YAML.dump({ default_website: global[:website] }, f)
409
- end
410
- end
411
- end
412
-
436
+ set_default_website(global[:website], config[:default_website])
413
437
  end
414
438
 
415
439
  end
@@ -431,6 +455,21 @@ on_error do |exception|
431
455
  end
432
456
  end
433
457
 
458
+ # If current website and default website are different ask whether current
459
+ # website should be set as default website
460
+ def set_default_website(current, default)
461
+ if (current != default)
462
+ print "Want to make '#{current}' the default (y/n)? "
463
+ if STDIN.gets.chomp =~ /y/i
464
+ puts; puts "Making '#{current}' the default website"
465
+ File.open(@syclink_file, 'w') do |f|
466
+ YAML.dump({ default_website: current }, f)
467
+ end
468
+ end
469
+ end
470
+ end
471
+
472
+ # Print links in table format
434
473
  def print_links(links, columns, opts = {})
435
474
  allowed_cols = %w{ url name description tag }
436
475
  cols = columns.delete(' ').downcase.split(',') & allowed_cols
@@ -6,12 +6,17 @@ module SycLink
6
6
  root_dir = File.dirname(path).scan(/^[^\*|\?]*/).first
7
7
  regex = Regexp.new("(?<=#{root_dir}).*")
8
8
  Dir.glob(path).map do |file|
9
- url = file
10
- name = File.basename(file)
9
+ next if File.directory? file
10
+ url, name = if File.extname(file).upcase == ".URL"
11
+ [File.read(file).scan(/(?<=\nURL=)(.*)$/).flatten.first,
12
+ name = File.basename(file, ".*")]
13
+ else
14
+ [file, File.basename(file)]
15
+ end
11
16
  description = ""
12
17
  tags = extract_tags(File.dirname(file).scan(regex))
13
18
  [url, name, description, tags]
14
- end
19
+ end.compact
15
20
  end
16
21
 
17
22
  end
@@ -49,7 +49,7 @@ module SycLink
49
49
  # Creates a formatter string based on the widths and the column separator
50
50
  def formatter_string(widhts, separator)
51
51
  widhts.map do |width|
52
- "%-#{width}s"
52
+ "%-#{width}.#{width}s"
53
53
  end.join(separator)
54
54
  end
55
55
 
@@ -8,10 +8,14 @@ module SycLink
8
8
 
9
9
  # Path to bookmarks file
10
10
  attr_accessor :path
11
+ # Options for importing
12
+ attr_accessor :opts
11
13
 
12
- # Creates a new Importer and sets the path to the bookmarks file
13
- def initialize(path_to_bookmarks)
14
+ # Creates a new Importer and sets the path to the bookmarks file. Opts may
15
+ # be :level which indicates to which levels tags should be imported.
16
+ def initialize(path_to_bookmarks, opts = {})
14
17
  @path = path_to_bookmarks
18
+ @opts = opts
15
19
  end
16
20
 
17
21
  # To be overridden!
@@ -37,11 +41,16 @@ module SycLink
37
41
 
38
42
  protected
39
43
 
44
+ # Extracts the tags from a tag string. If a level is provided during
45
+ # initialization the level is restricting the count of tags imported based
46
+ # on the level value
40
47
  def extract_tags(tag_string)
41
- if tag_string.empty?
42
- ""
48
+ if tag_string.empty? || opts[:level] == 0
49
+ "Default"
43
50
  else
44
- tag_string.first.gsub("/", ",")
51
+ tags = tag_string.first.split('/')
52
+ level = [opts[:level] || tags.size, tags.size].min
53
+ tags[-level..-1].join(',')
45
54
  end
46
55
  end
47
56
  end
@@ -13,9 +13,9 @@ module SycLink
13
13
  regex = Regexp.new("(?<=#{path}).*")
14
14
 
15
15
  files.map do |file|
16
- unless File.directory? file
16
+ unless ((File.directory? file) || (File.extname(file).upcase != ".URL"))
17
17
  url = File.read(file).scan(/(?<=\nURL=)(.*)$/).flatten.first
18
- name = File.basename(file)
18
+ name = File.basename(file, ".*")
19
19
  description = ""
20
20
  tag = extract_tags(File.dirname(file).scan(regex))
21
21
  [url, name, description, tag]
@@ -2,6 +2,6 @@
2
2
  module SycLink
3
3
 
4
4
  # Version of the application
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
6
 
7
7
  end
@@ -65,13 +65,21 @@ module SycLink
65
65
  end
66
66
  end
67
67
 
68
- # Groups the links on the provided attribute
69
- def links_group_by(attribute)
70
- links.map { |link| { key: link.send(attribute), link: link } }
68
+ # Groups the links on the provided attribute. If no links array is provided
69
+ # the links from self are used
70
+ def links_group_by(attribute, linkz = links)
71
+ linkz.map { |link| { key: link.send(attribute), link: link } }
71
72
  .group_by { |entry| entry[:key] }
72
73
  .each { |key, link| link.map! { |l| l[:link] }}
73
74
  end
74
75
 
76
+ # Groups the links on the provided attribute. If the attribute's value
77
+ # contains the provided separator, the value is split up and each of the
78
+ # values is used as group key
79
+ def links_group_by_separated(attribute, separator)
80
+ links_group_by(attribute, links_duplicate_on(attribute, separator))
81
+ end
82
+
75
83
  # Create multiple Links based on the attribute provided. The specified
76
84
  # spearator will splitt the attribute value in distinct values and for each
77
85
  # different value a Link will be created
@@ -89,8 +97,8 @@ module SycLink
89
97
  end
90
98
 
91
99
  # List all attributes of the links
92
- def link_attribute_list(attribute)
93
- links.map { |link| link.send(attribute) }.uniq.sort
100
+ def link_attribute_list(attribute, separator = nil)
101
+ links.map {|link| link.send(attribute).split(separator)}.flatten.uniq.sort
94
102
  end
95
103
  end
96
104
 
@@ -25,7 +25,7 @@ module SycLink
25
25
  @scaled_widths = [ 7, 6, 6, 7 ]
26
26
  @expanded_widths = [ 13, 12, 12, 13 ]
27
27
 
28
- @formatter = "%-8s | %-7s | %-7s | %-8s"
28
+ @formatter = "%-8.8s | %-7.7s | %-7.7s | %-8.8s"
29
29
  end
30
30
 
31
31
  it "should transform the rows to columns" do
@@ -0,0 +1,7 @@
1
+ [DEFAULT]
2
+ BASEURL=http://www.example.com/base
3
+ [InternetShortcut]
4
+ URL=http://www.example.com/
5
+ IDList=
6
+ [{000214A0-0000-0000-C000-000000000046}]
7
+ Prop3=19,2
@@ -39,9 +39,9 @@ module SycLink
39
39
 
40
40
  before do
41
41
  ie_directory = File.join(File.dirname(__FILE__), 'ie/')
42
- @result = [ [ "http://www.example.com/", "ie.txt", "", "one" ],
43
- [ "http://www.example.com/", "ie.txt", "", "one,two"],
44
- [ "http://www.example.com/", "ie.txt", "", ""] ]
42
+ @result = [ [ "http://www.example.com/", "ie", "", "one" ],
43
+ [ "http://www.example.com/", "ie", "", "one,two"],
44
+ [ "http://www.example.com/", "ie", "", "Default"] ]
45
45
 
46
46
  @ie = InternetExplorer.new(ie_directory)
47
47
  end
@@ -115,9 +115,41 @@ module SycLink
115
115
  ["/home/pierre/Work/syclink/spec/syclink/fi/a/two.pdf",
116
116
  "two.pdf", "", "a"],
117
117
  ["/home/pierre/Work/syclink/spec/syclink/fi/one.pdf",
118
- "one.pdf", "", ""]]
118
+ "one.pdf", "", "Default"]]
119
+ @pdf_zero = [["/home/pierre/Work/syclink/spec/syclink/fi/b/three.pdf",
120
+ "three.pdf", "", "Default"],
121
+ ["/home/pierre/Work/syclink/spec/syclink/fi/b/a/four.pdf",
122
+ "four.pdf", "", "Default"],
123
+ ["/home/pierre/Work/syclink/spec/syclink/fi/a/two.pdf",
124
+ "two.pdf", "", "Default"],
125
+ ["/home/pierre/Work/syclink/spec/syclink/fi/one.pdf",
126
+ "one.pdf", "", "Default"]]
119
127
  @txt_files = [["/home/pierre/Work/syclink/spec/syclink/fi/a.txt",
120
128
  "a.txt", "", ""]]
129
+ @any_files = [["/home/pierre/Work/syclink/spec/syclink/fi/b/three.pdf",
130
+ "three.pdf", "", "b"],
131
+ ["/home/pierre/Work/syclink/spec/syclink/fi/b/a/four.pdf",
132
+ "four.pdf", "", "b,a"],
133
+ ["/home/pierre/Work/syclink/spec/syclink/fi/a/two.pdf",
134
+ "two.pdf", "", "a"],
135
+ ["/home/pierre/Work/syclink/spec/syclink/fi/a.txt",
136
+ "a.txt", "", "Default"],
137
+ ["/home/pierre/Work/syclink/spec/syclink/fi/one.pdf",
138
+ "one.pdf", "", "Default"],
139
+ ["http://www.example.com/",
140
+ "ie", "", "c"]]
141
+ @any_level = [["/home/pierre/Work/syclink/spec/syclink/fi/b/three.pdf",
142
+ "three.pdf", "", "b"],
143
+ ["/home/pierre/Work/syclink/spec/syclink/fi/b/a/four.pdf",
144
+ "four.pdf", "", "a"],
145
+ ["/home/pierre/Work/syclink/spec/syclink/fi/a/two.pdf",
146
+ "two.pdf", "", "a"],
147
+ ["/home/pierre/Work/syclink/spec/syclink/fi/a.txt",
148
+ "a.txt", "", "Default"],
149
+ ["/home/pierre/Work/syclink/spec/syclink/fi/one.pdf",
150
+ "one.pdf", "", "Default"],
151
+ ["http://www.example.com/",
152
+ "ie", "", "c"]]
121
153
  end
122
154
 
123
155
  it "should import pdf filenames" do
@@ -130,12 +162,17 @@ module SycLink
130
162
  expect(fi.read).to eq @txt_files
131
163
  end
132
164
 
133
- it "should read rows" do
165
+ it "should import any file" do
166
+ fi = FileImporter.new(File.join(@file_dir, "**/*"))
167
+ expect(fi.read).to eq @any_files
168
+ end
169
+
170
+ it "should read rows from pdf" do
134
171
  fi = FileImporter.new(File.join(@file_dir, "**/*.pdf"))
135
172
  expect(fi.rows).to eq @pdf_files
136
173
  end
137
174
 
138
- it "should create links" do
175
+ it "should create links from pdf" do
139
176
  fi = FileImporter.new(File.join(@file_dir, "**/*.pdf"))
140
177
  links = fi.links
141
178
 
@@ -144,6 +181,16 @@ module SycLink
144
181
  expect(links.first.description).to eq @pdf_files.first[2]
145
182
  expect(links.first.tag).to eq @pdf_files.first[3]
146
183
  end
184
+
185
+ it "should use only the parent directory as the tag" do
186
+ fi = FileImporter.new(File.join(@file_dir, "**/*"), level: 1)
187
+ expect(fi.read).to eq @any_level
188
+ end
189
+
190
+ it "should not import tags" do
191
+ fi = FileImporter.new(File.join(@file_dir, "**/*.pdf"), level: 0)
192
+ expect(fi.read).to eq @pdf_zero
193
+ end
147
194
  end
148
195
 
149
196
  end
@@ -109,6 +109,12 @@ module SycLink
109
109
  expect(links.first.tag).to eq "One"
110
110
  end
111
111
 
112
+ it "should group links on tags and separated multiple tags" do
113
+ @website.add_link(@link)
114
+ @website.add_link(@link4)
115
+ expect(@website.links_group_by_separated(:tag, ',').size).to eq 3
116
+ end
117
+
112
118
  it "should list all tags" do
113
119
  @website.add_link(@link)
114
120
  @website.add_link(@link)
@@ -116,6 +122,12 @@ module SycLink
116
122
  expect(@website.link_attribute_list(:tag)).to eq target
117
123
  end
118
124
 
125
+ it "should list allt tags and multiple tags separated to single tags" do
126
+ @website.add_link(@link)
127
+ @website.add_link(@link4)
128
+ target = [@link.tag, @link4.tag.split(',')].flatten.sort
129
+ expect(@website.link_attribute_list(:tag, ',')).to eq target
130
+ end
119
131
  end
120
132
 
121
133
  end
@@ -12,7 +12,7 @@
12
12
  </header>
13
13
  <div class="container">
14
14
  <section id="tags">
15
- <% links_group_by(:tag).each do |tag, links| %>
15
+ <% links_group_by_separated(:tag, ',').each do |tag, links| %>
16
16
  <article class="tag">
17
17
  <header>
18
18
  <h2 id="tag_<%= tag %>"><%= tag %></h2>
@@ -41,7 +41,7 @@
41
41
  <h2>Tags</h2>
42
42
  </header>
43
43
  <ul>
44
- <% link_attribute_list(:tag).each do |tag| %>
44
+ <% link_attribute_list(:tag, ',').each do |tag| %>
45
45
  <li><a href="#tag_<%= tag %>"><%= tag %></a>
46
46
  <% end %>
47
47
  </ul>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syclink
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Sugar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-14 00:00:00.000000000 Z
11
+ date: 2015-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -173,12 +173,13 @@ files:
173
173
  - spec/syclink/fi/a/two.pdf
174
174
  - spec/syclink/fi/b/a/four.pdf
175
175
  - spec/syclink/fi/b/three.pdf
176
+ - spec/syclink/fi/c/ie.url
176
177
  - spec/syclink/fi/one.pdf
177
178
  - spec/syclink/formatter_spec.rb
178
179
  - spec/syclink/gc/Bookmarks
179
- - spec/syclink/ie/ie.txt
180
- - spec/syclink/ie/one/ie.txt
181
- - spec/syclink/ie/one/two/ie.txt
180
+ - spec/syclink/ie/ie.url
181
+ - spec/syclink/ie/one/ie.url
182
+ - spec/syclink/ie/one/two/ie.url
182
183
  - spec/syclink/importer_spec.rb
183
184
  - spec/syclink/link_spec.rb
184
185
  - spec/syclink/website_spec.rb
File without changes
File without changes
File without changes