imedo_client_communication 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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +27 -0
- data/imedo_client_communication.gemspec +38 -0
- data/lib/imedo_client_communication.rb +9 -0
- data/lib/imedo_client_communication/base_provider.rb +37 -0
- data/lib/imedo_client_communication/context.rb +52 -0
- data/lib/imedo_client_communication/payload.rb +11 -0
- data/lib/imedo_client_communication/version.rb +3 -0
- data/test/functional/lib/context_test.rb +64 -0
- data/test/test_helper.rb +13 -0
- metadata +110 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'gemmer'
|
5
|
+
require 'rake'
|
6
|
+
require 'rake/testtask'
|
7
|
+
|
8
|
+
desc 'Default: run all tests.'
|
9
|
+
task :default => ['test:units', 'test:functionals']
|
10
|
+
|
11
|
+
desc 'Unit Test the common_helpers gem.'
|
12
|
+
Rake::TestTask.new('test:units') do |t|
|
13
|
+
t.libs << 'lib'
|
14
|
+
t.pattern = 'test/unit/**/*_test.rb'
|
15
|
+
t.verbose = true
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'Functional Test the common_helpers gem.'
|
19
|
+
Rake::TestTask.new('test:functionals') do |t|
|
20
|
+
t.libs << 'lib'
|
21
|
+
t.pattern = 'test/functional/**/*_test.rb'
|
22
|
+
t.verbose = true
|
23
|
+
end
|
24
|
+
|
25
|
+
Gemmer::Tasks.new('imedo_client_communication') do |t|
|
26
|
+
t.release_via :scatter, :to => 'dev01'
|
27
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "imedo_client_communication/version"
|
4
|
+
|
5
|
+
# Dependencies
|
6
|
+
dependencies = [
|
7
|
+
[ %q<activesupport> , ["= 2.3.3"] ],
|
8
|
+
[ %q<actionpack> , ["= 2.3.3"] ]
|
9
|
+
]
|
10
|
+
|
11
|
+
Gem::Specification.new do |s|
|
12
|
+
s.name = "imedo_client_communication"
|
13
|
+
s.version = ImedoClientCommunication::VERSION
|
14
|
+
s.platform = Gem::Platform::RUBY
|
15
|
+
s.authors = ["imedo GmbH"]
|
16
|
+
s.email = ["entwickler@imedo.de"]
|
17
|
+
s.homepage = ""
|
18
|
+
s.summary = %q{Client-side communication with the main application}
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
|
25
|
+
if s.respond_to? :specification_version then
|
26
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
27
|
+
s.specification_version = 3
|
28
|
+
|
29
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
30
|
+
dependencies.each{|dep| s.add_runtime_dependency(*dep) }
|
31
|
+
else
|
32
|
+
dependencies.each{|dep| s.add_dependency(*dep) }
|
33
|
+
end
|
34
|
+
else
|
35
|
+
dependencies.each{|dep| s.add_dependency(*dep) }
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'action_controller'
|
5
|
+
module ImedoClientCommunication
|
6
|
+
autoload :Context, "imedo_client_communication/context"
|
7
|
+
autoload :Payload, "imedo_client_communication/payload"
|
8
|
+
autoload :BaseProvider, "imedo_client_communication/base_provider"
|
9
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ImedoClientCommunication
|
2
|
+
|
3
|
+
module BaseProvider
|
4
|
+
def self.included(receiver)
|
5
|
+
receiver.class_eval do
|
6
|
+
|
7
|
+
provides_context :title
|
8
|
+
provides_context :main_title, :main_subtitle, :meta_title, :title_class, :subtitle
|
9
|
+
provides_context :page_description, :page_keywords, :keywords
|
10
|
+
provides_context :geo_location_city, :geo_location_latlong, :geo_location_icbm, :geo_location_region
|
11
|
+
provides_context :noindex, :canonical, :no_breadcrumb
|
12
|
+
|
13
|
+
provides_context :request_uri do
|
14
|
+
request.request_uri
|
15
|
+
end
|
16
|
+
|
17
|
+
provides_context :forbidden
|
18
|
+
|
19
|
+
provides_context :page_id
|
20
|
+
provides_context :model_type => lambda { @navigation_model.class.name if @navigation_model },
|
21
|
+
:model_id => lambda { @navigation_model.id if @navigation_model },
|
22
|
+
# remove respond_to when all client apps implemented the necessary remote sitemap method in all models
|
23
|
+
:model_name => lambda { @navigation_model.sitemap_name if @navigation_model && @navigation_model.respond_to?(:sitemap_name) },
|
24
|
+
:model_param => lambda { @navigation_model.to_param if @navigation_model }
|
25
|
+
|
26
|
+
provides_context :back_link
|
27
|
+
|
28
|
+
provides_context :current_topic # hook to connect contents across apps
|
29
|
+
|
30
|
+
provides_context :client_javascripts do
|
31
|
+
(Array(@client_javascripts) || []).join(",")
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module ImedoClientCommunication
|
2
|
+
|
3
|
+
module Context
|
4
|
+
module ClassMethods
|
5
|
+
def provides_context(*names, &block)
|
6
|
+
if names.size > 1 && block_given?
|
7
|
+
raise "Either give the names of several instance variables, or one instance variable and a block"
|
8
|
+
else
|
9
|
+
if names.size == 1 && block_given?
|
10
|
+
names = { names.first => block }
|
11
|
+
elsif names.first.is_a?(Hash)
|
12
|
+
names = names.first
|
13
|
+
else
|
14
|
+
names = names.inject({}) { |hash, name| hash[name] = lambda { instance_variable_get :"@#{name}" }; hash }
|
15
|
+
end
|
16
|
+
self.context_providers.merge! names
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
module InstanceMethods
|
23
|
+
def dump_context
|
24
|
+
context.merge!(eval_context)
|
25
|
+
context
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
def eval_context
|
30
|
+
self.class.context_providers.inject({}) do |hash, pair|
|
31
|
+
hash[pair.first] = pair.last.bind(@template || self).call
|
32
|
+
hash
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def context
|
37
|
+
@context ||= {}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.included(receiver)
|
42
|
+
receiver.extend ClassMethods
|
43
|
+
receiver.send :include, InstanceMethods
|
44
|
+
|
45
|
+
receiver.class_eval do
|
46
|
+
class_inheritable_accessor :context_providers
|
47
|
+
self.context_providers = {}
|
48
|
+
helper_method :dump_context if self.respond_to?(:helper_method)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
3
|
+
class ImedoClientCommunication::ContextTest < ActionController::TestCase
|
4
|
+
|
5
|
+
test "should provide context for one variable" do
|
6
|
+
c = create_class do
|
7
|
+
provides_context :variable
|
8
|
+
end
|
9
|
+
assert c.context_providers.has_key?(:variable)
|
10
|
+
end
|
11
|
+
|
12
|
+
test "should provide context for more than one variable" do
|
13
|
+
c = create_class do
|
14
|
+
provides_context :one, :two, :three
|
15
|
+
end
|
16
|
+
assert (c.context_providers.keys - [:one, :two, :three]).blank?
|
17
|
+
end
|
18
|
+
|
19
|
+
test "should provide context for one variable with hash" do
|
20
|
+
c = create_class do
|
21
|
+
provides_context :variable => lambda { |value| Hash.new(:value => value) }
|
22
|
+
end
|
23
|
+
assert c.context_providers.has_key?(:variable)
|
24
|
+
end
|
25
|
+
|
26
|
+
test "should allow block as lambda for one variable" do
|
27
|
+
c = create_class do
|
28
|
+
provides_context :variable do |value|
|
29
|
+
Hash.new(:value => value)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
assert c.context_providers.has_key?(:variable)
|
33
|
+
end
|
34
|
+
|
35
|
+
test "should not allow block as lambda for multiple variables" do
|
36
|
+
assert_raise RuntimeError do
|
37
|
+
create_class do
|
38
|
+
provides_context :one, :two do |value|
|
39
|
+
Hash.new(:value => value)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
test "should dump context" do
|
46
|
+
klass = create_class do
|
47
|
+
provides_context :variable
|
48
|
+
attr_accessor :variable
|
49
|
+
end
|
50
|
+
c = klass.new
|
51
|
+
c.variable = { :value => 15 }
|
52
|
+
expected = { :variable => { :value => 15 } }
|
53
|
+
assert_equal expected, c.dump_context
|
54
|
+
end
|
55
|
+
|
56
|
+
protected
|
57
|
+
def create_class(&block)
|
58
|
+
returning Class.new(ApplicationController) do |klass|
|
59
|
+
klass.class_eval do
|
60
|
+
block.bind(self).call if block_given?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
RAILS_ROOT = File.dirname(__FILE__) + '/..'
|
5
|
+
|
6
|
+
gem 'activesupport', '2.3.3'
|
7
|
+
|
8
|
+
require 'active_support'
|
9
|
+
require 'ostruct'
|
10
|
+
|
11
|
+
require File.dirname(__FILE__) + '/../lib/imedo_client_communication'
|
12
|
+
ActionController::Base.send(:include, ImedoClientCommunication::Context)
|
13
|
+
class ApplicationController<ActionController::Base; end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: imedo_client_communication
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- imedo GmbH
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-27 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: activesupport
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - "="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 5
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 3
|
33
|
+
- 3
|
34
|
+
version: 2.3.3
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: actionpack
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - "="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 5
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 3
|
49
|
+
- 3
|
50
|
+
version: 2.3.3
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
description:
|
54
|
+
email:
|
55
|
+
- entwickler@imedo.de
|
56
|
+
executables: []
|
57
|
+
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files: []
|
61
|
+
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- Rakefile
|
66
|
+
- imedo_client_communication.gemspec
|
67
|
+
- lib/imedo_client_communication.rb
|
68
|
+
- lib/imedo_client_communication/base_provider.rb
|
69
|
+
- lib/imedo_client_communication/context.rb
|
70
|
+
- lib/imedo_client_communication/payload.rb
|
71
|
+
- lib/imedo_client_communication/version.rb
|
72
|
+
- test/functional/lib/context_test.rb
|
73
|
+
- test/test_helper.rb
|
74
|
+
has_rdoc: true
|
75
|
+
homepage: ""
|
76
|
+
licenses: []
|
77
|
+
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.3.7
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Client-side communication with the main application
|
108
|
+
test_files:
|
109
|
+
- test/functional/lib/context_test.rb
|
110
|
+
- test/test_helper.rb
|