Skip to content

Commit

Permalink
Merge pull request #15 from jerrywdlee/jerrywdlee/add-date-auto
Browse files Browse the repository at this point in the history
Jerrywdlee/add date auto
  • Loading branch information
jerrywdlee authored Jan 14, 2020
2 parents 4b3882b + 7c9c939 commit cb7a928
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
- curl https://oscdl.ipa.go.jp/IPAexfont/IPAexfont00401.zip > fonts.zip
- curl https://ipafont.ipa.go.jp/IPAexfont/IPAexfont00401.zip > fonts.zip
- unzip -oj fonts.zip -d fonts/ && rm -rf fonts.zip
script:
- bundle exec rspec
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ruby:alpine
FROM ruby:2.6-alpine

# Setup
RUN set -x && apk update && apk upgrade && apk add --no-cache \
Expand All @@ -13,8 +13,8 @@ ADD ./ /usr/src/app/
WORKDIR /usr/src/app

RUN bundle install
RUN curl https://oscdl.ipa.go.jp/IPAexfont/IPAexfont00401.zip > fonts.zip && \
RUN curl https://ipafont.ipa.go.jp/IPAexfont/IPAexfont00401.zip > fonts.zip && \
unzip -oj fonts.zip -d fonts/ && rm -rf fonts.zip

EXPOSE 4567
CMD ["ruby", "app.rb", "-o", "0.0.0.0", "-p", "4567"]
CMD ["bundle exec ruby app.rb", "-o", "0.0.0.0", "-p", "4567"]
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $ bundle install

#### フォントのダウンロード、バージョンは適宜に替えていいです
```sh
$ curl https://oscdl.ipa.go.jp/IPAexfont/IPAexfont00401.zip > fonts.zip
$ curl https://ipafont.ipa.go.jp/IPAexfont/IPAexfont00401.zip > fonts.zip
$ unzip -oj fonts.zip -d fonts/ && rm -rf fonts.zip
```

Expand All @@ -56,7 +56,7 @@ $ unzip -oj fonts.zip -d fonts/ && rm -rf fonts.zip
##### webアプリとして

```sh
$ ruby app.rb
$ bundle exec ruby app.rb
$ open http://localhost:4567
```

Expand All @@ -68,6 +68,7 @@ Usage: make_cv [options]
-i, --input [datafile]
-s, --style [stylefile]
-o, --output [output]
-v, --version
```

```sh
Expand Down Expand Up @@ -146,6 +147,9 @@ $ git push heroku master
- コマンドモードを使う際、`data.yaml``style.txt`の中に、`erb`文法が書けるようになった。
- `data.yaml``@date`で現在の年月日を出していて、[和暦](https://github.com/sugi/wareki)も使えることになった。
- セキュリティの観点で、WEB版では`erb`文法の利用ができません。
- `data.yaml``date: 令和2年1月14日現在` は空白の場合、和暦で本日の日付が入れられます。
- `data.yaml``birth_day` Field「日付」はのみ記入した場合、年齢が自動で計算されます。
- 「日付」の書式については、[和暦](https://github.com/sugi/wareki#%E3%83%91%E3%83%BC%E3%82%B9)または[西暦](https://docs.ruby-lang.org/ja/latest/class/Date.html#S_PARSE)が使えます。
- サンプルデータとスタイルは`templates/`配下に置いた。
- サンプルデータを当たり障りのない文章に再構成した。
- サンプル写真を[StyleGAN](https://github.com/NVlabs/stylegan)で生成された偽の人物像を使用した。
1 change: 1 addition & 0 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'sinatra'
require 'sinatra/reloader' if development?

require './config'
require './lib/cv_maker'
require './lib/txt2yaml'
require './lib/util'
Expand Down
13 changes: 13 additions & 0 deletions config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Config
class << self
@@settings = {
VERSION: '0.4.0'
}

@@settings.each do |key, value|
define_method key.to_sym do
value.freeze
end
end
end
end
16 changes: 16 additions & 0 deletions lib/cv_maker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
require "mini_magick"
require "open-uri"
require "prawn"
require "wareki"
require "yaml"

require "./lib/txt2yaml"
require "./lib/util"

Expand Down Expand Up @@ -259,6 +261,20 @@ def textbox(h)

def generate(data, style)
@data = data
# 今日の日付を入力
@data['date'] ||= Date.today.strftime("%Jf") + "現在"
# 年齢を計算、「平成7年1月13日 (満 25 歳)」のような入力であれば、
# 故意にエラーを発生させて計算はしない
begin
current_date = Date.parse(@data['date'])
birthday = Date.parse(@data['birth_day'])
age = current_date.strftime('%Y%m%d').to_i
age -= birthday.strftime('%Y%m%d').to_i
age /= 10000
@data['birth_day'] += " (満 #{age} 歳)"
rescue => e
puts e.message
end
@doc = Prawn::Document.new(:page_size => "A4")
style.each do |i|
send(i["type"], i)
Expand Down
6 changes: 6 additions & 0 deletions make_cv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "prawn"
require "yaml"

require './config'
require './lib/cv_maker'
require './lib/txt2yaml'
require './lib/util'
Expand All @@ -15,6 +16,7 @@ def parse_option
op.on("-i [datafile]", "--input [datafile]") { |v| args[:input] = v }
op.on("-s [stylefile]", "--style [stylefile]") { |v| args[:style] = v }
op.on("-o [output]", "--output [output]") { |v| args[:output] = v }
op.on("-v", "--version") { |v| args[:version] = v }
op.parse!(ARGV)
end
args
Expand Down Expand Up @@ -63,6 +65,10 @@ def cerate_pdf(input_file, style_file, output_file)
check_fonts

args = parse_option
if args[:version]
puts Config.VERSION
exit(0)
end
input_file = args.fetch(:input, "templates/data.yaml")
style_file = args.fetch(:style, "templates/style.txt")
output_file = args.fetch(:output, "output.pdf")
Expand Down
7 changes: 5 additions & 2 deletions templates/data.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# 名前等
date: <%= @date.strftime("%Jf") %>現在
# date が空白の時、今日の日付(和暦)が自動で入ります
# date: <%= @date.strftime("%Jf") %>現在
name_kana: りれき たろう
name: 履歴 太郎
birth_day: <%= (@date << 25 * 12).strftime("%Jf") %> (満 25 歳)
birth_day: <%= (@date << 25 * 12).strftime("%Jf") %>
# 年齢は誕生日を基づいて計算し、下記の書式になります
# <%= (@date << 25 * 12).strftime("%Jf") %> (満 25 歳)
gender:
cell_phone: 090-1234-5678
email: [email protected]
Expand Down
5 changes: 4 additions & 1 deletion views/partial/header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<div class="navbar-brand">
<a class="navbar-item" href="/">
<!-- <img src="https://bulma.io/images/bulma-logo.png" width="112" height="28">-->
<h1><strong><%= @title %></strong></h1>
<h1>
<strong><%= @title %></strong>
<small>v<%= Config.VERSION %></small>
</h1>
</a>

<div class="navbar-item is-hidden-desktop">
Expand Down

0 comments on commit cb7a928

Please sign in to comment.