citeproc-js 0.0.1.pre.1 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/citeproc-js.gemspec +1 -1
- data/lib/citeproc/js.rb +5 -2
- data/lib/citeproc/js/assets.rb +68 -0
- data/lib/citeproc/js/engine.rb +13 -1
- data/lib/citeproc/js/version.rb +1 -1
- data/spec/citeproc/js/assets_spec.rb +55 -0
- data/spec/citeproc/js/engine_spec.rb +27 -4
- metadata +127 -118
data/citeproc-js.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.license = 'AGPLv3'
|
17
17
|
|
18
18
|
s.add_runtime_dependency('citeproc', ['~>0.0'])
|
19
|
-
s.add_runtime_dependency('execjs', ['
|
19
|
+
s.add_runtime_dependency('execjs', ['>=1.2.4', '<1.3.0'])
|
20
20
|
|
21
21
|
s.add_development_dependency('cucumber', ['>=1.0.2'])
|
22
22
|
s.add_development_dependency('rspec', ['>=2.6.0'])
|
data/lib/citeproc/js.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
|
2
2
|
ENV['EXECJS_RUNTIME'] = 'RubyRhino'
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
if ENV['DEBUG']
|
5
|
+
require 'ruby-debug'
|
6
|
+
Debugger.start
|
7
|
+
end
|
6
8
|
|
7
9
|
require 'citeproc'
|
8
10
|
|
9
11
|
require 'citeproc/js/version'
|
12
|
+
require 'citeproc/js/assets'
|
10
13
|
require 'citeproc/js/engine'
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module CiteProc
|
4
|
+
module JS
|
5
|
+
module Asset
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.extend(ClassMethods)
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :asset
|
12
|
+
|
13
|
+
alias to_s asset
|
14
|
+
|
15
|
+
def inspect
|
16
|
+
to_s.inspect
|
17
|
+
end
|
18
|
+
|
19
|
+
module ClassMethods
|
20
|
+
|
21
|
+
attr_accessor :root, :extension, :prefix
|
22
|
+
|
23
|
+
def load(asset)
|
24
|
+
instance = new
|
25
|
+
case
|
26
|
+
when File.exists?(asset)
|
27
|
+
instance.asset = read(asset)
|
28
|
+
when File.exists?(File.join(root.to_s, extend_name(asset)))
|
29
|
+
instance.asset = read(File.join(root.to_s, extend_name(asset)))
|
30
|
+
else
|
31
|
+
instance.asset = asset
|
32
|
+
end
|
33
|
+
instance
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def read(name)
|
39
|
+
io = open(name, 'r:UTF-8')
|
40
|
+
io.read
|
41
|
+
ensure
|
42
|
+
io.close
|
43
|
+
end
|
44
|
+
|
45
|
+
def extend_name(file)
|
46
|
+
file = File.extname(file).empty? ? [file, extension].compact.join('.') : file
|
47
|
+
file = file.start_with?(prefix.to_s) ? file : [prefix,file].join
|
48
|
+
file
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
class Style
|
55
|
+
include Asset
|
56
|
+
@root = '/usr/local/share/citation-style-language/styles'.freeze
|
57
|
+
@extension = 'csl'.freeze
|
58
|
+
end
|
59
|
+
|
60
|
+
class Locale
|
61
|
+
include Asset
|
62
|
+
@root = '/usr/local/share/citation-style-language/locales'.freeze
|
63
|
+
@extension = 'xml'.freeze
|
64
|
+
@prefix = 'locales-'
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
data/lib/citeproc/js/engine.rb
CHANGED
@@ -63,10 +63,18 @@ module CiteProc
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
|
66
|
+
|
67
67
|
#
|
68
68
|
# instance methods
|
69
69
|
#
|
70
|
+
|
71
|
+
def style=(style)
|
72
|
+
@style = Style.load(style.to_s)
|
73
|
+
end
|
74
|
+
|
75
|
+
def locales=(locale)
|
76
|
+
@locales = { locale.to_sym => Locale.load(locale.to_s) }
|
77
|
+
end
|
70
78
|
|
71
79
|
attr_context :processor_version, :csl_version, :opt
|
72
80
|
|
@@ -99,8 +107,12 @@ module CiteProc
|
|
99
107
|
return if started?
|
100
108
|
super
|
101
109
|
|
110
|
+
self.style = processor.options[:style] if @style.nil?
|
111
|
+
self.locales = processor.options[:locale] if @locales.nil?
|
112
|
+
|
102
113
|
@context = ExecJS.compile(Engine.source)
|
103
114
|
update_system
|
115
|
+
|
104
116
|
delegate "citeproc = new CSL.Engine(system, #{style.inspect}, #{language.inspect})", :exec
|
105
117
|
set_output_format(options[:format])
|
106
118
|
|
data/lib/citeproc/js/version.rb
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
module CiteProc
|
5
|
+
module JS
|
6
|
+
|
7
|
+
describe 'Assets' do
|
8
|
+
let(:file) { Tempfile.new('asset') }
|
9
|
+
let(:root) { File.dirname(file.path) }
|
10
|
+
let(:name) { File.basename(file.path) }
|
11
|
+
let(:extension) { File.extname(name) }
|
12
|
+
|
13
|
+
before(:all) do
|
14
|
+
file.write("asset content\n")
|
15
|
+
file.close
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:all) { file.unlink }
|
19
|
+
|
20
|
+
describe 'Style' do
|
21
|
+
|
22
|
+
before(:all) do
|
23
|
+
Style.root = root
|
24
|
+
Style.extension = extension
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '.load' do
|
28
|
+
|
29
|
+
it 'accepts an absolute file name' do
|
30
|
+
Style.load(file.path).to_s.should == "asset content\n"
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'accepts a file name' do
|
34
|
+
Style.load(name).to_s.should == "asset content\n"
|
35
|
+
end
|
36
|
+
|
37
|
+
# it 'accepts a file name without extension' do
|
38
|
+
# Style.load(name.sub(/#{extension}$/,'')).to_s.should == "asset content\n"
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
#
|
42
|
+
# it 'accepts a uri' do
|
43
|
+
# pending
|
44
|
+
# end
|
45
|
+
|
46
|
+
it 'returns the given string if it is neither file nor uri' do
|
47
|
+
Style.load('foo bar!').to_s.should == 'foo bar!'
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -3,20 +3,38 @@ require 'spec_helper'
|
|
3
3
|
module CiteProc
|
4
4
|
module JS
|
5
5
|
describe 'Engine' do
|
6
|
-
|
6
|
+
before(:all) do
|
7
|
+
Style.root = File.expand_path('../../../fixtures/styles', __FILE__)
|
8
|
+
Locale.root = File.expand_path('../../../fixtures/locales', __FILE__)
|
9
|
+
end
|
10
|
+
|
7
11
|
let(:subject) do
|
8
12
|
Engine.new do |e|
|
9
13
|
p = double(:processor)
|
10
14
|
p.stub(:options).and_return { Processor.defaults }
|
11
15
|
p.stub(:items).and_return { load_items('items') }
|
12
16
|
e.processor = p
|
13
|
-
e.style = load_style('apa')
|
14
|
-
e.locales = { :'en-US' => load_locale('en-US') }
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
20
|
it { should_not be nil }
|
19
21
|
|
22
|
+
describe '#style' do
|
23
|
+
let(:apa) { load_style('apa') }
|
24
|
+
it 'accepts a style name' do
|
25
|
+
subject.style = :apa
|
26
|
+
subject.style.to_s.should == apa
|
27
|
+
end
|
28
|
+
it 'accepts a style name with extension' do
|
29
|
+
subject.style = 'apa.csl'
|
30
|
+
subject.style.to_s.should == apa
|
31
|
+
end
|
32
|
+
it 'accepts a full style' do
|
33
|
+
subject.style = apa
|
34
|
+
subject.style.to_s.should == apa
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
20
38
|
describe '#version' do
|
21
39
|
it 'returns a 1.x version string' do
|
22
40
|
subject.version.should =~ /^1\.[\d\.]+/
|
@@ -36,7 +54,12 @@ module CiteProc
|
|
36
54
|
end
|
37
55
|
|
38
56
|
context 'when started' do
|
39
|
-
before(:each)
|
57
|
+
before(:each) do
|
58
|
+
subject.style = :apa
|
59
|
+
subject.locales = :'en-US'
|
60
|
+
subject.start
|
61
|
+
end
|
62
|
+
|
40
63
|
after(:each) { subject.stop }
|
41
64
|
|
42
65
|
describe '#processor_version' do
|
metadata
CHANGED
@@ -1,136 +1,145 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: citeproc-js
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
- Sylvester Keil
|
7
|
+
authors:
|
8
|
+
- Sylvester Keil
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
12
|
+
|
13
|
+
date: 2011-08-08 00:00:00 +02:00
|
13
14
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
-
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: citeproc
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0.0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: execjs
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 1.2.4
|
36
|
+
- - <
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 1.3.0
|
39
|
+
type: :runtime
|
40
|
+
version_requirements: *id002
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: cucumber
|
43
|
+
prerelease: false
|
44
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.0.2
|
50
|
+
type: :development
|
51
|
+
version_requirements: *id003
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: rspec
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.6.0
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id004
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: watchr
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0.7"
|
72
|
+
type: :development
|
73
|
+
version_requirements: *id005
|
74
|
+
description: A citeproc engine based on the citeproc-js CSL (Citation Style Language) processor.
|
75
|
+
email:
|
76
|
+
- http://sylvester.keil.or.at
|
74
77
|
executables: []
|
78
|
+
|
75
79
|
extensions: []
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
- .
|
81
|
-
-
|
82
|
-
-
|
83
|
-
-
|
84
|
-
-
|
85
|
-
-
|
86
|
-
-
|
87
|
-
- lib/citeproc/js
|
88
|
-
- lib/citeproc/js/
|
89
|
-
- lib/citeproc/js/
|
90
|
-
- lib/citeproc/js/support/
|
91
|
-
- lib/citeproc/js/support/
|
92
|
-
- lib/citeproc/js/
|
93
|
-
-
|
94
|
-
-
|
95
|
-
- spec/
|
96
|
-
- spec/
|
97
|
-
- spec/
|
80
|
+
|
81
|
+
extra_rdoc_files:
|
82
|
+
- README.md
|
83
|
+
files:
|
84
|
+
- .gitignore
|
85
|
+
- .rspec
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE
|
88
|
+
- README.md
|
89
|
+
- auto.watchr
|
90
|
+
- citeproc-js.gemspec
|
91
|
+
- lib/citeproc/js.rb
|
92
|
+
- lib/citeproc/js/assets.rb
|
93
|
+
- lib/citeproc/js/engine.rb
|
94
|
+
- lib/citeproc/js/support/citeproc.js
|
95
|
+
- lib/citeproc/js/support/system.js
|
96
|
+
- lib/citeproc/js/support/xmldom.js
|
97
|
+
- lib/citeproc/js/support/xmle4x.js
|
98
|
+
- lib/citeproc/js/version.rb
|
99
|
+
- spec/citeproc/js/assets_spec.rb
|
100
|
+
- spec/citeproc/js/engine_spec.rb
|
101
|
+
- spec/fixtures/items/items.json
|
102
|
+
- spec/fixtures/locales/locales-en-US.xml
|
103
|
+
- spec/fixtures/styles/apa.csl
|
104
|
+
- spec/spec_helper.rb
|
98
105
|
has_rdoc: true
|
99
106
|
homepage: http://inukshuk.github.com/citeproc-js
|
100
|
-
licenses:
|
101
|
-
- AGPLv3
|
107
|
+
licenses:
|
108
|
+
- AGPLv3
|
102
109
|
post_install_message:
|
103
|
-
rdoc_options:
|
104
|
-
- --line-numbers
|
105
|
-
- --inline-source
|
106
|
-
- --title
|
107
|
-
-
|
108
|
-
- --main
|
109
|
-
- README.md
|
110
|
-
- --webcvs=http://github.com/inukshuk/citeproc-js/tree/master/
|
111
|
-
require_paths:
|
112
|
-
- lib
|
113
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
rdoc_options:
|
111
|
+
- --line-numbers
|
112
|
+
- --inline-source
|
113
|
+
- --title
|
114
|
+
- "\"CiteProc-JS Rubygem\""
|
115
|
+
- --main
|
116
|
+
- README.md
|
117
|
+
- --webcvs=http://github.com/inukshuk/citeproc-js/tree/master/
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
121
|
none: false
|
115
|
-
requirements:
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: "0"
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
127
|
none: false
|
121
|
-
requirements:
|
122
|
-
|
123
|
-
|
124
|
-
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: "0"
|
125
132
|
requirements: []
|
133
|
+
|
126
134
|
rubyforge_project:
|
127
|
-
rubygems_version: 1.
|
135
|
+
rubygems_version: 1.5.1
|
128
136
|
signing_key:
|
129
137
|
specification_version: 3
|
130
138
|
summary: A citeproc engine based on citeproc-js.
|
131
|
-
test_files:
|
132
|
-
- spec/citeproc/js/
|
133
|
-
- spec/
|
134
|
-
- spec/fixtures/
|
135
|
-
- spec/fixtures/
|
136
|
-
- spec/
|
139
|
+
test_files:
|
140
|
+
- spec/citeproc/js/assets_spec.rb
|
141
|
+
- spec/citeproc/js/engine_spec.rb
|
142
|
+
- spec/fixtures/items/items.json
|
143
|
+
- spec/fixtures/locales/locales-en-US.xml
|
144
|
+
- spec/fixtures/styles/apa.csl
|
145
|
+
- spec/spec_helper.rb
|