Skip to content

Commit 98d1db7

Browse files
committed
added list
Not a perfect implementation, this might change in the future
1 parent ca5092a commit 98d1db7

File tree

4 files changed

+46
-214
lines changed

4 files changed

+46
-214
lines changed

src/parser-short-old.rb

Lines changed: 0 additions & 207 deletions
This file was deleted.

src/parser-short.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
require 'json'
22
require_relative './reference.rb'
33

4+
# TODO: warn when two references have the same citation and potentially add (year[a-z]) and/or expand the reference.
5+
46
# # Short references
57
# [#5!] = Ward and Ramachandran (2010, December)
68
# [#5] = (Ward & Ramachandran 2010, December)

template-engine/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ The second time it appears in the same text:
4242
Belleflamme et al. (2014) states that crowdfunding involves a general request for money ...
4343
```
4444

45+
### Listing references
46+
```bash
47+
refst list path/to/file
48+
```
49+
50+
This will list all references in a text.
51+
4552
## A note from the author
4653
The citation style is based on the recommendations of Ghent University.
4754
This is because this tool was created for my own master thesis. Feel free to fork the project if your project requires a different style.

template-engine/src/engine.rb

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# © Jonas Everaert 2022
66
#
77
# USAGE:
8-
# refst <input>
8+
# refst [subcommand] <input>
99
#
1010
# ARGS:
1111
# <input> is either a file path, or a string
@@ -14,12 +14,17 @@
1414
# -h Prints this help information
1515
# -v, --version Prints the version of the cli
1616
# -p Sets a custom path for the refs cli
17+
#
18+
# SUBCOMMANDS:
19+
# list <input> List the references from the input
1720
#
18-
# ENVIRONMENT VARIABLES
21+
# ENVIRONMENT VARIABLES:
1922
# STREAM=true Can be set to false to output the file in one go
2023
# instead of as a stream
24+
#
2125

2226
require_relative '../../src/parser-short.rb'
27+
require 'set'
2328

2429
VERSION = "0.0.1"
2530

@@ -179,7 +184,7 @@ def replace_matches_multiple(line, match)
179184
numbers = numbers.split('&')
180185
short_refs = ""
181186
numbers.each_with_index do |number, idx|
182-
short_ref = @parser.parsePar(number, !@refs_used.key?(number))
187+
short_ref = @parser.parse(number, !@refs_used.key?(number))
183188
if not @refs_used.key?(number)
184189
@refs_used[number] = true
185190
end
@@ -228,6 +233,20 @@ def replace_matches_multiple_par(line, match)
228233
end
229234
end
230235

236+
def listReferences(input)
237+
re = /\[#(?<id>\d+)\!?\]/
238+
match = input.scan re
239+
list = Set.new
240+
match.each do |id_arr|
241+
id = id_arr[0]
242+
list << id
243+
end
244+
245+
list.each do |id|
246+
puts `refs -i #{id}`
247+
end
248+
end
249+
231250
# Reference match
232251
# type
233252
# string
@@ -239,10 +258,21 @@ def replace_matches_multiple_par(line, match)
239258
else
240259
true
241260
end
242-
243-
if stream
244-
CLI.new(ARGV).execute(stream)
261+
262+
if ARGV[0] == "list"
263+
input = begin
264+
File.read(ARGV[1])
265+
rescue Errno::ENOENT
266+
ARGV[1]
267+
end
268+
269+
listReferences(input)
245270
else
246-
puts CLI.new(ARGV).execute(stream)
271+
272+
if stream
273+
CLI.new(ARGV).execute(stream)
274+
else
275+
puts CLI.new(ARGV).execute(stream)
276+
end
247277
end
248278
end

0 commit comments

Comments
 (0)