rails_fancies 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +23 -0
- data/app/__init__.py +0 -0
- data/app/assets/__init__.py +0 -0
- data/app/assets/stylesheets/__init__.py +0 -0
- data/config/__init__.py +0 -0
- data/config/initializers/__init__.py +0 -0
- data/lib/rails_fancies.rb +5 -0
- data/lib/rails_fancies/fancy_faq_helper.rb +42 -0
- data/lib/rails_fancies/fancy_weekly_calendar_helper.rb +105 -0
- data/lib/rails_fancies/railtie.rb +10 -0
- data/lib/rails_fancies/version.rb +3 -0
- data/lib/tasks/rails_fancies_tasks.rake +4 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 77bf1a7e3931ade84562f9d0eb940c153dd71dd6
|
4
|
+
data.tar.gz: 52f50893bbcd7d392ac9541e7f101a14e1ccf8de
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 71ac93b56665f4f984f4922991d5972453889557964b30faedeee75c5db8f1804497e08c836a585a89ddb78527ae27e79f4e93b1023a863c6cb819424992a4ee
|
7
|
+
data.tar.gz: 322095334cbf9c56c0a5c273b8454c9271c5f38673f27a17f387f94cba7a732c488191fd7670896f03adc65461ecb6e8fdf77f857b3db1667c4820632a3a74db
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Chris Drane
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'RailsFancies'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
data/app/__init__.py
ADDED
File without changes
|
File without changes
|
File without changes
|
data/config/__init__.py
ADDED
File without changes
|
File without changes
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module RailsFancies
|
2
|
+
module FancyFaqHelper
|
3
|
+
def fancy_faq(&block)
|
4
|
+
renderer = FancyFaqHelper::FancyFaq.new(self, {})
|
5
|
+
capture(renderer, &block)
|
6
|
+
end
|
7
|
+
|
8
|
+
class FancyFaq < Struct.new(:view, :question_list)
|
9
|
+
delegate :content_tag, to: :view
|
10
|
+
def question(name, text)
|
11
|
+
add_to_list question_list, name, text
|
12
|
+
content_tag :div, class: 'faq_question' do
|
13
|
+
content_tag :a, href: "##{name}" do
|
14
|
+
"#{text}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def answer(name, text)
|
20
|
+
if question_list[name.to_sym].present?
|
21
|
+
content_tag :div, class: 'faq_answer' do
|
22
|
+
content_tag(:a, '', name: "#{name}") +
|
23
|
+
content_tag(:div, question_list[name.to_sym], class: 'faq_answer_heading') +
|
24
|
+
content_tag(:p, "#{text}", class: 'faq_answers')
|
25
|
+
end
|
26
|
+
else
|
27
|
+
raise "No question was found with a name of :#{name}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def add_to_list(list, name, text)
|
34
|
+
if list[name].present?
|
35
|
+
raise "A question with the name of :#{name} already exists."
|
36
|
+
else
|
37
|
+
list[name] = text
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# basis for this is http://railscasts.com/episodes/213-calendars-revised
|
2
|
+
module RailsFancies
|
3
|
+
module FancyWeeklyCalendarHelper
|
4
|
+
def fancy_weekly_calendar(date = Date.today, &block)
|
5
|
+
Calendar.new(self, date, block).table
|
6
|
+
end
|
7
|
+
def slot_available?(date, slot_num)
|
8
|
+
Calendar.available?(date, slot_num)
|
9
|
+
end
|
10
|
+
|
11
|
+
class Calendar < Struct.new(:view, :date, :callback)
|
12
|
+
HEADER = %w[Time Monday Tuesday Wednesday Thursday Friday Saturday Sunday]
|
13
|
+
START_DAY = :monday
|
14
|
+
SLOT_DURATION = 30.minutes
|
15
|
+
SLOT_START = 17
|
16
|
+
SLOT_END = 31
|
17
|
+
|
18
|
+
delegate :content_tag, to: :view
|
19
|
+
|
20
|
+
def table
|
21
|
+
content_tag :table, class: "calendar" do
|
22
|
+
header + weekly_rows
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def header
|
27
|
+
content_tag :tr do
|
28
|
+
HEADER.map { |day| content_tag :th, day }.join.html_safe
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def weekly_rows
|
33
|
+
slot_num = SLOT_START - 1
|
34
|
+
weekly_slots.map do |week|
|
35
|
+
slot_num += 1
|
36
|
+
content_tag :tr do
|
37
|
+
row = [slot_cell(slot_num)]
|
38
|
+
row += week.map { |day| day_slot_cell(day,slot_num) }
|
39
|
+
row.join.html_safe
|
40
|
+
end
|
41
|
+
end.join.html_safe
|
42
|
+
end
|
43
|
+
|
44
|
+
def slot_cell(slot_num)
|
45
|
+
content_tag :td do
|
46
|
+
slot_num_to_time(slot_num)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def slot_num_to_time(slot_num)
|
51
|
+
start_time = slot_start_time + (slot_num - SLOT_START) * SLOT_DURATION
|
52
|
+
Time.at(start_time).utc.strftime("%H:%M")
|
53
|
+
end
|
54
|
+
|
55
|
+
def slot_start_time
|
56
|
+
SLOT_START * SLOT_DURATION
|
57
|
+
end
|
58
|
+
|
59
|
+
def day_slot_cell(day, slot_num)
|
60
|
+
content_tag :td, view.capture(day, slot_num, &callback), class: day_classes(day, slot_num)
|
61
|
+
end
|
62
|
+
|
63
|
+
def day_classes(day, slot_num)
|
64
|
+
classes = []
|
65
|
+
classes << 'today' if day == Date.today
|
66
|
+
classes << 'notmonth' if day.month != date.month
|
67
|
+
classes << 'available' if Calendar.available?(day, slot_num)
|
68
|
+
classes.empty? ? nil : classes.join(' ')
|
69
|
+
end
|
70
|
+
|
71
|
+
def weekly_slots
|
72
|
+
first = date.beginning_of_week(START_DAY)
|
73
|
+
last = date.end_of_week(START_DAY)
|
74
|
+
weeks = []
|
75
|
+
week = (first..last).to_a
|
76
|
+
slots = (SLOT_START..SLOT_END)
|
77
|
+
slots.each do
|
78
|
+
weeks << week
|
79
|
+
end
|
80
|
+
weeks
|
81
|
+
end
|
82
|
+
|
83
|
+
def slots
|
84
|
+
(SLOT_START..SLOT_END)
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
def self.available?(day, slot_num)
|
89
|
+
day_sym = day.strftime("%A").downcase.to_sym
|
90
|
+
slots = Calendar.availability_hash[day_sym]
|
91
|
+
slot_num.in? slots if slots.present?
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.availability_hash
|
95
|
+
{ monday: [17, 18, 19, 20, 21, 24, 25, 26, 27],
|
96
|
+
tuesday: [17, 18, 19, 20, 21, 24, 25, 26, 27],
|
97
|
+
wednesday: [17, 18, 19, 20, 21],
|
98
|
+
thursday: [17, 18, 19, 20, 21, 24, 25, 26, 27],
|
99
|
+
friday: [17, 18, 19, 20, 21, 24, 25, 26, 27],
|
100
|
+
sunday: [24, 25, 26, 27]
|
101
|
+
}
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rails_fancies/fancy_faq_helper'
|
2
|
+
require 'rails_fancies/fancy_weekly_calendar_helper'
|
3
|
+
module RailFancies
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
initializer "rails_fancies" do
|
6
|
+
ActiveSupport.on_load( :action_view ){ include RailsFancies::FancyFaqHelper }
|
7
|
+
ActiveSupport.on_load( :action_view ){ include RailsFancies::FancyWeeklyCalendarHelper }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_fancies
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Obromios
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: better_errors
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: binding_of_caller
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sassc-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: meta_request
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Most rails helpers tend to be tightly focused on placing a single element
|
112
|
+
on a page, like a link or an image tag. Rails Fancies is for helpers that are more
|
113
|
+
complex and can form the basis of complete a web page. The inaugural helper is a
|
114
|
+
FAQ helper.
|
115
|
+
email:
|
116
|
+
- obromios@gmail.com
|
117
|
+
executables: []
|
118
|
+
extensions: []
|
119
|
+
extra_rdoc_files: []
|
120
|
+
files:
|
121
|
+
- MIT-LICENSE
|
122
|
+
- Rakefile
|
123
|
+
- app/__init__.py
|
124
|
+
- app/assets/__init__.py
|
125
|
+
- app/assets/stylesheets/__init__.py
|
126
|
+
- config/__init__.py
|
127
|
+
- config/initializers/__init__.py
|
128
|
+
- lib/rails_fancies.rb
|
129
|
+
- lib/rails_fancies/fancy_faq_helper.rb
|
130
|
+
- lib/rails_fancies/fancy_weekly_calendar_helper.rb
|
131
|
+
- lib/rails_fancies/railtie.rb
|
132
|
+
- lib/rails_fancies/version.rb
|
133
|
+
- lib/tasks/rails_fancies_tasks.rake
|
134
|
+
homepage: https://github.com/obromios/rails_fancies
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.4.6
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Rails Fancies is an open source project to develop some fanciful Ruby on
|
158
|
+
Rails helpers.
|
159
|
+
test_files: []
|