shoes_date_picker 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c7477b397384b86f4f29390af3f56ae22b5d5c1a
4
+ data.tar.gz: 1e217fb4e7c4d2feefc5b96d9d8fd98f55713fdf
5
+ SHA512:
6
+ metadata.gz: bd5d139363b3a88488283ba74c685255fffe011ee491709b0493d1159b819edf717332d40daddadaa4c86d4f755c42cb529e88dec24110475f56bb7b405b1619
7
+ data.tar.gz: 87b7abd22365910b5905a385af8413ccc1d597f74981fa4bd3dd3d023e9cbabfd47d0a4dae5cf64b964a86be4343bd1309d6502700b863eb794286b9bd4afb96
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.6
4
+ before_install: gem install bundler -v 1.10.1
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shoes_date_picker.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Sebastjan Hribar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # ShoesDatePicker
2
+
3
+ ShoesDatePicker gem provides a date picker functionality for the shoes gui toolkit.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'shoes_date_picker'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install shoes_date_picker
20
+
21
+ ## Usage
22
+
23
+ 1. require 'shoes_date_picker'
24
+ 2. call the shoes_date_picker method and capture the selected date:
25
+ ```ruby
26
+ button "Select deadline" do
27
+ @deadline = shoes_datepicker
28
+ end
29
+ ```
30
+ Optionally, pass in the background color to the widget:
31
+ ```ruby
32
+ button "Select deadline" do
33
+ @deadline = shoes_datepicker(green)
34
+ end
35
+ ```
36
+ The deafult color is set to deepskyblue.
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+
42
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/shoes_date_picker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
47
+
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
52
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "shoes_date_picker"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,105 @@
1
+ require "shoes_date_picker/version"
2
+ require_relative 'shoes_date_picker/sdp_helpers.rb'
3
+ require 'date'
4
+
5
+ class ShoesDatepicker < Shoes::Widget
6
+ def initialize(color = deepskyblue)
7
+ window title: "Date picker", margin: 35, width: 210, height: 430 do
8
+ background color
9
+ @month = Time.now.month
10
+ @year = Time.now.year
11
+ @day = Time.now.day
12
+ @today = "#{@year}-#{@month}-#{@day}"
13
+ @no_of_days = set_no_days(@year, @month)
14
+ setup_month(@year, @month, @no_of_days)
15
+
16
+ @year_slot = stack margin_bottom: 5 do
17
+ para "Year: #{@year}", :align => "center"
18
+ end
19
+
20
+ @month_slot = stack margin_bottom: 5 do
21
+ para "Month: #{@month}", :align => "center"
22
+ end
23
+
24
+ @today_slot = flow do
25
+ button "#{@today}", margin_bottom: 15 do
26
+ @selected_date = @today
27
+ alert @selected_date
28
+ end
29
+ end
30
+
31
+ @year_buttons_slot = flow height: 60 do
32
+ para "Change year"
33
+
34
+ button "<" do
35
+ @year = @year - 1
36
+ @no_of_days = set_no_days(@year, @month)
37
+ draw_year_slot
38
+ @month = 1
39
+ setup_month(@year, @month, @no_of_days)
40
+ draw_month_slot
41
+ draw_days_slot
42
+ end
43
+
44
+ button ">" do
45
+ @year = @year + 1
46
+ @no_of_days = set_no_days(@year, @month)
47
+ draw_year_slot
48
+ @month = 1
49
+ setup_month(@year, @month, @no_of_days)
50
+ draw_month_slot
51
+ draw_days_slot
52
+ end
53
+ end
54
+
55
+ @month_buttons_slot = flow height: 60 do
56
+ para "Change month"
57
+
58
+ button "<" do
59
+ @month = @month - 1
60
+ if @month == 0
61
+ @month = 12
62
+ @year = @year - 1
63
+ @no_of_days = set_no_days(@year, @month)
64
+ setup_month(@year, @month, @no_of_days)
65
+ draw_month_slot
66
+ draw_year_slot
67
+ draw_days_slot
68
+
69
+ else
70
+ @no_of_days = set_no_days(@year, @month)
71
+ setup_month(@year, @month, @no_of_days)
72
+ draw_month_slot
73
+ draw_year_slot
74
+ draw_days_slot
75
+ end
76
+ end
77
+
78
+ button ">" do
79
+ @month = @month + 1
80
+ if @month == 13
81
+ @month = 1
82
+ @year = @year + 1
83
+ @no_of_days = set_no_days(@year, @month)
84
+ setup_month(@year, @month, @no_of_days)
85
+ draw_month_slot
86
+ draw_year_slot
87
+ draw_days_slot
88
+ else
89
+ @no_of_days = set_no_days(@year, @month)
90
+ setup_month(@year, @month, @no_of_days)
91
+ draw_month_slot
92
+ draw_year_slot
93
+ draw_days_slot
94
+ end
95
+ end
96
+ end
97
+
98
+ @days_slot = flow do
99
+ draw_days(@no_of_days)
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+
@@ -0,0 +1,106 @@
1
+ def set_no_days(year, month)
2
+ case month
3
+ when 4 then 1..30
4
+ when 6 then 1..30
5
+ when 9 then 1..30
6
+ when 11 then 1..30
7
+ when 2 then 1..28
8
+ when 2 && Date.gregorian_leap?(year) then 1..29
9
+ else 1..31
10
+ end
11
+ end
12
+
13
+ def setup_month(year, month, no_of_days)
14
+ @all_days_in_month = Array.new(0)
15
+ first_day_name = Date.parse("#{year}-#{month}-01").strftime("%A")
16
+
17
+ case first_day_name
18
+ when "Monday" then
19
+ no_of_days.each {|day| @all_days_in_month << day }
20
+ when "Tuesday" then
21
+ @all_days_in_month[0] = nil
22
+ no_of_days.each {|day| @all_days_in_month << day }
23
+ when "Wednesday" then
24
+ @all_days_in_month[0] = nil
25
+ @all_days_in_month[1] = nil
26
+ no_of_days.each {|day| @all_days_in_month << day }
27
+ when "Thursday" then
28
+ @all_days_in_month[0] = nil
29
+ @all_days_in_month[1] = nil
30
+ @all_days_in_month[2] = nil
31
+ no_of_days.each {|day| @all_days_in_month << day }
32
+ when "Friday" then
33
+ @all_days_in_month[0] = nil
34
+ @all_days_in_month[1] = nil
35
+ @all_days_in_month[2] = nil
36
+ @all_days_in_month[3] = nil
37
+ no_of_days.each {|day| @all_days_in_month << day }
38
+ when "Saturday" then
39
+ @all_days_in_month[0] = nil
40
+ @all_days_in_month[1] = nil
41
+ @all_days_in_month[2] = nil
42
+ @all_days_in_month[3] = nil
43
+ @all_days_in_month[4] = nil
44
+ no_of_days.each {|day| @all_days_in_month << day }
45
+ when "Sunday" then
46
+ @all_days_in_month[0] = nil
47
+ @all_days_in_month[1] = nil
48
+ @all_days_in_month[2] = nil
49
+ @all_days_in_month[3] = nil
50
+ @all_days_in_month[4] = nil
51
+ @all_days_in_month[5] = nil
52
+ no_of_days.each {|day| @all_days_in_month << day }
53
+ end
54
+ end
55
+
56
+ def draw_days (no_of_days)
57
+ flow width: 210, height: 50 do
58
+ stack width: 30, height: 30 do
59
+ para "Mo", align: "center"
60
+ end
61
+ stack width: 30, height: 30 do
62
+ para "Tu", align: "center"
63
+ end
64
+ stack width: 30, height: 30 do
65
+ para "We", align: "center"
66
+ end
67
+ stack width: 30, height: 30 do
68
+ para "Th", align: "center"
69
+ end
70
+ stack width: 30, height: 30 do
71
+ para "Fr", align: "center"
72
+ end
73
+ stack width: 30, height: 30 do
74
+ para "Sa", align: "center"
75
+ end
76
+ stack width: 30, height: 30 do
77
+ para "Su", align: "center"
78
+ end
79
+
80
+ @all_days_in_month.each do |day|
81
+ stack width: 30, height: 30 do
82
+ unless day == nil
83
+ button day.to_s, width: 30, height: 30 do
84
+ @selected_date = "#{@year}-#{@month}-#{day.to_s}"
85
+ alert @selected_date
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ def draw_year_slot
94
+ @year_slot.clear
95
+ @year_slot.append {para "Year: #{@year}", :align => "center"}
96
+ end
97
+
98
+ def draw_month_slot
99
+ @month_slot.clear
100
+ @month_slot.append {para "Month: #{@month}", :align => "center"}
101
+ end
102
+
103
+ def draw_days_slot
104
+ @days_slot.clear
105
+ @days_slot.append {draw_days(@no_of_days)}
106
+ end
@@ -0,0 +1,3 @@
1
+ module ShoesDatePicker
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'shoes_date_picker/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "shoes_date_picker"
8
+ spec.version = ShoesDatePicker::VERSION
9
+ spec.authors = ["Sebastjan Hribar"]
10
+ spec.email = ["sebastjan.hribar@gmail.com"]
11
+
12
+ spec.summary = %q{A date picker for the shoes GUI toolkit.}
13
+ spec.description = %q{}
14
+ spec.homepage = "https://github.com/sebastjan-hribar/shoes_date_picker"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "minitest"
33
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shoes_date_picker
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Sebastjan Hribar
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: ''
56
+ email:
57
+ - sebastjan.hribar@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/shoes_date_picker.rb
72
+ - lib/shoes_date_picker/sdp_helpers.rb
73
+ - lib/shoes_date_picker/version.rb
74
+ - shoes_date_picker.gemspec
75
+ homepage: https://github.com/sebastjan-hribar/shoes_date_picker
76
+ licenses:
77
+ - MIT
78
+ metadata:
79
+ allowed_push_host: https://rubygems.org
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.3
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: A date picker for the shoes GUI toolkit.
100
+ test_files: []