instedd-pigeon 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +25 -0
- data/.rvmrc +1 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +140 -0
- data/Rakefile +1 -0
- data/app/assets/images/pigeon/android_local_gateway_preview.png +0 -0
- data/app/assets/images/pigeon/android_local_gateway_qr.png +0 -0
- data/app/assets/images/pigeon/other_local_gateway_preview.png +0 -0
- data/app/assets/javascripts/pigeon/qst-server-wizard.js.coffee +58 -0
- data/app/assets/javascripts/pigeon/template.js.coffee +43 -0
- data/app/assets/javascripts/pigeon/twitter-template.js.coffee +38 -0
- data/app/assets/javascripts/pigeon/wizard.js.coffee +95 -0
- data/app/assets/javascripts/pigeon.js +2 -0
- data/app/assets/stylesheets/pigeon.css.sass +13 -0
- data/app/controllers/pigeon/twitter_controller.rb +44 -0
- data/app/helpers/.gitkeep +0 -0
- data/app/helpers/pigeon/channel_helper.rb +93 -0
- data/app/helpers/pigeon/renderer/base.rb +172 -0
- data/app/helpers/pigeon/renderer/channel_renderer.rb +58 -0
- data/app/helpers/pigeon/renderer.rb +8 -0
- data/app/helpers/pigeon/tag_helper.rb +26 -0
- data/app/helpers/pigeon/template_helper.rb +20 -0
- data/app/helpers/pigeon/text_helper.rb +16 -0
- data/app/models/.gitkeep +0 -0
- data/app/models/pigeon/channel.rb +220 -0
- data/app/models/pigeon/channel_attribute.rb +64 -0
- data/app/models/pigeon/channel_schema.rb +113 -0
- data/app/models/pigeon/nested_attribute.rb +23 -0
- data/app/models/pigeon/nested_scopes.rb +34 -0
- data/app/models/pigeon/nuntium_channel.rb +92 -0
- data/app/models/pigeon/verboice_channel.rb +82 -0
- data/app/views/pigeon/twitter/callback.html.erb +6 -0
- data/config/routes.rb +4 -0
- data/config/schemas/nuntium/nuntium.yml +210 -0
- data/config/schemas/nuntium/qst-server.yml +180 -0
- data/config/schemas/nuntium/twitter.yml +56 -0
- data/config/schemas/verboice/verboice.yml +76 -0
- data/lib/pigeon/engine.rb +30 -0
- data/lib/pigeon/errors.rb +28 -0
- data/lib/pigeon/initializer.rb +13 -0
- data/lib/pigeon/nuntium.rb +10 -0
- data/lib/pigeon/verboice.rb +10 -0
- data/lib/pigeon/version.rb +3 -0
- data/lib/pigeon.rb +25 -0
- data/pigeon.gemspec +24 -0
- data/spec/data/test_schemas.yml +21 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +59 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/helpers/pigeon/channel_helper_spec.rb +173 -0
- data/spec/helpers/pigeon/renderer/base_spec.rb +109 -0
- data/spec/helpers/pigeon/renderer/channel_renderer_spec.rb +61 -0
- data/spec/helpers/pigeon/tag_helper_spec.rb +36 -0
- data/spec/helpers/pigeon/template_helper_spec.rb +57 -0
- data/spec/models/pigeon/channel_attribute_spec.rb +98 -0
- data/spec/models/pigeon/channel_schema_spec.rb +63 -0
- data/spec/models/pigeon/channel_spec.rb +205 -0
- data/spec/models/pigeon/nuntium_channel_spec.rb +53 -0
- data/spec/spec_helper.rb +43 -0
- data/spec/support/active_model_lint.rb +15 -0
- data/spec/support/test_schemas.rb +12 -0
- metadata +254 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Only use best-standards-support built into browsers
|
23
|
+
config.action_dispatch.best_standards_support = :builtin
|
24
|
+
|
25
|
+
# Raise exception on mass assignment protection for Active Record models
|
26
|
+
config.active_record.mass_assignment_sanitizer = :strict
|
27
|
+
|
28
|
+
# Log the query plan for queries taking more than this (works
|
29
|
+
# with SQLite, MySQL, and PostgreSQL)
|
30
|
+
config.active_record.auto_explain_threshold_in_seconds = 0.5
|
31
|
+
|
32
|
+
# Do not compress assets
|
33
|
+
config.assets.compress = false
|
34
|
+
|
35
|
+
# Expands the lines which load the assets
|
36
|
+
config.assets.debug = true
|
37
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# Code is not reloaded between requests
|
5
|
+
config.cache_classes = true
|
6
|
+
|
7
|
+
# Full error reports are disabled and caching is turned on
|
8
|
+
config.consider_all_requests_local = false
|
9
|
+
config.action_controller.perform_caching = true
|
10
|
+
|
11
|
+
# Disable Rails's static asset server (Apache or nginx will already do this)
|
12
|
+
config.serve_static_assets = false
|
13
|
+
|
14
|
+
# Compress JavaScripts and CSS
|
15
|
+
config.assets.compress = true
|
16
|
+
|
17
|
+
# Don't fallback to assets pipeline if a precompiled asset is missed
|
18
|
+
config.assets.compile = false
|
19
|
+
|
20
|
+
# Generate digests for assets URLs
|
21
|
+
config.assets.digest = true
|
22
|
+
|
23
|
+
# Defaults to nil and saved in location specified by config.assets.prefix
|
24
|
+
# config.assets.manifest = YOUR_PATH
|
25
|
+
|
26
|
+
# Specifies the header that your server uses for sending files
|
27
|
+
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
|
28
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
|
29
|
+
|
30
|
+
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
31
|
+
# config.force_ssl = true
|
32
|
+
|
33
|
+
# See everything in the log (default is :info)
|
34
|
+
# config.log_level = :debug
|
35
|
+
|
36
|
+
# Prepend all log lines with the following tags
|
37
|
+
# config.log_tags = [ :subdomain, :uuid ]
|
38
|
+
|
39
|
+
# Use a different logger for distributed setups
|
40
|
+
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
|
41
|
+
|
42
|
+
# Use a different cache store in production
|
43
|
+
# config.cache_store = :mem_cache_store
|
44
|
+
|
45
|
+
# Enable serving of images, stylesheets, and JavaScripts from an asset server
|
46
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
47
|
+
|
48
|
+
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
49
|
+
# config.assets.precompile += %w( search.js )
|
50
|
+
|
51
|
+
# Disable delivery errors, bad email addresses will be ignored
|
52
|
+
# config.action_mailer.raise_delivery_errors = false
|
53
|
+
|
54
|
+
# Enable threaded mode
|
55
|
+
# config.threadsafe!
|
56
|
+
|
57
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
58
|
+
# the I18n.default_locale when a translation can not be found)
|
59
|
+
config.i18n.fallbacks = true
|
60
|
+
|
61
|
+
# Send deprecation notices to registered listeners
|
62
|
+
config.active_support.deprecation = :notify
|
63
|
+
|
64
|
+
# Log the query plan for queries taking more than this (works
|
65
|
+
# with SQLite, MySQL, and PostgreSQL)
|
66
|
+
# config.active_record.auto_explain_threshold_in_seconds = 0.5
|
67
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Configure static asset server for tests with Cache-Control for performance
|
11
|
+
config.serve_static_assets = true
|
12
|
+
config.static_cache_control = "public, max-age=3600"
|
13
|
+
|
14
|
+
# Log error messages when you accidentally call methods on nil
|
15
|
+
config.whiny_nils = true
|
16
|
+
|
17
|
+
# Show full error reports and disable caching
|
18
|
+
config.consider_all_requests_local = true
|
19
|
+
config.action_controller.perform_caching = false
|
20
|
+
|
21
|
+
# Raise exceptions instead of rendering exception templates
|
22
|
+
config.action_dispatch.show_exceptions = false
|
23
|
+
|
24
|
+
# Disable request forgery protection in test environment
|
25
|
+
config.action_controller.allow_forgery_protection = false
|
26
|
+
|
27
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
28
|
+
# The :test delivery method accumulates sent emails in the
|
29
|
+
# ActionMailer::Base.deliveries array.
|
30
|
+
config.action_mailer.delivery_method = :test
|
31
|
+
|
32
|
+
# Raise exception on mass assignment protection for Active Record models
|
33
|
+
config.active_record.mass_assignment_sanitizer = :strict
|
34
|
+
|
35
|
+
# Print deprecation notices to the stderr
|
36
|
+
config.active_support.deprecation = :stderr
|
37
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format
|
4
|
+
# (all these examples are active by default):
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
8
|
+
# inflect.irregular 'person', 'people'
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# These inflection rules are supported but not enabled by default:
|
13
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
14
|
+
# inflect.acronym 'RESTful'
|
15
|
+
# end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
+
Dummy::Application.config.secret_token = '654a9a8e3ba0f5f078899b248d172d22e2520bc9f623322c49910a3e7cf95a9e1d3978e905a0e159bf2f9a5b4c585901cc96be0d43cefbf8bd9eeeaa7b3017ee'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
|
4
|
+
|
5
|
+
# Use the database for sessions instead of the cookie-based default,
|
6
|
+
# which shouldn't be used to store highly confidential information
|
7
|
+
# (create the session table with "rails generate session_migration")
|
8
|
+
# Dummy::Application.config.session_store :active_record_store
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
#
|
3
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
4
|
+
# is enabled by default.
|
5
|
+
|
6
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
wrap_parameters format: [:json]
|
9
|
+
end
|
10
|
+
|
11
|
+
# Disable root element in JSON by default.
|
12
|
+
ActiveSupport.on_load(:active_record) do
|
13
|
+
self.include_root_in_json = false
|
14
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/404.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
</div>
|
24
|
+
</body>
|
25
|
+
</html>
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Pigeon
|
4
|
+
describe ChannelHelper do
|
5
|
+
before(:each) do
|
6
|
+
@schema = ChannelSchema.from_hash 'nuntium', test_schema_hash('foobar')
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "pigeon_attribute_field" do
|
10
|
+
it "should render string attributes" do
|
11
|
+
@attr = ChannelAttribute.new 'foo', :string
|
12
|
+
helper.pigeon_attribute_field(@attr).
|
13
|
+
should match(/<input.*name="foo".*type="text"/)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should render password attributes" do
|
17
|
+
@attr = ChannelAttribute.new 'foo', :password
|
18
|
+
helper.pigeon_attribute_field(@attr).
|
19
|
+
should match(/<input.*name="foo".*type="password"/)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should render integer attributes" do
|
23
|
+
@attr = ChannelAttribute.new 'foo', :integer
|
24
|
+
helper.pigeon_attribute_field(@attr).
|
25
|
+
should match(/<input.*name="foo".*type="number"/)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should render enum attributes" do
|
29
|
+
@attr = ChannelAttribute.new 'foo', :enum
|
30
|
+
helper.pigeon_attribute_field(@attr).
|
31
|
+
should match(/<select.*name="foo"/)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should render timezone attributes" do
|
35
|
+
@attr = ChannelAttribute.new 'foo', :timezone
|
36
|
+
helper.pigeon_attribute_field(@attr).
|
37
|
+
should match(/<select.*name="foo"/)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should render boolean attributes" do
|
41
|
+
@attr = ChannelAttribute.new 'foo', :boolean
|
42
|
+
helper.pigeon_attribute_field(@attr).
|
43
|
+
should match(/<input.*name="foo".*type="checkbox"/)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should render an attribute with a forced given type" do
|
47
|
+
@attr = ChannelAttribute.new 'foo', :boolean
|
48
|
+
helper.pigeon_attribute_field(@attr, false, { type: 'hidden' }).
|
49
|
+
should have_tag('input', with: { name: 'foo', type: 'hidden'})
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should render an attribute with a forced custom type" do
|
53
|
+
@attr = ChannelAttribute.new 'foo', :string
|
54
|
+
helper.pigeon_attribute_field(@attr, false, { type: 'url' }).
|
55
|
+
should have_tag('input', with: { name: 'foo', type: 'url'})
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should accept a scope option" do
|
59
|
+
@attr = ChannelAttribute.new 'foo', :string
|
60
|
+
helper.pigeon_attribute_field(@attr, nil, scope: 'bar').
|
61
|
+
should match(/<input.*name="bar\[foo\]".*"/)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should accept additional HTML options" do
|
65
|
+
@attr = ChannelAttribute.new 'foo', :string
|
66
|
+
helper.pigeon_attribute_field(@attr, nil, size: '10').
|
67
|
+
should match(/<input.*name="foo".*size="10"/)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "pigeon_attribute_label" do
|
72
|
+
before(:each) do
|
73
|
+
@attr = ChannelAttribute.new 'foo', :string, label: 'Bar'
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should render a <label> tag with the attribute's label" do
|
77
|
+
helper.pigeon_attribute_label(@attr).
|
78
|
+
should match(/<label.*>#{@attr.label}<\/label>/)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should set the tag's for attribute" do
|
82
|
+
helper.pigeon_attribute_label(@attr).
|
83
|
+
should match(/<label[^>]+for="foo"/)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should accept a scope option" do
|
87
|
+
helper.pigeon_attribute_label(@attr, scope: 'bar').
|
88
|
+
should match(/<label[^>]+for="bar_foo"/)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should accept additional HTML options" do
|
92
|
+
helper.pigeon_attribute_label(@attr, :class => 'bar').
|
93
|
+
should match(/<label[^>]+class="bar"/)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "pigeon_attribute" do
|
98
|
+
it "should render label and field enclosed in a div tag" do
|
99
|
+
@attr = ChannelAttribute.new 'foo', :string
|
100
|
+
helper.pigeon_attribute(@attr).
|
101
|
+
should match(/<div.*<label.*for="foo".*<input.*name="foo"/)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should invert the render order for boolean attributes" do
|
105
|
+
@attr = ChannelAttribute.new 'foo', :boolean
|
106
|
+
helper.pigeon_attribute(@attr).
|
107
|
+
should match(/<div.*<input.*name="foo".*<label.*for="foo"/)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should accept a scope option" do
|
111
|
+
@attr = ChannelAttribute.new 'foo', :string
|
112
|
+
helper.pigeon_attribute(@attr, nil, scope: 'bar').
|
113
|
+
should match(/<div.*<label.*for="bar_foo".*<input.*name="bar\[foo\]"/)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should accept a field_with_errors and wrap the field in a DIV" do
|
117
|
+
@attr = ChannelAttribute.new 'foo', :string
|
118
|
+
helper.pigeon_attribute(@attr, nil, field_with_errors: true).
|
119
|
+
should match(/<div.*<div.*class="field_with_errors".*<input/)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should accept HTML options for the enclosing tag" do
|
123
|
+
@attr = ChannelAttribute.new 'foo', :string
|
124
|
+
helper.pigeon_attribute(@attr, nil, :class => 'bar').
|
125
|
+
should match(/<div[^>]+class="bar".*<input.*name="foo"/)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "pigeon_channel_attribute" do
|
130
|
+
before(:each) do
|
131
|
+
@channel = Channel.new schema: @schema,
|
132
|
+
ticket_code: '1234', configuration: { user: 'joe' }
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should render schema's attribute with the channel's value" do
|
136
|
+
out = helper.pigeon_channel_attribute(@channel, 'ticket_code')
|
137
|
+
out.should match(/<label.*for="ticket_code"/)
|
138
|
+
out.should match(/<input.*name="ticket_code".*type="number".*value="1234"/)
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should render a channel's attribute if not present in schema" do
|
142
|
+
@channel.write_attribute('other_attr', 'foobar')
|
143
|
+
out = helper.pigeon_channel_attribute(@channel, 'other_attr')
|
144
|
+
out.should match(/<label.*for="other_attr"/)
|
145
|
+
out.should match(/<input.*name="other_attr".*type="text".*value="foobar"/)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should accept a scope option" do
|
149
|
+
out = helper.pigeon_channel_attribute(@channel, 'configuration[user]', scope: 'channel')
|
150
|
+
out.should match(/<label.*for="channel_configuration_user"/)
|
151
|
+
out.should match(/<input.*name="channel\[configuration\]\[user\]"/)
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should accept additional HTML options" do
|
155
|
+
out = helper.pigeon_channel_attribute(@channel, 'ticket_code', :class => 'code')
|
156
|
+
out.should match(/<div.*class="code"/)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should accept a schema-less channel" do
|
160
|
+
@channel = Channel.new foo: 42
|
161
|
+
helper.pigeon_channel_attribute(@channel, 'foo').
|
162
|
+
should match(/<input.*name="foo"/)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should wrap the field in a DIV if it has errors" do
|
166
|
+
@channel.errors.add('configuration[user]', "User can't be blank")
|
167
|
+
out = helper.pigeon_channel_attribute(@channel, 'configuration[user]')
|
168
|
+
out.should match(/<div.*<div.*class="field_with_errors".*<input.*name="configuration\[user\]"/)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Pigeon
|
4
|
+
module Renderer
|
5
|
+
describe "Base" do
|
6
|
+
before(:each) do
|
7
|
+
@renderer = Base.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should render an empty vector" do
|
11
|
+
@renderer.render([]).should eq('')
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should render empty tags" do
|
15
|
+
@renderer.render(["p"]).should eq("<p></p>")
|
16
|
+
@renderer.render(["br"]).should eq("<br />")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should render tags with content text" do
|
20
|
+
@renderer.render(["h1", "Title"]).should eq("<h1>Title</h1>")
|
21
|
+
@renderer.render(["h2", "Hello", "World"]).
|
22
|
+
should eq("<h2>HelloWorld</h2>")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should optionally accept an attributes hash" do
|
26
|
+
@renderer.render(["span", { :class => 'foo' }, "with class foo"]).
|
27
|
+
should eq("<span class=\"foo\">with class foo</span>")
|
28
|
+
@renderer.render(["p", { :class => 'bar' }]).
|
29
|
+
should eq("<p class=\"bar\"></p>")
|
30
|
+
@renderer.render(["hr", { :class => 'bar' }]).
|
31
|
+
should eq("<hr class=\"bar\" />")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should recursively render content elements" do
|
35
|
+
@renderer.render(["div", ["h1", "Title"], ["p", "Foo", ["br"], "Bar"]]).
|
36
|
+
should eq("<div><h1>Title</h1><p>Foo<br />Bar</p></div>")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should parse tag name to produce element IDs" do
|
40
|
+
@renderer.render(["div#foo"]).should eq("<div id=\"foo\"></div>")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should parse tag name to produce classes" do
|
44
|
+
@renderer.render(["div.foo"]).should eq("<div class=\"foo\"></div>")
|
45
|
+
@renderer.render(["div.foo.bar"]).
|
46
|
+
should eq("<div class=\"foo bar\"></div>")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should accept IDs and classes simultaneously and in any order" do
|
50
|
+
@renderer.render(["div#foo.bar.baz"]).
|
51
|
+
should eq("<div class=\"bar baz\" id=\"foo\"></div>")
|
52
|
+
@renderer.render(["div.bar#foo.baz"]).
|
53
|
+
should eq("<div class=\"bar baz\" id=\"foo\"></div>")
|
54
|
+
@renderer.render(["div.bar.baz#foo"]).
|
55
|
+
should eq("<div class=\"bar baz\" id=\"foo\"></div>")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should render DIVs by default" do
|
59
|
+
@renderer.render(["#foo"]).should eq("<div id=\"foo\"></div>")
|
60
|
+
@renderer.render([".foo"]).should eq("<div class=\"foo\"></div>")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should merge options from the tag and the given hash" do
|
64
|
+
@renderer.render(["#foo", { :class => "bar" }]).
|
65
|
+
should eq("<div class=\"bar\" id=\"foo\"></div>")
|
66
|
+
@renderer.render([".foo", { :id => "bar" }]).
|
67
|
+
should eq("<div class=\"foo\" id=\"bar\"></div>")
|
68
|
+
@renderer.render([".foo", { :class => "bar" }]).
|
69
|
+
should eq("<div class=\"foo bar\"></div>")
|
70
|
+
@renderer.render(["#foo", { :id => "bar" }]).
|
71
|
+
should eq("<div id=\"foo\"></div>")
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should not render unknown at-commands by default" do
|
75
|
+
@renderer.render(["@x", "foo"]).should eq('')
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should delegate at-command rendering" do
|
79
|
+
class TestRenderer < Base
|
80
|
+
def render_at_command(v)
|
81
|
+
safe_join(v)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
@renderer = TestRenderer.new
|
86
|
+
@renderer.render(["@x", "foo"]).should eq('@xfoo')
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should escape HTML entities by default" do
|
90
|
+
@renderer.render(["h1", "<b>foo</b>"]).should_not have_tag('b')
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should accept @raw command and not escape entities" do
|
94
|
+
@renderer.render(["@raw", "<b>foo</b>"]).should have_tag('b')
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should accept @template, @wizard and @page commands" do
|
98
|
+
@renderer.render(["@template"]).should have_tag('div', with: { 'class' => 'pigeon pigeon_template' })
|
99
|
+
@renderer.render(["@wizard"]).should have_tag('div', with: { 'class' => 'pigeon pigeon_wizard' })
|
100
|
+
@renderer.render(["@page"]).should have_tag('div', with: { 'class' => 'pigeon_wizard_page' })
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should prefix custom options with 'data-' in template commands" do
|
104
|
+
@renderer.render(["@template", { "foo" => 42 }]).should have_tag('div', with: { "data-foo" => 42 })
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|