Skip to content

Commit 3541479

Browse files
committed
Replace tab with space
Add rubocop
1 parent 36b1602 commit 3541479

File tree

6 files changed

+45
-39
lines changed

6 files changed

+45
-39
lines changed

.rubocop.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
AllCops:
2+
DisabledByDefault: true
3+
4+
Style/Tab:
5+
Enabled: true

Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ end
1414

1515
# also generates 'lib/gepub/book_add_item.rb'
1616
file 'lib/gepub/metadata_add.rb' => 'tools/generate_function.rb' do
17-
sh %Q(ruby tools/generate_function.rb)
17+
sh %Q(ruby tools/generate_function.rb)
1818
end
1919

2020
desc 'auto generate code'

gepub.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ Gem::Specification.new do |s|
2020
s.add_runtime_dependency "rubyzip", "> 1.1.1", "< 2.4"
2121
s.add_development_dependency "rake"
2222
s.add_development_dependency "rspec"
23+
s.add_development_dependency "rubocop"
2324
end

lib/gepub/metadata_add.rb

+33-33
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module GEPUB
2-
class Metadata
2+
class Metadata
33
CONTENT_NODE_LIST = ['identifier', 'title', 'language', 'contributor', 'creator', 'coverage', 'date','description','format','publisher','relation','rights','source','subject','type'].each {
44
|node|
55
define_method(node + '_list') { @content_nodes[node].dup.sort_as_meta }
@@ -14,7 +14,7 @@ class Metadata
1414

1515
define_method(node, ->(content=UNASSIGNED, deprecated_id=nil, id:nil,
1616
title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
17-
lang: nil, alternates: {}) {
17+
lang: nil, alternates: {}) {
1818
if unassigned?(content)
1919
get_first_node(node)
2020
else
@@ -48,7 +48,7 @@ class Metadata
4848

4949
def add_title(content, deprecated_id = nil, deprecated_title_type = nil, id: nil,
5050
title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
51-
lang: nil, alternates: {})
51+
lang: nil, alternates: {})
5252
if deprecated_id
5353
warn 'second argument for add_title is deprecated. use id: instead'
5454
id = deprecated_id
@@ -58,15 +58,15 @@ def add_title(content, deprecated_id = nil, deprecated_title_type = nil, id: nil
5858
title_type = deprecated_title_type
5959
end
6060
meta = add_metadata('title', content, id: id,
61-
title_type: title_type,identifier_type: identifier_type,display_seq: display_seq,file_as: file_as,group_position: group_position,role: role,
62-
lang: lang, alternates: alternates)
61+
title_type: title_type,identifier_type: identifier_type,display_seq: display_seq,file_as: file_as,group_position: group_position,role: role,
62+
lang: lang, alternates: alternates)
6363
yield meta if block_given?
6464
meta
6565
end
6666

6767
def add_person(name, content, deprecated_id = nil, deprecated_role = nil, id: nil,
6868
title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
69-
lang: nil, alternates: {})
69+
lang: nil, alternates: {})
7070
if deprecated_id
7171
warn 'second argument for add_person is deprecated. use id: instead'
7272
id = deprecated_id
@@ -76,15 +76,15 @@ def add_person(name, content, deprecated_id = nil, deprecated_role = nil, id: ni
7676
role = deprecated_role
7777
end
7878
meta = add_metadata(name, content, id: id,
79-
title_type: title_type,identifier_type: identifier_type,display_seq: display_seq,file_as: file_as,group_position: group_position,role: role,
80-
lang: lang, alternates: alternates)
79+
title_type: title_type,identifier_type: identifier_type,display_seq: display_seq,file_as: file_as,group_position: group_position,role: role,
80+
lang: lang, alternates: alternates)
8181
yield meta if block_given?
8282
meta
8383
end
8484

8585
def add_creator(content, deprecated_id = nil, deprecated_role = nil, id: nil,
8686
title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
87-
lang: nil, alternates: {})
87+
lang: nil, alternates: {})
8888
if deprecated_id
8989
warn 'second argument for add_creator is deprecated. use id: instead'
9090
id = deprecated_id
@@ -93,17 +93,17 @@ def add_creator(content, deprecated_id = nil, deprecated_role = nil, id: nil,
9393
warn 'third argument for add_creator is deprecated. use role: instead'
9494
role = deprecated_role
9595
end
96-
role = 'aut' if role.nil?
96+
role = 'aut' if role.nil?
9797
meta = add_person('creator', content, id: id,
98-
title_type: title_type,identifier_type: identifier_type,display_seq: display_seq,file_as: file_as,group_position: group_position,role: role,
99-
lang: lang, alternates: alternates)
98+
title_type: title_type,identifier_type: identifier_type,display_seq: display_seq,file_as: file_as,group_position: group_position,role: role,
99+
lang: lang, alternates: alternates)
100100
yield meta if block_given?
101101
meta
102102
end
103103

104104
def add_contributor(content, deprecated_id = nil, deprecated_role = nil, id: nil,
105105
title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
106-
lang: nil, alternates: {})
106+
lang: nil, alternates: {})
107107
if deprecated_id
108108
warn 'second argument for add_contributor is deprecated. use id: instead'
109109
id = deprecated_id
@@ -113,30 +113,30 @@ def add_contributor(content, deprecated_id = nil, deprecated_role = nil, id: nil
113113
role = deprecated_role
114114
end
115115
meta = add_person('contributor', content, id: id,
116-
title_type: title_type,identifier_type: identifier_type,display_seq: display_seq,file_as: file_as,group_position: group_position,role: role,
117-
lang: lang, alternates: alternates)
116+
title_type: title_type,identifier_type: identifier_type,display_seq: display_seq,file_as: file_as,group_position: group_position,role: role,
117+
lang: lang, alternates: alternates)
118118
yield meta if block_given?
119119
meta
120120
end
121121

122-
def add_metadata(name, content, id: nil, itemclass: Meta,
123-
title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
124-
lang: nil, alternates: {}
125-
)
126-
meta = add_metadata_internal(name, content, id: id, itemclass: itemclass)
122+
def add_metadata(name, content, id: nil, itemclass: Meta,
123+
title_type: nil,identifier_type: nil,display_seq: nil,file_as: nil,group_position: nil,role: nil,
124+
lang: nil, alternates: {}
125+
)
126+
meta = add_metadata_internal(name, content, id: id, itemclass: itemclass)
127127
[{ value: title_type, name: 'title-type'},{ value: identifier_type, name: 'identifier-type'},{ value: display_seq, name: 'display-seq'},{ value: file_as, name: 'file-as'},{ value: group_position, name: 'group-position'},{ value: role, name: 'role'}].each do |refiner|
128-
if refiner[:value]
129-
meta.refine(refiner[:name], refiner[:value])
130-
end
131-
end
132-
if lang
133-
meta.lang = lang
134-
end
135-
if alternates
136-
meta.add_alternates alternates
137-
end
128+
if refiner[:value]
129+
meta.refine(refiner[:name], refiner[:value])
130+
end
131+
end
132+
if lang
133+
meta.lang = lang
134+
end
135+
if alternates
136+
meta.add_alternates alternates
137+
end
138138
yield meta if block_given?
139-
meta
140-
end
141-
end
139+
meta
140+
end
141+
end
142142
end

spec/example_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
book.generate_epub(epubname)
129129
epubcheck(epubname)
130130
end
131-
131+
132132
it 'should generate simple EPUB3 with landmarks' do
133133
book = GEPUB::Book.new
134134
book.primary_identifier('http:/example.jp/bookid_in_url', 'BookID', 'URL')
@@ -162,8 +162,8 @@
162162

163163
# within ordered block, add_item will be added to spine.
164164
book.ordered {
165-
book.add_item('text/cover.xhtml').add_content(StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>cover</title></head><body><h1>the book title</h1><img src="../img/image1.jpg" /></body></html>')).landmark(type: 'cover', title: '表紙')
166-
book.add_item('text/chap1.xhtml').add_content(StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c1</title></head><body><p>the first page</p></body></html>')).toc_text('Chapter 1').landmark(type: 'bodymatter', title: '本文')
165+
book.add_item('text/cover.xhtml').add_content(StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>cover</title></head><body><h1>the book title</h1><img src="../img/image1.jpg" /></body></html>')).landmark(type: 'cover', title: '表紙')
166+
book.add_item('text/chap1.xhtml').add_content(StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c1</title></head><body><p>the first page</p></body></html>')).toc_text('Chapter 1').landmark(type: 'bodymatter', title: '本文')
167167
book.add_item('text/chap1-1.xhtml').add_content(StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c2</title></head><body><p>the second page</p></body></html>')) # do not appear on table of contents
168168
book.add_item('text/chap2.xhtml').add_content(StringIO.new('<html xmlns="http://www.w3.org/1999/xhtml"><head><title>c3</title></head><body><p>the third page</p></body></html>')).toc_text('Chapter 2')
169169
}
@@ -173,7 +173,7 @@
173173
xml = Nokogiri::XML::Document.parse book.nav_doc
174174

175175
# check toc
176-
tocs = xml.xpath("//xmlns:nav[@epub:type='toc']/xmlns:ol/xmlns:li")
176+
tocs = xml.xpath("//xmlns:nav[@epub:type='toc']/xmlns:ol/xmlns:li")
177177
expect(tocs.size).to eq 2
178178
expect(tocs[0].content.strip).to eq 'Chapter 1'
179179
expect(tocs[1].content.strip).to eq 'Chapter 2'

tools/generate_function.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def add_ordered_item(href, deprecated_content = nil, deprecated_id = nil, deprec
3535
require_relative '../lib/gepub/meta.rb'
3636

3737
refiners = GEPUB::Meta::REFINERS.map do |refiner|
38-
refiner.sub('-', '_')
38+
refiner.sub('-', '_')
3939
end
4040

4141
refiners_arguments_string = refiners.map { |refiner| "#{refiner}: nil" }.join(',')

0 commit comments

Comments
 (0)