Skip to content

Commit

Permalink
feat(generators): support Google IME
Browse files Browse the repository at this point in the history
  • Loading branch information
mika-f committed May 30, 2019
1 parent 8e696d4 commit 929a6a2
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,36 @@ jobs:
- ./dist/atok
key: v1-releases-atok-{{ .Branch }}-{{ .Revision }}

generate_gime:
executor: perl
steps:
- restore_repo
- restore_global_deps
- restore_deps
- run: ./bin/runner.sh Generators::Google Kaomojic ./dist/google-ime/ かお
- save_cache:
paths:
- ./dist/google-ime
key: v1-releases-google-ime-{{ .Branch }}-{{ .Revision }}

release:
executor: perl
steps:
- restore_repo
- restore_cache:
keys:
- v1-releases-atok-{{ .Branch }}-{{ .Revision }}
- restore_cache:
keys:
- v1-releases-google-ime-{{ .Branch }}-{{ .Revision }}
- run:
name: Install zip
command: |
apt update
apt install zip -y
- run: mkdir -p ./releases
- run: zip ./releases/kaomojic-atok-dictionary.zip ./dist/atok/*.txt
- run: zip ./releases/kaomojic-google-ime-dictionary.zip ./dist/google-ime/*.txt
- run:
name: Install tcnksm/ghr
command: |
Expand Down Expand Up @@ -131,6 +147,15 @@ workflows:
only:
- master
- develop
- generate_gime:
requires:
- test
filters:
branches:
only:
- master
- develop
- release:
requires:
- generate_atok
- generate_gime
55 changes: 55 additions & 0 deletions lib/Kaomojic/Tasks/Generators/Google.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package Kaomojic::Tasks::Generators::Google;
use Kaomojic::Strict;

use Data::Validator;
use File::Path qw/make_path/;
use Module::Load;

sub run {
state $v; $v //= Data::Validator->new(
fixture => { isa => 'Str' },
dist => { isa => 'Str' },
aliased => { isa => 'Str', default => '' },
)->with(qw/Method StrictSequenced/);
my ($class, $args) = $v->validate(@_);
my ($fixture, $dist, $aliased) = @$args{qw/fixture dist aliased/};

die 'alias is empty' if $aliased eq '';
die 'dist path is empty' unless $dist;

make_path($dist) or die 'cannot create a directory tree.';

my $cls = "Kaomojic::Fixtures::$fixture";
load $cls;
my @entries = map { [$_->[0], $_->[1]] } @{$cls->load};

open(my $fh, '>:encoding(utf-8)', "$dist/kaomojic.txt") or die "cannot open the file: $dist/kaomojic.txt";

foreach my $entry (@entries) {
my $a = $entry->[0] || $aliased;
my $b = $entry->[1];

say $fh "$a\t$b\t顔文字\t";
}

close $fh;
}

1;

=pod
=head1 NAME
Kaomojic::Tasks::Generators::Google
=head1 DESCRIPTION
指定された Fixture 辞書から Google IME に対応した辞書ファイルを生成します。
=head1 SYNOPSIS
./bin/runner.sh Generators::Google Kaomojic ./dist/google-ime/
./bin/runner.sh Generators::Google Kaomojic ./dist/google-ime/ かお
=cut

0 comments on commit 929a6a2

Please sign in to comment.