eots 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +33 -0
- data/app/assets/javascripts/eots/application.js +13 -0
- data/app/assets/stylesheets/eots/application.css +15 -0
- data/app/controllers/application_controller.rb +5 -0
- data/app/controllers/eots/eots_controller.rb +33 -0
- data/app/helpers/eots/application_helper.rb +4 -0
- data/app/mailers/eots/mailer.rb +11 -0
- data/app/models/eots/email.rb +54 -0
- data/app/models/eots/email_kind.rb +89 -0
- data/app/models/eots/field.rb +71 -0
- data/app/views/eots/eots/_field.html.erb +3 -0
- data/app/views/eots/eots/show.html.erb +17 -0
- data/app/views/layouts/eots/application.html.erb +14 -0
- data/config/routes.rb +4 -0
- data/lib/eots.rb +57 -0
- data/lib/eots/engine.rb +12 -0
- data/lib/eots/version.rb +3 -0
- data/lib/tasks/eots_tasks.rake +4 -0
- data/spec/dummy/Gemfile +9 -0
- data/spec/dummy/Gemfile.lock +129 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +29 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +38 -0
- data/spec/dummy/config/environments/production.rb +76 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +9 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/log/test.log +601 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/spec/feature/end_to_end_spec.rb +84 -0
- data/spec/dummy/spec/feature/show_spec.rb +51 -0
- data/spec/dummy/spec/rails_helper.rb +59 -0
- data/spec/dummy/spec/spec_helper.rb +92 -0
- data/spec/dummy/spec/unit/email_html_spec.rb +49 -0
- data/spec/dummy/spec/unit/email_kind_spec.rb +209 -0
- data/spec/dummy/spec/unit/eots_spec.rb +11 -0
- data/spec/dummy/spec/unit/field_spec.rb +63 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/0RCX1g6aQPCN1X94TtJN8MINVXsqaHH14bKVfzjGXNY.cache +2 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/3ntMIa1diZ9pMuINbYDhyA2U4Hy6mNMNAxYbuox4hzk.cache +0 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/5Lly_CA8DZvPhQV2jDQx-Y6P_y3Ygra9t5jfSlGhHDA.cache +2 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/6Uj58Wch32M5GXpzryd2sADR_AALEvJwfJiGmj_StTE.cache +1 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/9JaB_YWzSKr6UPA8QSlW6uh_xtdAzgqr0PWKb7zOs-Q.cache +0 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/Ac69TcV6FfXabo8e-rphL_TeeNz5rwUFbPmQDyhT5VM.cache +0 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/F69YPXIf2edO_SGtxxpMcg_zMQIIfyWWZApPCP0ZPJg.cache +0 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/FLsx8bQSMDiBGj2js-NSZ7l8_T3YLZGRIBdhBAbdLQ8.cache +1 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/FWQ8Gy0SYezyHnYNSOQO00ERhBv_XqjH2AQo89gHsQU.cache +3 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/G0X1ZoxQfZElvSVKrJq8f6JSYoq7A5AlacgMOUS3_fA.cache +0 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/I8QyyWPde7gdCifUNc_UuVuuuy7P-N_wWaOlB2F0-wg.cache +1 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/LgjfJkyKstIrcG85QEALUQijdPUhSDMuahnhgT0tuGk.cache +1 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/NODTcGA3KAs_UNrXeUK7ua07e5TGLeiopgYkZF1YrAM.cache +1 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/NpodKRyMyfN-hYvDMY8Dqfrm9ZRIKIaluMViE2x3eK8.cache +1 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/OI6uxGcnsKavdWTtwDAasU3wPx8QXhzBgV0X2n1KjMQ.cache +3 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/Q0tr3vYpD7iA7QH1Fa46Z6jdSPaC_0ArYacaDmtL0oU.cache +0 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/RyuuLTTyuJMnhQpPyRYT-GIISGOG2PtJcD0EYIEQ51Q.cache +0 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/TmSYCXUWBNTXkBJl68gF3_TW4nrXB5e7zOrmfeduwrY.cache +0 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/VfRiaQoJWN9kYydt6-bgXvip-ETv7oFQ4UXjl0Yq_ic.cache +0 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/aMShh1T9yFNRIiUmnPVKbZkFGoG4MHccQ1MKCm38JSU.cache +1 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/c0dA8KQChF9bJJpBalejx2C26lRB4Zyx6gJOBmSATXs.cache +1 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/davW6NYx79KwUJhyi6Tnvxaj34483QJUZK0Cnfabg8k.cache +1 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/fU6DY9gYGBAmRXCUe_roiS2dqcxj_hX_ErldQFZiHtc.cache +1 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/hKvyvQHo0NIwRbSneYEgEyTzpYyDujdN-lGcWo5kAhw.cache +0 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/hN0aXCmRyzra8g0vx1ao03QPCs3hDg5BzOiDE0EJuG0.cache +3 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache +3 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/p7tkUMsi0MxSMjSoU48CGF5c2vKG1US-bReLTTf7cVU.cache +1 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache +2 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/pIl8QzN2vLr_cjBd9pmYj8LoHUvelAsvBnq3bjKjWtU.cache +1 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/pwUm81zFbRiD7SMT3oZbuyQxtTma9A6KRDGp5bngaxs.cache +1 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/svuNuIM179iBV9Fg_Sdhn7O94pjChsCERObyI5nlhzo.cache +2 -0
- data/spec/dummy/tmp/cache/sprockets/v3.0/v1AfZrsv4fWdl9mSy0ABU7MFx0JrLSeXIgKoo_7-kbE.cache +1 -0
- metadata +246 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 382988daf11034b395b9733a59aa22560517bbdb
|
4
|
+
data.tar.gz: c57aef8c58c5883618e327386d60995e640053a3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ef40145fe2ae2597acc421d7b07949423aa2a6f8fd3478d238848a07637a1a5eaa6e75e58c7ad6abdb32ed03a207a6ebbd1a29817c5de36ea5156caf0260ebd1
|
7
|
+
data.tar.gz: 706caef30f3a11d3f81cb33ec2b83e20a8ec3735517941fef8a44489557ea0f377e1d8bb976c62c30a7b274f13d251ac25f21510225ecf9f2a288f4bb7c0afa6
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Dave Aronson
|
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,33 @@
|
|
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 = 'EOTS'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
19
|
+
load 'rails/tasks/engine.rake'
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
|
27
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each { |f| load f }
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
|
32
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
33
|
+
task :default => :spec
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module EOTS
|
2
|
+
|
3
|
+
class EOTSController < ApplicationController
|
4
|
+
|
5
|
+
include Rails.application.routes.url_helpers
|
6
|
+
|
7
|
+
before_action :get_view_context
|
8
|
+
|
9
|
+
def show
|
10
|
+
# TODO: make this just get the KIND
|
11
|
+
@kind = EOTS::find_kind(params[:kind])
|
12
|
+
render :show
|
13
|
+
end
|
14
|
+
|
15
|
+
def send_email
|
16
|
+
@email, errs = EOTS::Email.create_from_params(params)
|
17
|
+
if errs && errs.any?
|
18
|
+
flash.now[:alert] = errs.join("\n")
|
19
|
+
redirect_to request.url, request.params
|
20
|
+
end
|
21
|
+
EOTS::Mailer.email(@email).deliver_now
|
22
|
+
redirect_to root_path, notice: 'Your email has been sent'
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def get_view_context
|
28
|
+
@view_context = view_context
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class EOTS::Email # an instance, as opposed to the whole kind
|
2
|
+
|
3
|
+
attr_reader :kind, :values
|
4
|
+
|
5
|
+
EOTS::STANDARD_FIELDS.each do |field|
|
6
|
+
define_method(field) { kind.send field || values[:name] }
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(kind, values={})
|
10
|
+
@kind = kind
|
11
|
+
@values = values.dup
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.create_from_params(params)
|
15
|
+
kind_name = params[:kind]
|
16
|
+
kind = EOTS::find_kind(kind_name)
|
17
|
+
unless kind
|
18
|
+
raise(EOTS::EmailKind::NotFoundError,
|
19
|
+
"Unknown email kind '#{kind_name}': #{list}")
|
20
|
+
end
|
21
|
+
# TEMPORARY KLUGE, UNTIL I MAKE THE VALUES A SUB-HASH:
|
22
|
+
values = params.dup
|
23
|
+
%w(action controller authenticity_token commit kind utf8).each { |k| values.delete k }
|
24
|
+
check_value_names(values, kind) if values
|
25
|
+
self.new(kind, values)
|
26
|
+
end
|
27
|
+
|
28
|
+
def body
|
29
|
+
parts = [kind.name.titleize]
|
30
|
+
kind.form_fields.values.flatten.each do |field|
|
31
|
+
parts << "> #{"* " if field.html_options[:required]}#{field.label}"
|
32
|
+
reply = values[field.name]
|
33
|
+
parts << (reply.present? ? reply : "(not answered)")
|
34
|
+
end
|
35
|
+
parts.join("\n\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
def from
|
39
|
+
kind.from || "\"#{values[:name]}\" <#{values[:email]}>"
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def self.check_value_names(values, kind)
|
45
|
+
field_names = kind.form_fields.values.flatten.map &:name
|
46
|
+
errs = values.keys.reject { |key| field_names.include? key }
|
47
|
+
if errs.any?
|
48
|
+
list = errs.map { |e| "'#{e}'" }.join(", ")
|
49
|
+
raise(EOTS::EmailKind::FieldNotFoundError,
|
50
|
+
"Field(s) not found on email kind '#{kind.name}': #{list}")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
class EOTS::EmailKind
|
2
|
+
|
3
|
+
AlreadyDefinedError = Class.new(RuntimeError)
|
4
|
+
FieldNotFoundError = Class.new(RuntimeError)
|
5
|
+
NotFoundError = Class.new(RuntimeError)
|
6
|
+
|
7
|
+
attr_accessor :fields, :name, :parent, :options
|
8
|
+
|
9
|
+
EOTS::STANDARD_FIELDS.each do |field|
|
10
|
+
attr_writer field
|
11
|
+
define_method field do
|
12
|
+
instance_variable_get("@#{field}".to_sym) || parent.try(field)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
EOTS::NON_FIELD_ITEMS.each { |field| attr_accessor field }
|
17
|
+
|
18
|
+
def initialize(name, parent, options={})
|
19
|
+
@name = name.to_s
|
20
|
+
opts = options.dup
|
21
|
+
@fields = {}
|
22
|
+
(EOTS::STANDARD_FIELDS + EOTS::NON_FIELD_ITEMS).each do |field|
|
23
|
+
instance_variable_set("@#{field}".to_sym, opts.delete(field))
|
24
|
+
end
|
25
|
+
@options = opts # what's left
|
26
|
+
@parent = parent
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_field(field_name, label, field_options)
|
30
|
+
field_name = field_name.to_s
|
31
|
+
if @fields[field_name]
|
32
|
+
raise(EOTS::Field::AlreadyDefinedError,
|
33
|
+
"Field #{field_name} is already defined on email kind #{self.name}")
|
34
|
+
end
|
35
|
+
@form_fields = nil # invalidate it... can't reach down to children tho :-(
|
36
|
+
# also return the new field, in case caller wants to do something with it
|
37
|
+
@fields[field_name] = EOTS::Field.new(field_name, label, field_options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def body_fields
|
41
|
+
form_fields[:body]
|
42
|
+
end
|
43
|
+
|
44
|
+
def footer_fields
|
45
|
+
form_fields[:footer]
|
46
|
+
end
|
47
|
+
|
48
|
+
def footers
|
49
|
+
below = @parent ? @parent.footers : []
|
50
|
+
([footer] + below).compact
|
51
|
+
end
|
52
|
+
|
53
|
+
def form_fields
|
54
|
+
unless @form_fields
|
55
|
+
@form_fields = @parent ? @parent.form_fields : { header: [], body: [], footer: [] }
|
56
|
+
mine = fields.values.group_by &:section
|
57
|
+
@form_fields[:header] += mine[:header] if mine[:header]
|
58
|
+
@form_fields[:body] += mine[:body] if mine[:body]
|
59
|
+
@form_fields[:footer] = mine[:footer] + @form_fields[:footer] if mine[:footer]
|
60
|
+
end
|
61
|
+
@form_fields.dup # dup so children don't add stuff
|
62
|
+
end
|
63
|
+
|
64
|
+
def header_fields
|
65
|
+
form_fields[:header]
|
66
|
+
end
|
67
|
+
|
68
|
+
def headers
|
69
|
+
above = @parent ? @parent.headers : []
|
70
|
+
(above << header).compact
|
71
|
+
end
|
72
|
+
|
73
|
+
def html_footers
|
74
|
+
wrap_in_html_paragraphs(footers)
|
75
|
+
end
|
76
|
+
|
77
|
+
def html_headers
|
78
|
+
wrap_in_html_paragraphs(headers)
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def wrap_in_html_paragraphs(stuff)
|
84
|
+
if stuff.any?
|
85
|
+
"#{stuff.map { |thing| "<p>#{thing}</p>" }.join("\n")}<br/>".html_safe
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class EOTS::Field
|
2
|
+
|
3
|
+
AlreadyDefinedError = Class.new(RuntimeError)
|
4
|
+
InvalidSectionError = Class.new(RuntimeError)
|
5
|
+
|
6
|
+
attr_reader :name, :label, :caption, :section, :html_options
|
7
|
+
|
8
|
+
def initialize(name, label, options={})
|
9
|
+
@name = name.to_s
|
10
|
+
@label = label
|
11
|
+
opts = options.dup
|
12
|
+
@caption = opts.delete(:caption)
|
13
|
+
@section = opts.delete(:section) || :body
|
14
|
+
unless [:header, :body, :footer].include? @section
|
15
|
+
raise(InvalidSectionError,
|
16
|
+
"Invalid section '#{@section}' -- must be :header, :body, or :footer")
|
17
|
+
end
|
18
|
+
apply_defaults(opts)
|
19
|
+
@html_options = opts
|
20
|
+
end
|
21
|
+
|
22
|
+
def html(form)
|
23
|
+
result = form.label_tag(name, "#{"* " if html_options[:required]}#{label}")
|
24
|
+
type = html_options[:type]
|
25
|
+
if type.to_sym == :checkbox # to_sym 'cuz it could be string or symbol
|
26
|
+
result << form.content_tag(:span, " ") # just to provide a spacer
|
27
|
+
opts = html_options.dup
|
28
|
+
checked = opts.delete :checked
|
29
|
+
result << form.check_box_tag(name, name, checked, opts)
|
30
|
+
else
|
31
|
+
result << form.tag(:br)
|
32
|
+
tag = "#{type}_field_tag".gsub("textarea_field", "text_area").to_sym
|
33
|
+
result << form.send(tag, name, nil, html_options)
|
34
|
+
end
|
35
|
+
if caption
|
36
|
+
result << form.tag(:br)
|
37
|
+
result << form.content_tag(:small, caption)
|
38
|
+
end
|
39
|
+
result
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def apply_defaults(opts)
|
45
|
+
opts[:type] ||= :text
|
46
|
+
case opts[:type].to_sym
|
47
|
+
when :checkbox
|
48
|
+
apply_check_box_defaults(opts)
|
49
|
+
when :text, :email
|
50
|
+
apply_text_defaults(opts)
|
51
|
+
when :text_area
|
52
|
+
apply_text_area_defaults(opts)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def apply_check_box_defaults(opts)
|
57
|
+
opts[:checked] = false unless opts.has_key?(:checked)
|
58
|
+
end
|
59
|
+
|
60
|
+
def apply_text_area_defaults(opts)
|
61
|
+
cols = (opts[:cols] ||= 60)
|
62
|
+
rows = (opts[:rows] ||= 5)
|
63
|
+
opts[:maxlength] ||= cols * rows
|
64
|
+
end
|
65
|
+
|
66
|
+
def apply_text_defaults(opts)
|
67
|
+
size = (opts[:size] ||= 60)
|
68
|
+
opts[:maxlength] ||= size
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<br/>
|
2
|
+
|
3
|
+
<%= @kind.html_headers %>
|
4
|
+
|
5
|
+
<%= form_tag(request.url) do %>
|
6
|
+
|
7
|
+
<%= render :partial => "field", :collection => @kind.header_fields %>
|
8
|
+
<%= render :partial => "field", :collection => @kind.body_fields %>
|
9
|
+
<%= render :partial => "field", :collection => @kind.footer_fields %>
|
10
|
+
|
11
|
+
<%= submit_tag "Send" %>
|
12
|
+
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
<br/>
|
16
|
+
|
17
|
+
<%= @kind.html_footers %>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>EOTS</title>
|
5
|
+
<%= stylesheet_link_tag "eots/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "eots/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
data/lib/eots.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require "eots/engine"
|
2
|
+
|
3
|
+
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
4
|
+
inflect.acronym "EOTS"
|
5
|
+
end
|
6
|
+
|
7
|
+
module EOTS
|
8
|
+
|
9
|
+
# standard fields you'd see in any email
|
10
|
+
STANDARD_FIELDS = %i(from to reply_to cc bcc subject)
|
11
|
+
|
12
|
+
# need a better short name for this... stuff we want to let the dev pass in
|
13
|
+
# the email_kind declaration, either as an option or in the block, other than
|
14
|
+
# fields....
|
15
|
+
NON_FIELD_ITEMS = %i(header footer)
|
16
|
+
|
17
|
+
def self.email_kind(name, options={}, &block)
|
18
|
+
kind = create_email_kind(name, options)
|
19
|
+
@@kind_stack.push kind
|
20
|
+
yield if block_given?
|
21
|
+
@@kind_stack.pop
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.field(name, label, options={})
|
25
|
+
@@kind_stack.last.add_field(name, label, options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.find_kind(kind_name)
|
29
|
+
kind = @@kind_hash[kind_name]
|
30
|
+
unless kind
|
31
|
+
raise(EOTS::EmailKind:: NotFoundError,
|
32
|
+
"Unknown email kind '#{kind_name}'")
|
33
|
+
end
|
34
|
+
kind
|
35
|
+
end
|
36
|
+
|
37
|
+
(STANDARD_FIELDS + NON_FIELD_ITEMS).each do |field|
|
38
|
+
define_singleton_method field do |value|
|
39
|
+
@@kind_stack.last.send "#{field}=".to_sym, value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
# declare/init innards this way so we can reset them in tests
|
46
|
+
def self.reset
|
47
|
+
@@kind_stack = []
|
48
|
+
@@kind_hash = {}
|
49
|
+
end
|
50
|
+
self.reset
|
51
|
+
|
52
|
+
def self.create_email_kind(name, options)
|
53
|
+
raise(EmailKind::AlreadyDefinedError, "Email kind #{name} is already defined") if @@kind_hash[name]
|
54
|
+
@@kind_hash[name] = EOTS::EmailKind.new(name, @@kind_stack.last, options)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|