bakery-core 0.0.4

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 (40) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +4 -0
  3. data/Rakefile +2 -0
  4. data/app/helpers/bakery_theme/object_list_helper.rb +100 -0
  5. data/app/helpers/bakery_theme/toolbar_helper.rb +390 -0
  6. data/app/helpers/bakery_theme_helper.rb +10 -0
  7. data/app/helpers/platform/asset_tag_helper.rb +76 -0
  8. data/app/helpers/platform_helper.rb +7 -0
  9. data/app/models/platform/site_configuration.rb +63 -0
  10. data/app/models/platform/site_manager.rb +112 -0
  11. data/bakery-core.gemspec +23 -0
  12. data/config/.gitkeep +0 -0
  13. data/lib/bakery-core.rb +8 -0
  14. data/lib/bakery-core/version.rb +5 -0
  15. data/lib/engine.rb +8 -0
  16. data/lib/generators/website/USAGE +18 -0
  17. data/lib/generators/website/templates/config.yml +221 -0
  18. data/lib/generators/website/templates/layout.html.haml +9 -0
  19. data/lib/generators/website/templates/style.css +5 -0
  20. data/lib/generators/website/templates/template.html.haml +14 -0
  21. data/lib/generators/website/templates/theme/images/bg_wood_eureka.png +0 -0
  22. data/lib/generators/website/templates/theme/images/ui-bg_flat_55_999999_40x100.png +0 -0
  23. data/lib/generators/website/templates/theme/images/ui-bg_flat_55_ffffff_40x100.png +0 -0
  24. data/lib/generators/website/templates/theme/images/ui-bg_flat_75_000000_40x100.png +0 -0
  25. data/lib/generators/website/templates/theme/images/ui-bg_flat_75_103b53_40x100.png +0 -0
  26. data/lib/generators/website/templates/theme/images/ui-bg_flat_75_70a9c5_40x100.png +0 -0
  27. data/lib/generators/website/templates/theme/images/ui-bg_gloss-wave_45_e14f1c_500x100.png +0 -0
  28. data/lib/generators/website/templates/theme/images/ui-bg_highlight-hard_70_9fc7db_1x100.png +0 -0
  29. data/lib/generators/website/templates/theme/images/ui-bg_highlight-soft_70_103b53_1x100.png +0 -0
  30. data/lib/generators/website/templates/theme/images/ui-bg_inset-hard_100_e9dfc4_1x100.png +0 -0
  31. data/lib/generators/website/templates/theme/images/ui-icons_0c3d58_256x240.png +0 -0
  32. data/lib/generators/website/templates/theme/images/ui-icons_103b53_256x240.png +0 -0
  33. data/lib/generators/website/templates/theme/images/ui-icons_58a4ca_256x240.png +0 -0
  34. data/lib/generators/website/templates/theme/images/ui-icons_9fc7db_256x240.png +0 -0
  35. data/lib/generators/website/templates/theme/images/ui-icons_d8e7f3_256x240.png +0 -0
  36. data/lib/generators/website/templates/theme/images/ui-icons_fcd113_256x240.png +0 -0
  37. data/lib/generators/website/templates/theme/images/ui-icons_ffffff_256x240.png +0 -0
  38. data/lib/generators/website/templates/theme/ui.theme.css +1100 -0
  39. data/lib/generators/website/website_generator.rb +40 -0
  40. metadata +135 -0
@@ -0,0 +1,10 @@
1
+ require File.join(File.dirname(__FILE__), "bakery_theme", "toolbar_helper")
2
+ require File.join(File.dirname(__FILE__), "bakery_theme", "object_list_helper")
3
+
4
+ module BakeryThemeHelper
5
+
6
+ include BakeryTheme::ObjectListHelper
7
+ include BakeryTheme::ToolbarHelper
8
+
9
+
10
+ end
@@ -0,0 +1,76 @@
1
+ module Platform::AssetTagHelper
2
+
3
+ include ActionView::Helpers::AssetTagHelper
4
+
5
+ def stylesheet_link_tag_with_context(*sources)
6
+ options = sources.extract_options!.stringify_keys
7
+ context = options.delete("context") || :site
8
+ if context
9
+ assets_with_context context do
10
+ stylesheet_link_tag_without_context *(sources + [options])
11
+ end
12
+ else
13
+ stylesheet_link_tag_without_context *(sources + [options])
14
+ end
15
+ end
16
+ alias_method_chain :stylesheet_link_tag, :context
17
+
18
+ def javascript_include_tag_with_context(*sources)
19
+ options = sources.extract_options!.stringify_keys
20
+ context = options.delete("context") || :site
21
+ if context
22
+ assets_with_context context do
23
+ javascript_include_tag_without_context *(sources + [options])
24
+ end
25
+ else
26
+ javascript_include_tag_without_context *(sources + [options])
27
+ end
28
+ end
29
+ alias_method_chain :javascript_include_tag, :context
30
+
31
+ def admin_image_tag(source, options = {})
32
+ options.symbolize_keys!
33
+ src = options[:src] = "/admin/images/#{source}"
34
+ unless src =~ /^cid:/
35
+ options[:alt] = options.fetch(:alt){ File.basename(src, '.*').capitalize }
36
+ end
37
+ if size = options.delete(:size)
38
+ options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
39
+ end
40
+ if mouseover = options.delete(:mouseover)
41
+ options[:onmouseover] = "this.src='/admin/images/#{mouseover}'"
42
+ options[:onmouseout] = "this.src='#{src}'"
43
+ end
44
+ tag("img", options)
45
+ end
46
+
47
+ def compute_public_path_with_context(source, dir, ext = nil, include_host = true)
48
+ r = compute_public_path_without_context(source, dir, ext, include_host)
49
+ @active_context != :site ? "/#{@active_context}#{r}" : r
50
+ end
51
+ alias_method_chain :compute_public_path, :context
52
+
53
+ private
54
+
55
+ def assets_with_context(context, &block)
56
+ @active_context = context
57
+ assets_dir = ActionController::Base.config.assets_dir
58
+ stylesheets_dir = ActionController::Base.config.stylesheets_dir
59
+ javascripts_dir = ActionController::Base.config.javascripts_dir
60
+ if context == :site
61
+ ActionController::Base.config.assets_dir = site_configuration.asset_folder(:base)
62
+ ActionController::Base.config.stylesheets_dir = site_configuration.asset_folder(:stylesheets)
63
+ ActionController::Base.config.javascripts_dir = site_configuration.asset_folder(:javascripts)
64
+ end
65
+
66
+ begin
67
+ yield
68
+ ensure
69
+ ActionController::Base.config.assets_dir = assets_dir
70
+ ActionController::Base.config.stylesheets_dir = stylesheets_dir
71
+ ActionController::Base.config.javascripts_dir = javascripts_dir
72
+ @active_context = nil
73
+ end
74
+ end
75
+
76
+ end
@@ -0,0 +1,7 @@
1
+ require File.join(File.dirname(__FILE__), "platform", "asset_tag_helper")
2
+
3
+ module PlatformHelper
4
+
5
+ include Platform::AssetTagHelper
6
+
7
+ end
@@ -0,0 +1,63 @@
1
+ class Platform::SiteConfiguration
2
+
3
+ def initialize(config_reader, site)
4
+ @config_reader = config_reader
5
+ @site = site
6
+ @assets = {}
7
+ end
8
+
9
+ def get(path)
10
+ config_reader.get site, path
11
+ end
12
+
13
+ def read_array(path, default = nil)
14
+ read_type path, Array, default
15
+ end
16
+
17
+ def read_string(path, default = nil)
18
+ read_type path, String, default
19
+ end
20
+
21
+ def read_hash(path, default = nil)
22
+ read_type path, Hash, default
23
+ end
24
+
25
+ def layout(name, page_type = "templated_page")
26
+ layout_name = get "templates.standard.#{page_type}.#{name}.layout"
27
+ "/#{config_reader.sites_location}#{site}/app/views/layouts/#{layout_name}"
28
+ end
29
+
30
+ def component_enabled? component_name
31
+ !read_array("disabled_components", []).include?(component_name)
32
+ end
33
+
34
+ def asset_folder(type)
35
+ case type
36
+ when :base then
37
+ @assets[:base] ||= File.expand_path(File.join([Rails.root, config_reader.sites_location, site, "public"]))
38
+ else
39
+ @assets[type.to_sym] ||= File.expand_path(File.join([Rails.root, config_reader.sites_location, site, "public", type.to_s]))
40
+ end
41
+ end
42
+
43
+ attr_reader :site
44
+
45
+ private
46
+ attr_reader :config_reader
47
+
48
+ def read_type(path, type, default)
49
+ @cache ||= {}
50
+ return @cache[path] if @cache.has_key? path
51
+ item = get path
52
+ system_default = nil # @defaults[path]
53
+ result = if item.is_a? type
54
+ item
55
+ else
56
+ system_default || default
57
+ end
58
+ result.freeze
59
+ @cache[path] = result
60
+ result
61
+ end
62
+
63
+ end
@@ -0,0 +1,112 @@
1
+ class Platform::SiteManager
2
+
3
+ def initialize(admin_group = "website_bakery", sites_location = "sites/")
4
+ @auto_reloading = %w(development).include?(Rails.env)
5
+ Rails.logger.info "Auto reloading configuration is #{@auto_reloading ? "on" : "off"}."
6
+ @configurations = {}
7
+ @admin_group = admin_group
8
+ @sites_location = sites_location
9
+ end
10
+
11
+ attr_reader :admin_group, :sites_location
12
+
13
+ def get(site, path)
14
+ auto_reload_site site if @auto_reloading
15
+ parts = "#{site}.#{path}".split "." # if path is string
16
+ get_part site, parts, c[site][:config]
17
+ end
18
+
19
+ def get_part(site, parts, root)
20
+ element = parts.shift
21
+ item = root[element.to_s]
22
+ return get_part site, parts, item unless parts.length.zero?
23
+ Rails.logger.info "reading #{item.inspect} from config"
24
+ item
25
+ rescue
26
+ Rails.logger.error "can't read #{parts * "."}"
27
+ end
28
+
29
+ def auto_reload_site(*sites)
30
+ sites.each do |site|
31
+ initialize_site site, :location => sites_location unless c.has_key? site
32
+ file_name = (c[site] || {})[:config_file]
33
+
34
+ if File.exist?(file_name)
35
+ read_time = File.new(file_name).mtime
36
+ if c[site][:config_time].nil? or read_time > c[site][:config_time]
37
+ c[site][:config] = YAML::load_file(file_name)
38
+ c[site][:config_time] = read_time
39
+ load_site site
40
+
41
+ Rails.logger.info "Reloading #{site}"
42
+ end
43
+ else
44
+ Rails.logger.error "Configuration for #{site} (#{file_name}) can not be found"
45
+ raise "Configuration for #{site} (#{file_name}) can not be found"
46
+ end
47
+ end
48
+ end
49
+
50
+ def configuration_for options
51
+ options.assert_valid_keys(:site, :host)
52
+ raise ArgumentError.new("You must provide either :site or :host option") if !!options.has_key?(:site) == !!options.has_key?(:host)
53
+ site = determine_site_by_hostname hostname if options[:host]
54
+ site ||= options[:site]
55
+ Platform::SiteConfiguration.new(self, site)
56
+ end
57
+
58
+ def determine_site_by_hostname(hostname)
59
+ @domain_cache ||= {}
60
+ unless @domain_cache.has_key? hostname
61
+ c.each do |site, settings|
62
+ (get(site, "virtual_hosts") || []).each do |domain|
63
+ @domain_cache[domain] = site
64
+ end
65
+ end
66
+ end
67
+ @domain_cache[hostname] or raise "No configuration found for hostname: #{hostname}"
68
+ end
69
+
70
+ COPYRIGHT = "© 2009-#{Date.today.year} Websitebakery"
71
+
72
+ def self.changelog
73
+ @changelog ||= YAML::load_file(File.join([Rails.root, "doc", "changes.yml"]))["changes"]
74
+ end
75
+
76
+ def self.version
77
+ changelog.keys.sort.last
78
+ end
79
+
80
+ def collect_and_load_sites!
81
+ sites = []
82
+ Dir.foreach(Rails.root + sites_location) do |site|
83
+ site_root = Rails.root + sites_location + site
84
+ if File.directory?(site_root) and !%w(. ..).include?(site)
85
+ sites << site
86
+ initialize_site(site, :location => sites_location)
87
+ end
88
+ end
89
+ auto_reload_site *sites
90
+ end
91
+
92
+ private
93
+
94
+ attr_reader :configurations
95
+ alias :c :configurations
96
+
97
+ def initialize_site(site, options)
98
+ Rails.logger.info("Initializing site: #{site}")
99
+ config_file = "#{Rails.root + options[:location] + site}/config/website.yml"
100
+ c[site] = {:config_file => config_file}
101
+ end
102
+
103
+ def load_site site
104
+ return unless Site.table_exists?
105
+ site_root = Site.find_or_initialize_by_config site
106
+ unless site_root.persisted?
107
+ site_root.name = get(site, "name")
108
+ site_root.save!
109
+ end
110
+ end
111
+
112
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "bakery-core/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "bakery-core"
7
+ s.version = Bakery::Core::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Matthijs Groen", "Pat-Jos Huisman"]
10
+ s.email = ["matthijs.groen@gmail.com", "patjos@websitebakery.nl"]
11
+ s.homepage = ""
12
+ s.summary = %q{core bakery platform functionality}
13
+ s.description = %q{rendering of content, admin interface creation, host redirection}
14
+ s.add_dependency "RedCloth"
15
+ s.add_dependency "rails"
16
+
17
+ s.rubyforge_project = "bakery-core"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
data/config/.gitkeep ADDED
File without changes
@@ -0,0 +1,8 @@
1
+ # nothing special here
2
+ require File.dirname(__FILE__) + '/engine'
3
+
4
+ module Bakery
5
+ module Core
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Bakery
2
+ module Core
3
+ VERSION = "0.0.4"
4
+ end
5
+ end
data/lib/engine.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "bakery-theme"
2
+ require "rails"
3
+
4
+ module Authr
5
+ class Engine < Rails::Engine
6
+ engine_name :bakery_core
7
+ end
8
+ end
@@ -0,0 +1,18 @@
1
+ Description:
2
+ Create a new website skeleton
3
+
4
+ Example:
5
+ rails generate website Workname domainname.nl
6
+
7
+ This will create:
8
+ sites/workname/config/workname.yml
9
+ sites/workname/config/workname
10
+
11
+ sites/workname/app/views/layout
12
+ sites/workname/app/views/templates
13
+ sites/workname/app/views/partials
14
+
15
+ sites/workname/public/stylesheets
16
+ sites/workname/public/javascripts
17
+ sites/workname/public/images
18
+
@@ -0,0 +1,221 @@
1
+ <%= file_name %>:
2
+ name: "<%= name %>"
3
+
4
+ virtual_hosts:
5
+ <%- domain_names.each do |name| -%>
6
+ - "<%= name %>"
7
+ <%- end -%>
8
+
9
+ admin_layout:
10
+ css: "background-image: url(\"/stylesheets/theme/images/bg_wood_eureka.png\");" # css background
11
+ theme: "<%= file_name %>"
12
+ logo: "<%= file_name %>.png"
13
+ #copyright: "&copy; 1494 Christoffel Colombia"
14
+ #link_color: "#C96EC8"
15
+
16
+ disabled_components:
17
+ # - help
18
+ # - chat
19
+ # - hints
20
+ # - user_control
21
+
22
+ page_content_types:
23
+ - "PageFolder" # map
24
+ - "TemplatedPage"
25
+ - "TextLink"
26
+ - "FileDownload"
27
+ - "CustomObject::Page"
28
+ - "PictureFolder" # Deprecated. Picture series are the new way. Picture folder could be revived as CustomContent though
29
+ #- "CustomPage" # Deprecated. Fully replaced by CustomContent
30
+
31
+ #custom_object_types:
32
+ # - "CustomObject::WebshopItem"
33
+
34
+ # users:
35
+ # access:
36
+ # bakery:
37
+ # - "matthijs.groen"
38
+ # - "patjoshuisman"
39
+ # - "hendrikje@hotmail.com"
40
+ # customer:
41
+ # - "matthijs.groen"
42
+ #
43
+ # picasa:
44
+ # - "matthijs.groen"
45
+ # - "patjoshuisman"
46
+
47
+ site_configurations:
48
+ menus:
49
+ -
50
+ name: "top_menu"
51
+ display_name: "Bovenmenu"
52
+ -
53
+ name: "main_menu"
54
+ display_name: "Hoofdmenu"
55
+ -
56
+ name: "test_menu"
57
+ display_name: "Ondermenu"
58
+
59
+ templates:
60
+ standard: # device
61
+ templated_page:
62
+ standard: # mandatory
63
+ preview: "template2.png"
64
+ layout: "<%= file_name %>"
65
+ template: "default"
66
+ description: "Standaard lay-out"
67
+
68
+ picture_folder:
69
+ standard:
70
+ preview: "template2.png"
71
+ layout: "example"
72
+ template: "examples/example_picture_overview"
73
+ description: "Standaard fotoalbum"
74
+ standard_view:
75
+ preview: "template4.png"
76
+ layout: "example"
77
+ template: "examples/example_picture"
78
+ hide: true
79
+
80
+ picture_serie_overview:
81
+ standard:
82
+ preview: "album_template1.png"
83
+ partial: "examples/picture_serie/tiles_overview"
84
+ description: "Tegels"
85
+ picture_serie_popup:
86
+ standard:
87
+ description: "Vergroote afbeelding"
88
+ preview: "template5.png"
89
+ partial: "examples/picture_serie/default_popup"
90
+
91
+ webshop_item_serie_page:
92
+ standard:
93
+ description: "Shop overzicht"
94
+ preview: "album_template1.png"
95
+ layout: "example"
96
+ template: "examples/product_serie"
97
+
98
+ webshop_item_page:
99
+ standard:
100
+ description: "Product pagina"
101
+ preview: "template1.png"
102
+ template: "examples/product"
103
+ layout: "example"
104
+
105
+ image_lists:
106
+ page_image:
107
+ name: "Template afbeeldingen"
108
+ versions:
109
+ -
110
+ name: "side_image"
111
+ display_name: "Zij afbeelding"
112
+ size:
113
+ width: 37
114
+ height: 40
115
+ mode: "exact"
116
+ webshop_images:
117
+ name: "Product afbeeldingen"
118
+ versions:
119
+ -
120
+ name: "thumb_image"
121
+ display_name: "Voorbeeld"
122
+ size:
123
+ width: 200
124
+ height: 200
125
+ mode: "exact"
126
+ -
127
+ name: "normal_image"
128
+ display_name: "Product voorbeeld"
129
+ size:
130
+ width: 400
131
+ height: 600
132
+ mode: "max"
133
+
134
+ picture_album:
135
+ name: "Foto album"
136
+ allowed:
137
+ - picasa
138
+ versions:
139
+ -
140
+ name: "thumb_image"
141
+ display_name: "Voorbeeld miniatuur"
142
+ size:
143
+ width: 200
144
+ height: 200
145
+ mode: "exact"
146
+ -
147
+ name: "normal_image"
148
+ display_name: "Normale versie"
149
+ size:
150
+ width: 700
151
+ height: 700
152
+ mode: "max"
153
+
154
+ flash_banners:
155
+ name: "Flash banners"
156
+ allowed:
157
+ - flash
158
+ versions:
159
+ -
160
+ name: "top_image"
161
+ display_name: "Banner"
162
+ size:
163
+ width: 857
164
+ height: 279
165
+ mode: "exact"
166
+
167
+ picture_album: # example of an picture album. the versions 'thumb_image' and 'normal_image' are mandatory for picture folder to select it.
168
+ name: "Foto album"
169
+ allowed:
170
+ - picasa
171
+ versions:
172
+ -
173
+ name: "thumb_image"
174
+ display_name: "Voorbeeld miniatuur"
175
+ size:
176
+ width: 128
177
+ height: 128
178
+ mode: "max"
179
+ -
180
+ name: "normal_image"
181
+ display_name: "Normale versie"
182
+ size:
183
+ width: 640
184
+ height: 640
185
+ mode: "max"
186
+ # Verplicht voor opslag website afbeeldingen!
187
+ content_images:
188
+ name: "Website afbeeldingen"
189
+ versions:
190
+ -
191
+ name: "website"
192
+ display_name: "Website"
193
+ mode: "variable"
194
+
195
+ dashboard_buttons:
196
+ -
197
+ label: "Statistieken"
198
+ icon: "search"
199
+ url: "https://www.google.com/analytics/settings/?&et=reset&hl=nl-NL"
200
+ -
201
+ label: "E-mail"
202
+ icon: "mail-closed"
203
+ url: "http://www.gmail.com/"
204
+ # -
205
+ # label: "Picasa openen"
206
+ # icon: "image"
207
+ # url: "http://picasaweb.google.com/"
208
+ # email_addresses:
209
+ # - "helpdesk@websitebakery.nl"
210
+ # - "info@websitebakery.nl"
211
+ # - "patjos@websitebakery.nl"
212
+ domains:
213
+ -
214
+ name: "websitebakery.nl"
215
+ expires: "2010-6-1"
216
+ -
217
+ name: "sitebakery.nl"
218
+ expires: "2009-10-1"
219
+ visitor_trackers:
220
+ google_analytics:
221
+ - ""