iab-WhiteLabeling 0.1.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.
Files changed (2) hide show
  1. data/lib/channel_manager.rb +147 -0
  2. metadata +73 -0
@@ -0,0 +1,147 @@
1
+ # Copyright (c) 2007-2008 Orangery Technology Limited
2
+ # You can redistribute it and/or modify it under the same terms as Ruby.
3
+ #
4
+ # a session has one brand (e.g. Lexus) and one human language (e.g. English)
5
+ # a session can have many products
6
+ module ChannelManager
7
+ def self.debug_default_channel=(value)
8
+ @@debug_default_channel = value
9
+ end
10
+
11
+ def set_channel_in_session
12
+ set_session_data unless params_remain_unchanged
13
+ end
14
+
15
+ def load_changes_in_channel
16
+ inject_channel unless channel_already_loaded
17
+ end
18
+
19
+ #helper used to handle xpath field name translation to human understandable field label/legend
20
+ #TODO: generate these translation into a separate dictionary
21
+ def __(key)
22
+ trans = @dictionary[key]
23
+ return trans unless trans == nil
24
+ key
25
+ end
26
+
27
+ #helper used for human language translation
28
+ def _(key)
29
+ if (session[:lang] != "en")
30
+ trans = @dictionary[key]
31
+ return trans unless trans == nil
32
+ end
33
+ key
34
+ end
35
+
36
+ private
37
+ def params_remain_unchanged
38
+ param_same_as_session?("brand") && param_same_as_session?("product") && param_same_as_session?("lang")
39
+ end
40
+
41
+ def param_same_as_session?(param)
42
+ if (session == nil || session[param.to_sym] == nil) then
43
+ #we don't currently have a variable of name param in session store, so we must be entering for the first time
44
+ return false
45
+ elsif (params[param.to_sym] == nil) then
46
+ #no param variable on the current url so we must stick with what we have in session store
47
+ return true
48
+ else
49
+ return session[param.to_sym] == params[param.to_sym]
50
+ end
51
+ end
52
+
53
+ def channel_already_loaded
54
+ #where no channel has yet been injected the method productName will not be defined
55
+ return false unless self.respond_to? :productName
56
+ #where productName method exists, if the product has changed then this method will not return the new product name
57
+ return (productName('dummy') == session[:product])
58
+ end
59
+
60
+ def set_session_data
61
+ #only set/change session variable is there is something on the URL for that variable
62
+ session[:brand] = params["brand"] unless params["brand"] == nil
63
+ session[:lang] = params["lang"] unless params["lang"] == nil
64
+ session[:product] = params["product"] unless params["product"] == nil
65
+ end
66
+
67
+ def inject_channel
68
+ if defined?(@@debug_default_channel) && (!session || !session[:brand] || !session[:product] || !session[:lang])
69
+ product = @@debug_default_channel[:product]
70
+ brand = @@debug_default_channel[:brand]
71
+ lang = @@debug_default_channel[:lang]
72
+ else
73
+ product = session[:product]
74
+ brand = session[:brand]
75
+ lang = session[:lang]
76
+ end
77
+
78
+ productPath = PRODUCT_ROOT.gsub(/%product/,product)
79
+ brandPath = BRAND_ROOT.gsub(/%brand/,brand)
80
+
81
+ unless FileTest.directory?("#{productPath}")
82
+ puts "#{productPath} channel does not exist!"
83
+ end
84
+
85
+ #introduce graphical assets including stylesheets
86
+ introduceBrand(brand)
87
+ #add human language of choice
88
+ introduce_dictionary(PRODUCTS_ROOT, lang)
89
+ introduce_dictionary(productPath, lang)
90
+ introduce_dictionary(brandPath, lang)
91
+ #enable oil DSL based layout files to be used a rails view definitions
92
+ prepend_view_path(File.join(productPath, 'DSL', 'layouts' ))
93
+ prepend_view_path(File.join("#{WIDGET_ROOT4}"))
94
+ #dynamically sets the flow of the process from the process part of the oil DSL
95
+ load_controller_actions(product)
96
+ end
97
+
98
+ def introduceBrand(brand)
99
+ path = BRAND_ROOT.gsub(/%brand/,brand)
100
+ open("#{path}/damManifest.rb") {|f| @contents = f.read }
101
+
102
+ #introduce brand information as a ruby module
103
+ eval(@contents.to_s)
104
+
105
+ #extend the current controller instance with the channel specific ruby module
106
+ #loaded on the line above
107
+ eval("self.extend #{brand}Manifest");
108
+
109
+ associateDAMReferences
110
+ end
111
+
112
+ def introduce_dictionary(dictionary_folder, lang)
113
+ dict = "#{dictionary_folder}/dictionary_#{lang}.rb"
114
+ load_dictionary(dict,lang)
115
+ end
116
+
117
+ def load_controller_actions(product)
118
+ if (File.exist?("#{PRODUCT_ROOT.gsub(/%product/,product)}/DSL/processes.oil"))
119
+ action_methods = Communicator.instance.handle(session,"ProcessDefinition",nil)
120
+ #extend controller with actions for this product
121
+ self.class.class_eval("#{action_methods}")
122
+ #the following method is introduced by the evaluation of the results of the above
123
+ #call to communicator and injected with the line above
124
+ wireProcess
125
+ end
126
+ end
127
+
128
+ def load_dictionary(dict,lang)
129
+ if (File.exists?(dict))
130
+ open(dict) {|f| eval(f.read.to_s) }
131
+ eval("self.extend Dictionary#{lang}HL")
132
+
133
+ # We assume the first dictionary loaded is the master and all subsequent
134
+ # loads are to be merged into the master
135
+ @dictionary = dictionary if @dictionary == nil
136
+ @dictionary.merge!(dictionary) unless @dictionary == nil
137
+
138
+ #setup variables used by the UI views
139
+ associateHLReferences
140
+ end
141
+ end
142
+
143
+ def introduce_layout_dictionary(layout)
144
+ dict = PRODUCT_ROOT.gsub(/%product/,session[:product])+"/DSL/layouts/#{layout}_dictionary_#{session[:lang]}.rb"
145
+ load_dictionary(dict,session[:lang])
146
+ end
147
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iab-WhiteLabeling
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Gary Mawdsley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-31 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mime-types
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "1.15"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: diff-lcs
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.2
34
+ version:
35
+ description: WhiteLabeling is a module that facilitates the separation of UI layers allowing for quick brand and language change
36
+ email: garymawdsley@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - lib/channel_manager.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/iab/WhiteLabeling
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --inline-source
50
+ - --charset=UTF-8
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project: WhiteLabeling
68
+ rubygems_version: 1.2.0
69
+ signing_key:
70
+ specification_version: 2
71
+ summary: WhiteLabeling is a module that facilitates the separation of UI layers allowing for quick brand and language change
72
+ test_files: []
73
+