Skip to content

Commit

Permalink
Improved build script
Browse files Browse the repository at this point in the history
  • Loading branch information
neauoire committed Jun 19, 2017
1 parent 188a532 commit 2ef16b5
Show file tree
Hide file tree
Showing 17 changed files with 467 additions and 792 deletions.
167 changes: 122 additions & 45 deletions core/book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,80 @@ class Book

attr_accessor :name
attr_accessor :style
attr_accessor :content

def initialize name
def initialize content

# A5 = 148mm x 210mm
@name = name
@content = content
@style = default_styles

end

def assemble target_story

puts "Assembling #{target_story[:title]}, by #{target_story[:translator]}"

@pages = []
@style = "
@font-face { font-family: 'Jura'; src: url('assets/fonts/jura_regular.ttf') format('truetype'); font-weight: normal; font-style: normal; }
@page { size: 148mm 210mm; width:592px; height:840px; margin:0px; padding:0px }
body { font-family:'azuki_font','aquafont','Garamond'; padding:0px; margin:0px;}
page { page-break-after: always; display:block; position:relative; overflow:hidden; background:#ffffff; width:592px; height:820px; border:1px solid #fefefe; }
page id { position: absolute;bottom: 10px;display: block;text-align: center;width:100%;}
page grave { display:inline; background-image:url(assets/accent.grave.svg); background-position:center 0px}
page aigue { display:inline; background-image:url(assets/accent.aigue.svg); background-position:center 0px}
page cedil { display:inline; background-image:url(assets/accent.cedil.svg); background-position:center 0px}
page trema { display: inline-block;background-position: center 0px;height: 15.5px;}
page trema:before { background-color:white; display: inline-block;width: 15px;height: 15px;content: ' ';position: absolute; background-image: url(assets/accent.trema.svg); }
<<<<<<< HEAD
body.lang_el { font-family: 'Jura', sans-serif; }
body.lang_ru h1 { letter-spacing:-12px}
body.lang_el h1 { letter-spacing:-2px}
body.lang_ru .cover h1 { letter-spacing:-8px}
body.lang_el .cover h1 { letter-spacing:-2px}
body.lang_ru .title h1 { letter-spacing:-8px}
body.lang_el .preface p {letter-spacing:-2px}
body.lang_ru .preface p {letter-spacing:-6px}
body.lang_el .illustration h1 { letter-spacing:-2px}
body.lang_ru .thank p {letter-spacing:-6px}
body.lang_el .thank p {letter-spacing:-2px}
body.lang_ar { font-family: 'KufiStandardGK', 'Jura', Tahoma !important; }
=======
body.lang_el { font-family: 'Yuanti TC', sans-serif; }
body.lang_ru h1 { letter-spacing:-12px}
body.lang_ru .cover h1 { letter-spacing:-8px}
body.lang_ru .title h1 { letter-spacing:-8px}
body.lang_ru .preface p {letter-spacing:-6px}
body.lang_ru .thank p {letter-spacing:-6px}
body.lang_ar { font-family: 'Jura', Tahoma !important; }
>>>>>>> upstream/master
"
@name = name
@increment = 0


add_page(CoverPage.new(target_story[:title]))
add_page(BlankPage.new)
add_page(TitlePage.new(target_story[:title_page]))
add_page(BlankPage.new)
add_page(PrefacePage.new(target_story[:preface]))
add_page(BlankPage.new)
add_page(ChapterPage.new(1,target_story[:lesson1][0]))
add_page(IllustrationPage.new("cat.1",target_story[:lesson1][1]))
add_page(IllustrationPage.new("owl.1",target_story[:lesson1][2]))
add_page(IllustrationPage.new("bat.1",target_story[:lesson1][3]))
add_page(IllustrationPage.new("fox.1",target_story[:lesson1][4]))
add_page(BlankPage.new)

add_page(ChapterPage.new(2,target_story[:lesson2][0]))
add_page(IllustrationPage.new("cat.2",target_story[:lesson2][1]))
add_page(IllustrationPage.new("owl.2",target_story[:lesson2][2]))
add_page(IllustrationPage.new("bat.2",target_story[:lesson2][3]))
add_page(IllustrationPage.new("fox.2",target_story[:lesson2][4]))
add_page(BlankPage.new)

add_page(ChapterPage.new(3,target_story[:lesson3][0]))
add_page(IllustrationPage.new("cat.3",target_story[:lesson3][1]))
add_page(IllustrationPage.new("owl.3",target_story[:lesson3][2]))
add_page(IllustrationPage.new("bat.3",target_story[:lesson3][3]))
add_page(IllustrationPage.new("fox.3",target_story[:lesson3][4]))
add_page(BlankPage.new)

add_page(ChapterPage.new(4,target_story[:lesson4][0]))
add_page(IllustrationPage.new("cat.4",target_story[:lesson4][1]))
add_page(IllustrationPage.new("owl.4",target_story[:lesson4][2]))
add_page(IllustrationPage.new("bat.4",target_story[:lesson4][3]))
add_page(IllustrationPage.new("fox.4",target_story[:lesson4][4]))
add_page(BlankPage.new)

add_page(ChapterPage.new(5,target_story[:lesson5][0]))
add_page(IllustrationPage.new("cat.5",target_story[:lesson5][1]))
add_page(IllustrationPage.new("owl.5",target_story[:lesson5][2]))
add_page(IllustrationPage.new("bat.5",target_story[:lesson5][3]))
add_page(IllustrationPage.new("fox.5",target_story[:lesson5][4]))
add_page(BlankPage.new)

add_page(ChapterPage.new(6,target_story[:lesson6][0]))
add_page(IllustrationPage.new("cat.6",target_story[:lesson6][1]))
add_page(IllustrationPage.new("owl.6",target_story[:lesson6][2]))
add_page(IllustrationPage.new("bat.6",target_story[:lesson6][3]))
add_page(IllustrationPage.new("fox.6",target_story[:lesson6][4]))
add_page(BlankPage.new)

add_page(ChapterPage.new(7,target_story[:lesson7][0]))
add_page(BlankPage.new)
add_page(IllustrationPage.new("you.1",target_story[:lesson7][1]))
add_page(BlankPage.new)

add_page(ThankPage.new(target_story[:thanks],@content))
add_page(BlankPage.new)

end

def add_page page
Expand All @@ -64,30 +95,76 @@ def add_page page
@pages.push(page)

end

def build lang

puts "Generating.."

content = "<style>\n#{@style}</style>\n\n"
def bind lang

puts "Binding #{@pages.length} pages"

body = "<style>\n#{@style}</style>\n\n"

# Print pages
count = 0
@pages.each do |page|
progress = (((count+1)/@pages.length.to_f)*100).to_i
puts "#{progress}% Page: #{page.id} #{page.type}"
content += page.to_s
body += page.to_s
count += 1
end

# Create file
out_file = File.new("thousand.#{lang}.html", "w")
out_file.puts("<html><meta charset='UTF-8'><body class='lang_#{lang}'>#{content}</body></html>")
out_file.puts("<html><meta charset='UTF-8'><body class='lang_#{lang}'>#{body}</body></html>")
out_file.close

puts "Completed #{count} pages, for thousand.#{lang}.html"
puts "Word count: #{$word_cound}"

end

def build

@content.each do |lang,pages|
puts "Building #{lang}"
assemble(pages)
bind(lang)
end

end

def default_styles

return "
@font-face { font-family: 'Jura'; src: url('assets/fonts/jura_regular.ttf') format('truetype'); font-weight: normal; font-style: normal; }
@page { size: 148mm 210mm; width:592px; height:840px; margin:0px; padding:0px }
body { font-family:'azuki_font','aquafont','Garamond'; padding:0px; margin:0px;}
page { page-break-after: always; display:block; position:relative; overflow:hidden; background:#ffffff; width:592px; height:820px; border:1px solid #fefefe; }
page id { position: absolute;bottom: 10px;display: block;text-align: center;width:100%;}
page grave { display:inline; background-image:url(assets/accent.grave.svg); background-position:center 0px}
page aigue { display:inline; background-image:url(assets/accent.aigue.svg); background-position:center 0px}
page cedil { display:inline; background-image:url(assets/accent.cedil.svg); background-position:center 0px}
page trema { display: inline-block;background-position: center 0px;height: 15.5px;}
page trema:before { background-color:white; display: inline-block;width: 15px;height: 15px;content: ' ';position: absolute; background-image: url(assets/accent.trema.svg); }
body.lang_el { font-family: 'Jura', sans-serif; }
body.lang_ru h1 { letter-spacing:-12px}
body.lang_el h1 { letter-spacing:-2px}
body.lang_ru .cover h1 { letter-spacing:-8px}
body.lang_el .cover h1 { letter-spacing:-2px}
body.lang_ru .title h1 { letter-spacing:-8px}
body.lang_el .preface p {letter-spacing:-2px}
body.lang_ru .preface p {letter-spacing:-6px}
body.lang_el .illustration h1 { letter-spacing:-2px}
body.lang_ru .thank p {letter-spacing:-6px}
body.lang_el .thank p {letter-spacing:-2px}
body.lang_ar { font-family: 'KufiStandardGK', 'Jura', Tahoma !important; }
body.lang_el { font-family: 'Yuanti TC', sans-serif; }
body.lang_ru h1 { letter-spacing:-12px}
body.lang_ru .cover h1 { letter-spacing:-8px}
body.lang_ru .title h1 { letter-spacing:-8px}
body.lang_ru .preface p {letter-spacing:-6px}
body.lang_ru .thank p {letter-spacing:-6px}
body.lang_ar { font-family: 'Jura', Tahoma !important; }
"
end


end
2 changes: 0 additions & 2 deletions core/pages/chapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ def initialize chapter, loc_text
@style["h1 grave"] = "display: inline;background-image: url(assets/accent.grave.svg);background-position: 2px 5px !important"
@style["h1 aigue"] = "display:inline; background-image:url(assets/accent.aigue.svg); background-position:center 0px"
@style["h1 cedil"] = "display:inline; background-image:url(assets/accent.cedil.svg); background-position:3px 13px"

$word_cound += @text.split(" ").length

end

Expand Down
2 changes: 0 additions & 2 deletions core/pages/illustration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ def initialize name = "missing", loc_text = nil
@style["h1"] = "position:absolute; top:100px; display:block; text-align:center; width:calc(100% - 40px); padding:0px 20px; font-size:38px;font-weight: normal; line-height: 60px"
@style["h1 trema:before"] = "top:10px"

$word_cound += @text.split(" ").length

end

def content
Expand Down
2 changes: 0 additions & 2 deletions core/pages/preface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def initialize loc_text

@text = loc_text

$word_cound += @text.split(" ").length

end

def content
Expand Down
95 changes: 15 additions & 80 deletions main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,83 +24,18 @@
require_relative 'lang.ch.rb'
require_relative 'lang.ar.rb'

$lang = ARGV.first.to_sym ? ARGV.first.to_sym : :en
$word_cound = 0

$story = {}
$story[:en] = $lang_en
$story[:fr] = $lang_fr
$story[:ru] = $lang_ru
$story[:jp] = $lang_jp
$story[:li] = $lang_li
$story[:de] = $lang_de
$story[:it] = $lang_it
$story[:nl] = $lang_nl
$story[:el] = $lang_el
$story[:ch] = $lang_ch
$story[:ar] = $lang_ar

$story.each do |lang,story|

target_story = $story[lang]

book = Book.new(target_story[:title])
book.add_page(CoverPage.new(target_story[:title]))
book.add_page(BlankPage.new)
book.add_page(TitlePage.new(target_story[:title_page]))
book.add_page(BlankPage.new)
book.add_page(PrefacePage.new(target_story[:preface]))
book.add_page(BlankPage.new)
book.add_page(ChapterPage.new(1,target_story[:lesson1][0]))
book.add_page(IllustrationPage.new("cat.1",target_story[:lesson1][1]))
book.add_page(IllustrationPage.new("owl.1",target_story[:lesson1][2]))
book.add_page(IllustrationPage.new("bat.1",target_story[:lesson1][3]))
book.add_page(IllustrationPage.new("fox.1",target_story[:lesson1][4]))
book.add_page(BlankPage.new)

book.add_page(ChapterPage.new(2,target_story[:lesson2][0]))
book.add_page(IllustrationPage.new("cat.2",target_story[:lesson2][1]))
book.add_page(IllustrationPage.new("owl.2",target_story[:lesson2][2]))
book.add_page(IllustrationPage.new("bat.2",target_story[:lesson2][3]))
book.add_page(IllustrationPage.new("fox.2",target_story[:lesson2][4]))
book.add_page(BlankPage.new)

book.add_page(ChapterPage.new(3,target_story[:lesson3][0]))
book.add_page(IllustrationPage.new("cat.3",target_story[:lesson3][1]))
book.add_page(IllustrationPage.new("owl.3",target_story[:lesson3][2]))
book.add_page(IllustrationPage.new("bat.3",target_story[:lesson3][3]))
book.add_page(IllustrationPage.new("fox.3",target_story[:lesson3][4]))
book.add_page(BlankPage.new)

book.add_page(ChapterPage.new(4,target_story[:lesson4][0]))
book.add_page(IllustrationPage.new("cat.4",target_story[:lesson4][1]))
book.add_page(IllustrationPage.new("owl.4",target_story[:lesson4][2]))
book.add_page(IllustrationPage.new("bat.4",target_story[:lesson4][3]))
book.add_page(IllustrationPage.new("fox.4",target_story[:lesson4][4]))
book.add_page(BlankPage.new)

book.add_page(ChapterPage.new(5,target_story[:lesson5][0]))
book.add_page(IllustrationPage.new("cat.5",target_story[:lesson5][1]))
book.add_page(IllustrationPage.new("owl.5",target_story[:lesson5][2]))
book.add_page(IllustrationPage.new("bat.5",target_story[:lesson5][3]))
book.add_page(IllustrationPage.new("fox.5",target_story[:lesson5][4]))
book.add_page(BlankPage.new)

book.add_page(ChapterPage.new(6,target_story[:lesson6][0]))
book.add_page(IllustrationPage.new("cat.6",target_story[:lesson6][1]))
book.add_page(IllustrationPage.new("owl.6",target_story[:lesson6][2]))
book.add_page(IllustrationPage.new("bat.6",target_story[:lesson6][3]))
book.add_page(IllustrationPage.new("fox.6",target_story[:lesson6][4]))
book.add_page(BlankPage.new)

book.add_page(ChapterPage.new(7,target_story[:lesson7][0]))
book.add_page(BlankPage.new)
book.add_page(IllustrationPage.new("you.1",target_story[:lesson7][1]))
book.add_page(BlankPage.new)

book.add_page(ThankPage.new(target_story[:thanks],$story))
book.add_page(BlankPage.new)

book.build(lang)

end
content = {}
content[:en] = $lang_en
content[:fr] = $lang_fr
content[:ru] = $lang_ru
content[:jp] = $lang_jp
content[:li] = $lang_li
content[:de] = $lang_de
content[:it] = $lang_it
content[:nl] = $lang_nl
content[:el] = $lang_el
content[:ch] = $lang_ch
content[:ar] = $lang_ar

book = Book.new(content)
book.build
64 changes: 30 additions & 34 deletions thousand.ar.html
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
<html><meta charset='UTF-8'><body class='lang_ar'><style>


@font-face { font-family: 'Jura'; src: url('assets/fonts/jura_regular.ttf') format('truetype'); font-weight: normal; font-style: normal; }
@page { size: 148mm 210mm; width:592px; height:840px; margin:0px; padding:0px }
body { font-family:'azuki_font','aquafont','Garamond'; padding:0px; margin:0px;}
page { page-break-after: always; display:block; position:relative; overflow:hidden; background:#ffffff; width:592px; height:820px; border:1px solid #fefefe; }
page id { position: absolute;bottom: 10px;display: block;text-align: center;width:100%;}
page grave { display:inline; background-image:url(assets/accent.grave.svg); background-position:center 0px}
page aigue { display:inline; background-image:url(assets/accent.aigue.svg); background-position:center 0px}
page cedil { display:inline; background-image:url(assets/accent.cedil.svg); background-position:center 0px}
page trema { display: inline-block;background-position: center 0px;height: 15.5px;}
page trema:before { background-color:white; display: inline-block;width: 15px;height: 15px;content: ' ';position: absolute; background-image: url(assets/accent.trema.svg); }
<<<<<<< HEAD
body.lang_el { font-family: 'Jura', sans-serif; }
body.lang_ru h1 { letter-spacing:-12px}
body.lang_el h1 { letter-spacing:-2px}
body.lang_ru .cover h1 { letter-spacing:-8px}
body.lang_el .cover h1 { letter-spacing:-2px}
body.lang_ru .title h1 { letter-spacing:-8px}
body.lang_el .preface p {letter-spacing:-2px}
body.lang_ru .preface p {letter-spacing:-6px}
body.lang_el .illustration h1 { letter-spacing:-2px}
body.lang_ru .thank p {letter-spacing:-6px}
body.lang_el .thank p {letter-spacing:-2px}
body.lang_ar { font-family: 'KufiStandardGK', 'Jura', Tahoma !important; }
=======
body.lang_el { font-family: 'Yuanti TC', sans-serif; }
body.lang_ru h1 { letter-spacing:-12px}
body.lang_ru .cover h1 { letter-spacing:-8px}
body.lang_ru .title h1 { letter-spacing:-8px}
body.lang_ru .preface p {letter-spacing:-6px}
body.lang_ru .thank p {letter-spacing:-6px}
body.lang_ar { font-family: 'Jura', Tahoma !important; }
>>>>>>> upstream/master
page.cover { background:white; overflow:hidden }
@font-face { font-family: 'Jura'; src: url('assets/fonts/jura_regular.ttf') format('truetype'); font-weight: normal; font-style: normal; }
@page { size: 148mm 210mm; width:592px; height:840px; margin:0px; padding:0px }
body { font-family:'azuki_font','aquafont','Garamond'; padding:0px; margin:0px;}
page { page-break-after: always; display:block; position:relative; overflow:hidden; background:#ffffff; width:592px; height:820px; border:1px solid #fefefe; }
page id { position: absolute;bottom: 10px;display: block;text-align: center;width:100%;}
page grave { display:inline; background-image:url(assets/accent.grave.svg); background-position:center 0px}
page aigue { display:inline; background-image:url(assets/accent.aigue.svg); background-position:center 0px}
page cedil { display:inline; background-image:url(assets/accent.cedil.svg); background-position:center 0px}
page trema { display: inline-block;background-position: center 0px;height: 15.5px;}
page trema:before { background-color:white; display: inline-block;width: 15px;height: 15px;content: ' ';position: absolute; background-image: url(assets/accent.trema.svg); }
body.lang_el { font-family: 'Jura', sans-serif; }
body.lang_ru h1 { letter-spacing:-12px}
body.lang_el h1 { letter-spacing:-2px}
body.lang_ru .cover h1 { letter-spacing:-8px}
body.lang_el .cover h1 { letter-spacing:-2px}
body.lang_ru .title h1 { letter-spacing:-8px}
body.lang_el .preface p {letter-spacing:-2px}
body.lang_ru .preface p {letter-spacing:-6px}
body.lang_el .illustration h1 { letter-spacing:-2px}
body.lang_ru .thank p {letter-spacing:-6px}
body.lang_el .thank p {letter-spacing:-2px}
body.lang_ar { font-family: 'KufiStandardGK', 'Jura', Tahoma !important; }
body.lang_el { font-family: 'Yuanti TC', sans-serif; }
body.lang_ru h1 { letter-spacing:-12px}
body.lang_ru .cover h1 { letter-spacing:-8px}
body.lang_ru .title h1 { letter-spacing:-8px}
body.lang_ru .preface p {letter-spacing:-6px}
body.lang_ru .thank p {letter-spacing:-6px}
body.lang_ar { font-family: 'Jura', Tahoma !important; }
page.cover { background:white; overflow:hidden }
page.cover img { width:100% }
page.cover h1 { position:absolute; bottom:100px; color:black; text-transform:uppercase; width:100%; text-align:center; font-weight:normal; font-size:36px }
page.cover h1 trema:before { top:-15px }
Expand Down
Loading

0 comments on commit 2ef16b5

Please sign in to comment.