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.
@@ -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', ['~>1.2.3'])
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'])
@@ -1,10 +1,13 @@
1
1
 
2
2
  ENV['EXECJS_RUNTIME'] = 'RubyRhino'
3
3
 
4
- require 'ruby-debug'
5
- Debugger.start
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
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  module CiteProc
2
2
  module JS
3
- VERSION = '0.0.1.pre.1'.freeze
3
+ VERSION = '0.0.1'.freeze
4
4
  end
5
5
  end
@@ -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) { subject.start }
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
- version: 0.0.1.pre.1
5
- prerelease: 6
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
- date: 2011-08-03 00:00:00.000000000 +02:00
12
+
13
+ date: 2011-08-08 00:00:00 +02:00
13
14
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: citeproc
17
- requirement: &2157316160 !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - ~>
21
- - !ruby/object:Gem::Version
22
- version: '0.0'
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: *2157316160
26
- - !ruby/object:Gem::Dependency
27
- name: execjs
28
- requirement: &2157315600 !ruby/object:Gem::Requirement
29
- none: false
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: 1.2.3
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: *2157315600
37
- - !ruby/object:Gem::Dependency
38
- name: cucumber
39
- requirement: &2157315120 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ! '>='
43
- - !ruby/object:Gem::Version
44
- version: 1.0.2
45
- type: :development
46
- prerelease: false
47
- version_requirements: *2157315120
48
- - !ruby/object:Gem::Dependency
49
- name: rspec
50
- requirement: &2157314620 !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
53
- - - ! '>='
54
- - !ruby/object:Gem::Version
55
- version: 2.6.0
56
- type: :development
57
- prerelease: false
58
- version_requirements: *2157314620
59
- - !ruby/object:Gem::Dependency
60
- name: watchr
61
- requirement: &2157314140 !ruby/object:Gem::Requirement
62
- none: false
63
- requirements:
64
- - - ! '>='
65
- - !ruby/object:Gem::Version
66
- version: '0.7'
67
- type: :development
68
- prerelease: false
69
- version_requirements: *2157314140
70
- description: A citeproc engine based on the citeproc-js CSL (Citation Style Language)
71
- processor.
72
- email:
73
- - http://sylvester.keil.or.at
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
- extra_rdoc_files:
77
- - README.md
78
- files:
79
- - .gitignore
80
- - .rspec
81
- - Gemfile
82
- - LICENSE
83
- - README.md
84
- - auto.watchr
85
- - citeproc-js.gemspec
86
- - lib/citeproc/js.rb
87
- - lib/citeproc/js/engine.rb
88
- - lib/citeproc/js/support/citeproc.js
89
- - lib/citeproc/js/support/system.js
90
- - lib/citeproc/js/support/xmldom.js
91
- - lib/citeproc/js/support/xmle4x.js
92
- - lib/citeproc/js/version.rb
93
- - spec/citeproc/js/engine_spec.rb
94
- - spec/fixtures/items/items.json
95
- - spec/fixtures/locales/locales-en-US.xml
96
- - spec/fixtures/styles/apa.csl
97
- - spec/spec_helper.rb
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
- - ! '"CiteProc-JS Rubygem"'
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
- - !ruby/object:Gem::Version
118
- version: '0'
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
- - !ruby/object:Gem::Version
124
- version: 1.3.1
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: "0"
125
132
  requirements: []
133
+
126
134
  rubyforge_project:
127
- rubygems_version: 1.6.2
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/engine_spec.rb
133
- - spec/fixtures/items/items.json
134
- - spec/fixtures/locales/locales-en-US.xml
135
- - spec/fixtures/styles/apa.csl
136
- - spec/spec_helper.rb
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