happy_new_year 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ tudu
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem "rspec", "~> 2.14.1"
5
+ gem "thor", "~> 0.18.1"
6
+ gem "simplecov", "~> 0.8.2"
7
+ gem "activesupport", "~> 4.0.1"
8
+ gem "activemodel", "~> 4.0.2"
9
+ gem "tudu", "~> 0.0.4"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 tbpgr
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # HappyNewYear
2
+
3
+ HappyNewYear generates 'happy new year html-letters'.
4
+
5
+ ## Purpose
6
+ * Send new year messages by html-marquee.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'happy_new_year'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install happy_new_year
21
+
22
+ ## Usage
23
+ ### init setting file(Happynewyearfile)
24
+ ~~~bash
25
+ happynewyear init
26
+ ~~~
27
+
28
+ Happynewyearfile
29
+ ~~~ruby
30
+ # encoding: utf-8
31
+
32
+ # filename
33
+ # filename is required
34
+ # filename allow only String
35
+ # filename's default value => "NewYear"
36
+ filename "NewYear"
37
+
38
+ # newyear letter from(your name)
39
+ # from is required
40
+ # from allow only String
41
+ # from's default value => "your name"
42
+ from "your name"
43
+
44
+ # newyear letter common_message
45
+ # common_message is required
46
+ # common_message allow only String
47
+ # common_message's default value => "common_message"
48
+ common_message "common_message"
49
+
50
+ # newyear letter tos(target names)
51
+ # tos is required
52
+ # tos allow only Array
53
+ # tos's default value => ["target name1", "target name2"]
54
+ tos ["target name1", "target name2"]
55
+
56
+ # newyear letter specific_messages(for each target)
57
+ # specific_messages is required
58
+ # specific_messages allow only Array
59
+ # specific_messages's default value => ["specific message1", "specific message2"]
60
+ specific_messages ["specific message1", "specific message2"]
61
+ ~~~
62
+
63
+ ### edit setting file(Happynewyearfile) manually
64
+ Happynewyearfile
65
+ ~~~ruby
66
+ # encoding: utf-8
67
+ filename "NewYear"
68
+ from "tbpgr"
69
+ common_message "Happy New Year!!"
70
+ tos ["Mr tanaka kazuo", "Mr suzuki ichiro"]
71
+ specific_messages ["The best regards next year.", "In fact I love you."]
72
+ ~~~
73
+
74
+ ### output happy new year html-letter
75
+ ~~~bash
76
+ happynewyear execute
77
+ ~~~
78
+
79
+ ### comfirm output html files
80
+ * NewYear1.html
81
+ ~~~html
82
+ <html>
83
+ <head>
84
+ <meta charset="UTF-8">
85
+ <title>Happy New Year</title>
86
+ </head>
87
+ <body>
88
+ <marquee style='font-size:40px;'>To Mr tanaka kazuo Happy New Year!! The best regards next year. From tbpgr</marquee>
89
+ </body>
90
+ </html>
91
+ ~~~
92
+
93
+ * NewYear2.html
94
+ ~~~html
95
+ <html>
96
+ <head>
97
+ <meta charset="UTF-8">
98
+ <title>Happy New Year</title>
99
+ </head>
100
+ <body>
101
+ <marquee style='font-size:40px;'>To Mr suzuki ichiro Happy New Year!! In fact I love you. From tbpgr</marquee>
102
+ </body>
103
+ </html>
104
+ ~~~
105
+
106
+ ## History
107
+ * version 0.0.1 : first release.
108
+
109
+ ## Contributing
110
+
111
+ 1. Fork it
112
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
113
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
114
+ 4. Push to the branch (`git push origin my-new-feature`)
115
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/happynewyear ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'happy_new_year_core'
5
+ require 'happy_new_year/version'
6
+ require 'thor'
7
+
8
+ module HappyNewYear
9
+ # = HappyNewYear CLI
10
+ class CLI < Thor
11
+ class_option :help, type: :boolean, aliases: '-h', desc: 'help message.'
12
+ class_option :version, type: :boolean, desc: 'version'
13
+
14
+ desc 'execute', 'generate Happy New Year html letters'
15
+ def execute
16
+ HappyNewYear::Core.new.execute
17
+ end
18
+
19
+ desc 'init', 'generate Happynewyearfile'
20
+ def init
21
+ HappyNewYear::Core.new.init
22
+ end
23
+
24
+ desc 'version', 'version'
25
+ def version
26
+ p HappyNewYear::VERSION
27
+ end
28
+ end
29
+ end
30
+
31
+ HappyNewYear::CLI.start(ARGV)
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'happy_new_year/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "happy_new_year"
8
+ spec.version = HappyNewYear::VERSION
9
+ spec.authors = ["tbpgr"]
10
+ spec.email = ["tbpgr@tbpgr.jp"]
11
+ spec.description = %q{HappyNewYear generates 'happy new year html-letters'}
12
+ spec.summary = %q{HappyNewYear generates 'happy new year html-letters'}
13
+ spec.homepage = "https://github.com/tbpgr/happy_new_year"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "thor", "~> 0.18.1"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "simplecov", "~> 0.8.2"
26
+ spec.add_development_dependency "rspec", "~> 2.14.1"
27
+ end
@@ -0,0 +1,3 @@
1
+ module HappyNewYear
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,97 @@
1
+ # encoding: utf-8
2
+ require 'happy_new_year_dsl'
3
+ require 'erb'
4
+
5
+ # =HappyNewYear
6
+ module HappyNewYear
7
+ # =HappyNewYear Core
8
+ class Core
9
+ # Internal DSL Setting file name
10
+ HAPPY_NEW_YEAR_FILE = 'Happynewyearfile'
11
+ # Internal DSL Setting file Template
12
+ HAPPY_NEW_YEAR_TEMPLATE = <<-EOS
13
+ # encoding: utf-8
14
+
15
+ # filename
16
+ # filename is required
17
+ # filename allow only String
18
+ # filename's default value => "NewYear"
19
+ filename "NewYear"
20
+
21
+ # newyear letter from(your name)
22
+ # from is required
23
+ # from allow only String
24
+ # from's default value => "your name"
25
+ from "your name"
26
+
27
+ # newyear letter common_message
28
+ # common_message is required
29
+ # common_message allow only String
30
+ # common_message's default value => "common_message"
31
+ common_message "common_message"
32
+
33
+ # newyear letter tos(target names)
34
+ # tos is required
35
+ # tos allow only Array
36
+ # tos's default value => ["target name1", "target name2"]
37
+ tos ["target name1", "target name2"]
38
+
39
+ # newyear letter specific_messages(for each target)
40
+ # specific_messages is required
41
+ # specific_messages allow only Array
42
+ # specific_messages's default value => ["specific message1", "specific message2"]
43
+ specific_messages ["specific message1", "specific message2"]
44
+
45
+ EOS
46
+
47
+ # output html template
48
+ HAPPY_NEW_YEAR_CONTENTS_TEMPLATE = <<-EOS
49
+ <html>
50
+ <head>
51
+ <meta charset="UTF-8">
52
+ <title>Happy New Year</title>
53
+ </head>
54
+ <body>
55
+ <marquee style='font-size:40px;'><%=message%></marquee>
56
+ </body>
57
+ </html>
58
+ EOS
59
+
60
+ # basic spacing
61
+ BASIC_SPACE = ' '
62
+
63
+ # == generate Happynewyearfile to current directory.
64
+ def init
65
+ File.open(HAPPY_NEW_YEAR_FILE, 'w') { |f|f.puts HAPPY_NEW_YEAR_TEMPLATE }
66
+ end
67
+
68
+ # == generate Happy New Year html letters
69
+ def execute
70
+ src = read_dsl
71
+ dsl = HappyNewYear::Dsl.new
72
+ dsl.instance_eval src
73
+ from = dsl.happy_new_year.from
74
+ common_message = dsl.happy_new_year.common_message
75
+ output_base = dsl.happy_new_year.filename
76
+ dsl.happy_new_year.specific_messages.each_with_index do |specific_message, index|
77
+ contents = get_result_html(from, common_message, specific_message, dsl.happy_new_year.tos[index])
78
+ output_newyear_html("#{output_base}#{index + 1}.html", contents)
79
+ end
80
+ end
81
+
82
+ private
83
+ def read_dsl
84
+ File.open(HAPPY_NEW_YEAR_FILE) { |f|f.read }
85
+ end
86
+
87
+ def get_result_html(from, common_message, specific_message, to)
88
+ message = "To #{to}#{BASIC_SPACE}#{common_message}#{BASIC_SPACE}#{specific_message}#{BASIC_SPACE}From #{from}"
89
+ erb = ERB.new(HAPPY_NEW_YEAR_CONTENTS_TEMPLATE)
90
+ erb.result(binding)
91
+ end
92
+
93
+ def output_newyear_html(filename, contents)
94
+ File.open(filename, 'w:utf-8') { |f|f.print contents }
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ require 'happy_new_year_dsl_model'
3
+
4
+ module HappyNewYear
5
+ class Dsl
6
+ attr_accessor :happy_new_year
7
+
8
+ # String Define
9
+ [:filename, :from, :common_message].each do |f|
10
+ define_method f do |value|
11
+ eval "@happy_new_year.#{f.to_s} = '#{value}'", binding
12
+ end
13
+ end
14
+
15
+ # Array/Hash/Boolean Define
16
+ [:tos, :specific_messages].each do |f|
17
+ define_method f do |value|
18
+ eval "@happy_new_year.#{f.to_s} = #{value}", binding
19
+ end
20
+ end
21
+
22
+ def initialize
23
+ @happy_new_year = HappyNewYear::DslModel.new
24
+ @happy_new_year.filename = 'NewYear'
25
+ @happy_new_year.from = 'your name'
26
+ @happy_new_year.common_message = 'common_message'
27
+ @happy_new_year.tos = ['target name1', 'target name2']
28
+ @happy_new_year.specific_messages = ['specific message1', 'specific message2']
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ require 'active_model'
3
+
4
+ module HappyNewYear
5
+ class DslModel
6
+ include ActiveModel::Model
7
+
8
+ # filename
9
+ attr_accessor :filename
10
+ validates :filename, presence: true
11
+
12
+ # newyear letter from(your name)
13
+ attr_accessor :from
14
+ validates :from, presence: true
15
+
16
+ # newyear letter common_message
17
+ attr_accessor :common_message
18
+ validates :common_message, presence: true
19
+
20
+ # newyear letter tos(target names)
21
+ attr_accessor :tos
22
+ validates :tos, presence: true
23
+
24
+ # newyear letter specific_messages(for each target)
25
+ attr_accessor :specific_messages
26
+ validates :specific_messages, presence: true
27
+
28
+ end
29
+ end
@@ -0,0 +1,130 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'happy_new_year_core'
4
+
5
+ describe HappyNewYear::Core do
6
+
7
+ context :init do
8
+ OUTPUT_DSL_TMP_DIR = 'generate_dsl'
9
+ cases = [
10
+ {
11
+ case_no: 1,
12
+ case_title: 'valid new year mail',
13
+ expected: HappyNewYear::Core::HAPPY_NEW_YEAR_TEMPLATE,
14
+ },
15
+ ]
16
+
17
+ cases.each do |c|
18
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
19
+ begin
20
+ case_before c
21
+
22
+ # -- given --
23
+ happy_new_year_core = HappyNewYear::Core.new
24
+
25
+ # -- when --
26
+ happy_new_year_core.init
27
+
28
+ # -- then --
29
+ actual = File.read("./#{HappyNewYear::Core::HAPPY_NEW_YEAR_FILE}")
30
+ expect(actual).to eq(c[:expected])
31
+ ensure
32
+ case_after c
33
+
34
+ end
35
+ end
36
+
37
+ def case_before(c)
38
+ Dir.mkdir(OUTPUT_DSL_TMP_DIR) unless Dir.exists? OUTPUT_DSL_TMP_DIR
39
+ Dir.chdir(OUTPUT_DSL_TMP_DIR)
40
+ end
41
+
42
+ def case_after(c)
43
+ Dir.chdir('../')
44
+ FileUtils.rm_rf(OUTPUT_DSL_TMP_DIR) if Dir.exists? OUTPUT_DSL_TMP_DIR
45
+ end
46
+ end
47
+ end
48
+
49
+ context :execute do
50
+ OUTPUT_TMP_DIR = 'tmp_newyear'
51
+ NEWYEAR_CASE1_INPUT = <<-EOS
52
+ # encoding: utf-8
53
+ filename "HappyNewYear"
54
+ from "tbpgr"
55
+ common_message "A Happy New Year!!"
56
+ tos ["Mr tanaka hiroshi", "Mr suzuki kazuo"]
57
+ specific_messages ["The best regards next year.", "In fact I love you."]
58
+ EOS
59
+
60
+ NEWYEAR_OUTPUTS1_1 = <<-EOS
61
+ <html>
62
+ <head>
63
+ <meta charset="UTF-8">
64
+ <title>Happy New Year</title>
65
+ </head>
66
+ <body>
67
+ <marquee style='font-size:40px;'>To Mr tanaka hiroshi A Happy New Year!! The best regards next year. From tbpgr</marquee>
68
+ </body>
69
+ </html>
70
+ EOS
71
+
72
+ NEWYEAR_OUTPUTS1_2 = <<-EOS
73
+ <html>
74
+ <head>
75
+ <meta charset="UTF-8">
76
+ <title>Happy New Year</title>
77
+ </head>
78
+ <body>
79
+ <marquee style='font-size:40px;'>To Mr suzuki kazuo A Happy New Year!! In fact I love you. From tbpgr</marquee>
80
+ </body>
81
+ </html>
82
+ EOS
83
+
84
+ cases = [
85
+ {
86
+ case_no: 1,
87
+ case_title: 'valid new year output',
88
+ input: NEWYEAR_CASE1_INPUT,
89
+ expected_file_names: ['HappyNewYear1.html', 'HappyNewYear2.html'],
90
+ expected_file_contents: [NEWYEAR_OUTPUTS1_1, NEWYEAR_OUTPUTS1_2],
91
+ },
92
+ ]
93
+
94
+ cases.each do |c|
95
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
96
+ begin
97
+ case_before c
98
+
99
+ # -- given --
100
+ happy_new_year_core = HappyNewYear::Core.new
101
+
102
+ # -- when --
103
+ happy_new_year_core.execute
104
+
105
+ # -- then --
106
+ c[:expected_file_names].each_with_index do |filename, index|
107
+ file_exists = File.exists?(filename)
108
+ expect(file_exists).to be_true
109
+ file_contents = File.read(filename)
110
+ expect(file_contents).to eq(c[:expected_file_contents][index])
111
+ end
112
+ ensure
113
+ case_after c
114
+ end
115
+ end
116
+
117
+ def case_before(c)
118
+ Dir.mkdir(OUTPUT_DSL_TMP_DIR) unless Dir.exists? OUTPUT_DSL_TMP_DIR
119
+ Dir.chdir(OUTPUT_DSL_TMP_DIR)
120
+ File.open(HappyNewYear::Core::HAPPY_NEW_YEAR_FILE, 'w:utf-8') { |f|f.print c[:input] }
121
+ end
122
+
123
+ def case_after(c)
124
+ Dir.chdir('../')
125
+ FileUtils.rm_rf(OUTPUT_DSL_TMP_DIR) if Dir.exists? OUTPUT_DSL_TMP_DIR
126
+ end
127
+ end
128
+ end
129
+
130
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+ require 'simplecov'
3
+ SimpleCov.start 'rails'
4
+
5
+ RSpec.configure do |config|
6
+ config.treat_symbols_as_metadata_keys_with_true_values = true
7
+ config.run_all_when_everything_filtered = true
8
+ config.filter_run :focus
9
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: happy_new_year
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - tbpgr
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: &21759384 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.18.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *21759384
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &21758928 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '1.3'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *21758928
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &21758592 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *21758592
47
+ - !ruby/object:Gem::Dependency
48
+ name: simplecov
49
+ requirement: &21758268 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.2
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *21758268
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &21757968 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 2.14.1
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *21757968
69
+ description: HappyNewYear generates 'happy new year html-letters'
70
+ email:
71
+ - tbpgr@tbpgr.jp
72
+ executables:
73
+ - happynewyear
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rspec
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/happynewyear
84
+ - happy_new_year.gemspec
85
+ - lib/happy_new_year/version.rb
86
+ - lib/happy_new_year_core.rb
87
+ - lib/happy_new_year_dsl.rb
88
+ - lib/happy_new_year_dsl_model.rb
89
+ - spec/happy_new_year_core_spec.rb
90
+ - spec/spec_helper.rb
91
+ homepage: https://github.com/tbpgr/happy_new_year
92
+ licenses:
93
+ - MIT
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 1.8.11
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: HappyNewYear generates 'happy new year html-letters'
116
+ test_files:
117
+ - spec/happy_new_year_core_spec.rb
118
+ - spec/spec_helper.rb
119
+ has_rdoc: