denrei 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,17 @@
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
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in denrei.gemspec
4
+ gemspec
5
+ gem "rspec", "~> 2.14.1"
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,52 @@
1
+ # Denrei
2
+
3
+ Denrei shows Ruby/Tk-Dialog with your favorite titile & message.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'denrei'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install denrei
18
+
19
+
20
+
21
+ ## Usage
22
+
23
+ Only you have to do is execute command denrei in command prompt.(default title=Denrei, message=Finish!!)
24
+
25
+ denrei
26
+
27
+ If you want to use custom title or message, first create Denreifile.
28
+
29
+ denrei init
30
+
31
+ And you can change your favorite title & message
32
+
33
+ # encoding: utf-8
34
+ # ***title-settings***
35
+ # if you want to change defalt title "Denrei", comment out title_text and set your text
36
+ title_text "set your favorite title"
37
+
38
+ # ***message-settings***
39
+ # if you want to change defalt message "finish", comment out message_text and set your text
40
+ message_text "set your favorite message"
41
+
42
+ After setting your favorites, you execute denrei.
43
+
44
+ denrei
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/denrei ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'denrei'
4
+ Denrei::Core.new.do_denrei
data/denrei.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'denrei/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "denrei"
8
+ spec.version = Denrei::VERSION
9
+ spec.authors = ["tbpgr"]
10
+ spec.email = ["tbpgr@tbpgr.jp"]
11
+ spec.description = %q{Denrei shows Ruby/Tk-Dialog with your favorite titile & message.}
12
+ spec.summary = %q{Denrei shows Ruby/Tk-Dialog with your favorite titile & message.}
13
+ spec.homepage = "https://github.com/tbpgr/denrei"
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 2.14.1"
24
+ end
data/lib/denrei.rb ADDED
@@ -0,0 +1,156 @@
1
+ # encoding: utf-8
2
+ require "denrei/version"
3
+ require 'tk'
4
+
5
+ module Denrei
6
+ #= Denrei Core
7
+ class Core
8
+ attr_accessor :title, :message
9
+ DENREI_TEMPLATE =<<-EOS
10
+ # encoding: utf-8
11
+ # ***title-settings***
12
+ # if you want to change defalt title "Denrei", comment out title_text and set your text
13
+ # title_text "title text"
14
+
15
+ # ***message-settings***
16
+ # if you want to change defalt message "Finish!!", comment out message_text and set your text
17
+ # message_text "message text"
18
+ EOS
19
+
20
+ def do_denrei
21
+ denrei = Denrei::Core.new
22
+
23
+ if $*[0] == "init"
24
+ denrei.init
25
+ else
26
+ denrei.read_denreifile
27
+ denrei.open
28
+ denrei.keep_tk
29
+ end
30
+ end
31
+
32
+ #== generate denreifile template
33
+ def init
34
+ File.open("./Denreifile", "w") {|f|f.puts DENREI_TEMPLATE}
35
+ end
36
+
37
+ #== read Denreifile
38
+ # read current directory's Denreifile file.
39
+ # if Denreifile is not exists, do nothing.
40
+ # if Denreifile is exists, set gui parameters by DenreiDSL.
41
+ def read_denreifile
42
+ set_default
43
+ return unless File.exists? "./Denreifile"
44
+ execute_denrei_dsl read_denreifile_source
45
+ end
46
+
47
+ #== OpenMessageDialog
48
+ def open
49
+ set_title_label
50
+ set_message_label
51
+ set_close_button get_tk_root
52
+ end
53
+
54
+ #== keep display GUI
55
+ def keep_tk
56
+ Tk.mainloop
57
+ end
58
+
59
+ private
60
+ def set_title_label
61
+ title = @title
62
+ TkLabel.new do
63
+ text title
64
+ font TkFont.new({
65
+ 'family' => 'times',
66
+ 'weight' => 'bold',
67
+ 'size' => 20,
68
+ 'slant' => 'italic'
69
+ })
70
+ width 20
71
+ height 2
72
+ bd 5
73
+ relief "groove"
74
+ pack
75
+ end
76
+ end
77
+
78
+ def set_message_label
79
+ message = @message
80
+ TkLabel.new do
81
+ text message
82
+ font TkFont.new({
83
+ 'family' => 'times',
84
+ 'weight' => 'bold',
85
+ 'size' => 20,
86
+ })
87
+ width 20
88
+ height 4
89
+ bd 5
90
+ relief "groove"
91
+ pack
92
+ end
93
+ end
94
+
95
+ def get_tk_root
96
+ TkRoot.new
97
+ end
98
+
99
+ def set_close_button(tk_root)
100
+ btn_OK = TkButton.new(tk_root) do
101
+ text "close"
102
+ width 10
103
+ focus
104
+ borderwidth 5
105
+ underline 0
106
+ state "normal"
107
+ cursor "hand2"
108
+ font TkFont.new('times 20 bold')
109
+ foreground "red"
110
+ activebackground "blue"
111
+ relief "raised"
112
+ command {exit}
113
+ pack("side" => "right", "padx"=> "50", "pady"=> "10")
114
+ end
115
+ end
116
+
117
+ def read_denreifile_source
118
+ File.open("./Denreifile") {|f|f.read}
119
+ end
120
+
121
+ def execute_denrei_dsl(source)
122
+ source.each_line do |line|
123
+ begin
124
+ eval line, binding
125
+ rescue => e
126
+ puts "invalid dsl = #{line}"
127
+ puts <<-EOS
128
+ you can use only these dsl
129
+
130
+ # this set dialog title
131
+ title_text "value"
132
+ # this set dialog message
133
+ message_text "value"
134
+ EOS
135
+ raise Denrei::DenreiDslError.new
136
+ exit
137
+ end
138
+ end
139
+ end
140
+
141
+ def set_default
142
+ @title = "Denrei"
143
+ @message = "Finish!!"
144
+ end
145
+
146
+ def title_text(title)
147
+ @title = title
148
+ end
149
+
150
+ def message_text(message)
151
+ @message = message
152
+ end
153
+ end
154
+
155
+ class DenreiDslError < StandardError;end
156
+ end
@@ -0,0 +1,3 @@
1
+ module Denrei
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,107 @@
1
+ # encoding: utf-8
2
+ require_relative "../lib/denrei"
3
+ require "spec_helper"
4
+
5
+ describe Denrei::Core do
6
+ cases_init = [
7
+ {
8
+ case_no: 1,
9
+ expected: Denrei::Core::DENREI_TEMPLATE
10
+ },
11
+ ]
12
+
13
+ cases_init.each do |c|
14
+ it "#init case_no=#{c[:case_no]} generate Denreifile" do
15
+ # given
16
+ denrei = Denrei::Core.new
17
+
18
+ # when
19
+ denrei.init
20
+
21
+ # then
22
+ actual = File.open("Denreifile") {|f|f.read}
23
+ expect(actual).to eq(c[:expected])
24
+ end
25
+ end
26
+
27
+ cases_set_default = [
28
+ {
29
+ case_no: 1,
30
+ expected: {title: "Denrei", message: "Finish!!"}
31
+ },
32
+ ]
33
+
34
+ cases_set_default.each do |c|
35
+ it "#set_default case_no=#{c[:case_no]} set set_default settings" do
36
+ # given
37
+ denrei = Denrei::Core.new
38
+
39
+ # when
40
+ denrei.method(:set_default).call
41
+
42
+ # then
43
+ c[:expected].each do |k, v|
44
+ actual = denrei.method(k).call
45
+ expect(actual).to eq(v)
46
+ end
47
+ end
48
+ end
49
+
50
+ EXECUTE_DENREI_DSL_VALID_INPUT =<<-EOS
51
+ title_text "title text"
52
+ message_text "message text"
53
+ EOS
54
+
55
+ EXECUTE_DENREI_DSL_ALL_COMMENT_INPUT =<<-EOS
56
+ # title_text "title text"
57
+ # message_text "message text"
58
+ EOS
59
+
60
+ EXECUTE_DENREI_DSL_INVALID_INPUT =<<-EOS
61
+ title_text_invalid "title text"
62
+ message_text "message text"
63
+ EOS
64
+
65
+ cases_execute_denrei_dsl = [
66
+ {
67
+ case_no: 1,
68
+ input: EXECUTE_DENREI_DSL_VALID_INPUT,
69
+ expected: {title: "title text", message: "message text"}
70
+ },
71
+ {
72
+ case_no: 2,
73
+ input: EXECUTE_DENREI_DSL_ALL_COMMENT_INPUT,
74
+ expected: {title: nil, message: nil}
75
+ },
76
+ {
77
+ case_no: 3,
78
+ input: EXECUTE_DENREI_DSL_INVALID_INPUT,
79
+ expected: {title: nil, message: nil},
80
+ have_error: true
81
+ },
82
+ ]
83
+
84
+ cases_execute_denrei_dsl.each do |c|
85
+ it "#execute_denrei_dsl case_no=#{c[:case_no]} set set_default settings" do
86
+ # given
87
+ denrei = Denrei::Core.new
88
+
89
+ # when
90
+ if c[:have_error]
91
+ lambda{denrei.method(:execute_denrei_dsl).call(c[:input])}.should raise_error(Denrei::DenreiDslError)
92
+ else
93
+ denrei.method(:execute_denrei_dsl).call(c[:input])
94
+ # then
95
+ c[:expected].each do |k, v|
96
+ actual = denrei.method(k).call
97
+ expect(actual).to eq(v)
98
+ end
99
+ end
100
+
101
+ end
102
+ end
103
+
104
+ after(:each) do
105
+ File.delete("Denreifile") if File.exists?("Denreifile")
106
+ end
107
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: denrei
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-11-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &26946000 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *26946000
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &26945748 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *26945748
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &26945424 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.14.1
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *26945424
47
+ description: Denrei shows Ruby/Tk-Dialog with your favorite titile & message.
48
+ email:
49
+ - tbpgr@tbpgr.jp
50
+ executables:
51
+ - denrei
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - .rspec
57
+ - Gemfile
58
+ - LICENSE.txt
59
+ - README.md
60
+ - Rakefile
61
+ - bin/denrei
62
+ - denrei.gemspec
63
+ - lib/denrei.rb
64
+ - lib/denrei/version.rb
65
+ - spec/denrei_spec.rb
66
+ - spec/spec_helper.rb
67
+ homepage: https://github.com/tbpgr/denrei
68
+ licenses:
69
+ - MIT
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 1.8.11
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Denrei shows Ruby/Tk-Dialog with your favorite titile & message.
92
+ test_files:
93
+ - spec/denrei_spec.rb
94
+ - spec/spec_helper.rb
95
+ has_rdoc: