bakery-theme 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bakery-theme.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,100 @@
1
+ module BakeryTheme
2
+ module ObjectListHelper
3
+
4
+ def group_list(options = {}, &block)
5
+ attributes = options
6
+ attributes[:class] ||= []
7
+ attributes[:class] << "content_items"
8
+ attributes[:class] << "object_list" # folder_item_list
9
+ attributes[:class] << @content_space
10
+ content = capture do
11
+ yield
12
+ end
13
+ content_tag :ol, content, tag_attributes_for(attributes)
14
+ end
15
+
16
+ def object_list(options = {}, &block)
17
+ sortable = options.delete :sortable
18
+ object = options.delete :object
19
+ display_mode = options.delete :display_mode
20
+ custom_class = options.delete :class
21
+ refresh_url = options.delete :update
22
+
23
+ attributes = options
24
+ attributes[:id] = dom_id(object, :children) if object
25
+ attributes[:'data-change-url'] = refresh_url if refresh_url
26
+ attributes[:class] ||= []
27
+ attributes[:class] << custom_class if custom_class
28
+ attributes[:class] << "object_list" #folder_item_list
29
+ attributes[:class] << "content_list"
30
+ attributes[:class] << "content_items"
31
+ attributes[:class] << "grid_display" if display_mode == :grid
32
+ attributes[:class] << "sortable_content" if sortable
33
+ attributes[:class] << @content_space
34
+ content = capture do
35
+ yield
36
+ end
37
+ content << content_tag(:li, "", :class => "dragspace") if sortable
38
+ content_tag :ol, content, tag_attributes_for(attributes)
39
+ end
40
+
41
+ def object_list_item_for object, options = {}
42
+ item = ObjectListItem.new object, options, self
43
+ yield item if block_given?
44
+ item.to_html
45
+ end
46
+
47
+ private
48
+
49
+ def tag_attributes_for(attributes)
50
+ case attributes[:id]
51
+ when ActiveRecord::Base then
52
+ attributes[:id] = dom_id(attributes[:id])
53
+ end
54
+ attributes[:class] = attributes[:class].join " "
55
+ attributes
56
+ end
57
+
58
+ class ObjectListItem
59
+
60
+ def initialize(object, options, template)
61
+ @object = object
62
+ @options = options
63
+ @template = template
64
+ end
65
+
66
+ attr_reader :object, :options
67
+
68
+ def to_html
69
+ content = ""
70
+ content << %(<a name="#{options[:ref]}"></a>).html_safe if options[:ref]
71
+ content << %(<span class="icon"></span>)
72
+
73
+ inner_contents = %(<h3 class="file_name">#{h options[:name]}</h3>).html_safe
74
+
75
+ content << content_tag(:div, inner_contents, :class => "item_contents")
76
+
77
+ item = content_tag :div, content.html_safe, :class => ["ui-widget-content", "ui-helper-clearfix"].compact.join(" ")
78
+ content_tag :li, item, :id => dom_id(object), :class => [dom_class(object), "ui-widget", "ui-helper-clearfix", options[:type]].compact.map(&:to_s).join(" ")
79
+ end
80
+
81
+ private
82
+ attr_reader :template
83
+ delegate :content_tag, :dom_id, :dom_class, :h, :to => :template
84
+
85
+ end
86
+
87
+ # = object_item_for site, :name => site.name, :ref => site.config, :type => :cropped_image #do |object|
88
+ # -#- object.left_tools do |tools|
89
+ # -# - tools.button root_url, :icon => "lightbulb", :hint => "dingen"
90
+ #
91
+ # %li.ui-widget.ui-helper-clearfix[site]
92
+ # .ui-widget-content.ui-helper-clearfix.cropped_image
93
+ # %a{:name => site.config }
94
+ # %span.icon
95
+ # .item_contents
96
+ # %h3.file_name= site.name
97
+ # -#= render :partial => content_item.tools_partial, :object => content_item.content, :locals => { :content_item => content_item }
98
+
99
+ end
100
+ end
@@ -0,0 +1,390 @@
1
+ module BakeryTheme
2
+ module ToolbarHelper
3
+
4
+ def toolbar(options = {}, &block)
5
+ raise "Block required" unless block_given?
6
+ t = Toolbar.new self, options
7
+ yield t
8
+ t.to_html
9
+ end
10
+
11
+ class Toolbar
12
+
13
+ def initialize(template, options = {})
14
+ @template = template
15
+ @options = options
16
+ @items = []
17
+ end
18
+
19
+ def flag(options={})
20
+ options = {:label => options} if options.is_a? String
21
+ button nil, options
22
+ end
23
+
24
+ def panel_header text
25
+ contents = content_tag :h3, text, :class => "panel-header"
26
+ @items << content_tag(:li, contents.html_safe)
27
+ end
28
+
29
+ def submit_button(form_id, options={}, &block)
30
+ options = {:primary => true}.reverse_merge options
31
+
32
+ contents = ""
33
+ contents = yield if block_given?
34
+
35
+ if form_id.nil?
36
+ button :submit, options
37
+ else
38
+ button nil, options.update(:function => "#{contents} " +
39
+ "var submitCode = $(\"##{form_id}\").attr(\"onsubmit\");\n" +
40
+ "if (submitCode) {\n" +
41
+ "eval(\"var test = $.bind(function() { \" + submitCode + \" }, $(\\\"##{form_id}\\\"));\");\n" +
42
+ "var result = test();" +
43
+ "if (result == false) return false;" +
44
+ "}\n" +
45
+ "$(\"##{form_id}\").submit();")
46
+ end
47
+ end
48
+
49
+ #
50
+ # Usage:
51
+ # url - url to link to
52
+ # options - the following keys can be used:
53
+ # :class - adds a css class to the button list item
54
+ # :state - sets the jquery UI state on the link
55
+ # other options are redirected to icon_link_to, but those include:
56
+ # :class - adds a css class for the link
57
+ # :label - label to show
58
+ # :icon - jquery-ui icon to show. the first part ui-icon- is prefixed automatically
59
+ # :remote - boolean. Then true, link_to_remote is used instead
60
+ # :function - when set, link_to_function is used instead
61
+ # all other options are redirected to the link_to method
62
+ #
63
+ def button(url, options={})
64
+ # new_container_type_path, :label => t(:add), :icon => :plusthick
65
+
66
+ # <a title="Toevoegen" class="ui-state-default ui-corner-all" href="">
67
+ # <span class="ui-icon ui-icon-plusthick"></span> Toevoegen
68
+ # </a>
69
+ options = options.clone.reverse_merge @options[:standard_options] if @options[:standard_options]
70
+ button_class = options.delete :class
71
+ state = options.delete :state
72
+ state ||= :default
73
+
74
+ add_i18n_support options, state
75
+
76
+ button_options = {}
77
+ button_classes = []
78
+ button_classes << "ui-state-default"
79
+ button_classes << "ui-state-#{state}"
80
+ button_classes << "ui-state-transparent" if options.delete :transparent
81
+ button_classes << "ui-corner-all" unless options.delete :no_corner
82
+
83
+ options[:class] = button_classes.uniq * " "
84
+
85
+ if url == :submit
86
+ button_content = icon_link_content(options)
87
+ link = content_tag(:button, button_content.html_safe, options.merge(:type => "submit"))
88
+ elsif url == :button
89
+ button_content = icon_link_content(options)
90
+ link = content_tag(:button, button_content.html_safe, options.merge(:type => "button"))
91
+ else
92
+ link = icon_link_to url, options
93
+ end
94
+ @items << content_tag(:li, link.html_safe, :class => button_class)
95
+ end
96
+
97
+ def choice_dialog(options, &block)
98
+ raise "Block required" unless block_given?
99
+ dialog_settings = options.delete :dialog
100
+ dialog_settings[:id] ||= (0...6).map { ('a'..'z').to_a[rand(26)] }.join
101
+
102
+ bar = Interface::Toolbar.new @template, :transparent => true,
103
+ :standard_options => {
104
+ :before_click => "$('##{dialog_settings[:id]}').dialog('destroy'); setTimeout('$(\\'##{dialog_settings[:id]}\\').remove()', 500)"
105
+ }
106
+ yield bar
107
+ button_bar = bar.to_html
108
+ dialog_code = %(<div title="#{dialog_settings[:title]}" id="#{dialog_settings[:id]}">
109
+ <p>#{"<span class=\"ui-icon ui-icon-#{dialog_settings[:icon]}\" style=\"float:left; margin:0 7px 20px 0;\"></span>" if dialog_settings[:icon]}
110
+ #{dialog_settings[:message]}
111
+ </p>
112
+ #{button_bar}
113
+ </div>)
114
+ dialog_code
115
+ javascript_code = "$('#{escape_javascript(dialog_code)}').dialog({ resizable: false, modal: true, position: ['center', 100] })"
116
+
117
+ button nil, options.update(:function => javascript_code)
118
+ end
119
+
120
+ def to_html
121
+ # <ul class="ui-widget ui-helper-clearfix toolbar">
122
+ # <li>
123
+ bar_class = @options[:class]
124
+ bar_class ||= "toolbar"
125
+
126
+ classes = []
127
+ classes << "ui-widget"
128
+ classes << "ui-helper-reset"
129
+ classes << "ui-helper-clearfix"
130
+ classes << "ui-widget-header" unless @options[:transparent]
131
+ classes << bar_class
132
+
133
+ toolbar_options = {
134
+ :class => classes * " "
135
+ }
136
+ toolbar_options[:id] = @template.dom_id(@options[:object], :tools) if @options[:object]
137
+ toolbar_options[:style] = @options[:style] if @options[:style]
138
+ content_tag :ul, (@items * "").html_safe, toolbar_options
139
+ end
140
+
141
+ def tab(url, options={})
142
+ # new_container_type_path, :label => t(:add), :icon => :plusthick
143
+
144
+ # <a title="Toevoegen" class="ui-state-default ui-corner-all" href="">
145
+ # <span class="ui-icon ui-icon-plusthick"></span> Toevoegen
146
+ # </a>
147
+ button_class = options.delete :class
148
+ state = options.delete :state
149
+ state ||= :default
150
+ button_options = {}
151
+ button_classes = []
152
+ button_classes << "ui-state-default"
153
+ button_classes << "ui-state-#{state}"
154
+ button_classes << "ui-corner-top tab"
155
+
156
+ options[:class] = button_classes.uniq * " "
157
+
158
+ link = icon_link_to url, options
159
+ @items << content_tag(:li, link, :class => button_class)
160
+ end
161
+
162
+ def select_button(url, options={}, &block)
163
+ raise "Block required" unless block_given?
164
+
165
+ state = options.delete :state
166
+ state ||= :default
167
+ add_i18n_support options, state
168
+
169
+ button_class = options.delete :class
170
+ state = options.delete :state
171
+ state ||= :default
172
+ button_options = {}
173
+ button_classes = []
174
+ unless options[:transparent]
175
+ button_classes << "ui-state-default"
176
+ button_classes << "ui-state-#{state}"
177
+ else
178
+ button_classes << "ui-state-transparent"
179
+ end
180
+ select_button_classes = button_classes.clone << "ui-corner-left" << "select_button"
181
+ options[:class] = select_button_classes.uniq * " "
182
+
183
+ link = icon_link_to url, options
184
+
185
+ select_options_classes = button_classes.clone << "ui-corner-right" << "open_options"
186
+ select_options = icon_link_to "#options",
187
+ :class => select_options_classes.uniq * " ",
188
+ :icon => "carat-1-s"
189
+
190
+ option_list = Interface::Toolbar.new self, :class => "option_list right ui-corner-all ui-widget-content ui-state-default",
191
+ :standard_options => {:transparent => true},
192
+ :style => "display: none;",
193
+ :transparent => true
194
+ yield option_list
195
+ select_options += option_list.to_html
196
+
197
+
198
+ @items << content_tag(:li, link + select_options, :class => button_class)
199
+ end
200
+
201
+ def select(options={}, &block)
202
+ raise "Block required" unless block_given?
203
+
204
+ state = options.delete :state
205
+ state ||= :default
206
+ add_i18n_support options, state
207
+
208
+ button_class = options.delete :class
209
+ state = options.delete :state
210
+ state ||= :default
211
+ button_options = {}
212
+ button_classes = []
213
+ unless options[:transparent]
214
+ button_classes << "ui-state-default"
215
+ button_classes << "ui-state-#{state}"
216
+ else
217
+ button_classes << "ui-state-transparent"
218
+ end
219
+ select_button_classes = button_classes.clone << "ui-corner-all" << "open_options"
220
+ options[:class] = select_button_classes.uniq * " "
221
+ options[:right_icon] ||= "triangle-1-s"
222
+
223
+ link = icon_link_to "#options", options
224
+
225
+ #select_options_classes = button_classes.clone << "ui-corner-right" << "open_options"
226
+ #select_options = icon_link_to ,
227
+ # :class => select_options_classes.uniq * " ",
228
+ # :icon => "carat-1-s"
229
+
230
+ option_list = Toolbar.new self, :class => "option_list ui-corner-all ui-widget-content ui-state-default",
231
+ :standard_options => {:transparent => true},
232
+ :style => "display: none;",
233
+ :transparent => true
234
+ yield option_list
235
+ select_options = option_list.to_html
236
+
237
+
238
+ @items << content_tag(:li, link + select_options, :class => button_class)
239
+ end
240
+
241
+ private
242
+
243
+ attr_reader :template
244
+ delegate :content_tag, :link_to, :h, :t, :escape_javascript, :to => :template
245
+
246
+ def icon_link_content(options = {})
247
+ content = []
248
+ icon = options.delete :icon
249
+ label = options.delete :label
250
+ right_icon = options.delete :right_icon
251
+
252
+ if options[:primary]
253
+ link_class = [options[:class], "ui-priority-primary"].compact.join " "
254
+ options[:class] = link_class
255
+ end
256
+
257
+ icon_classes = []
258
+ icon_classes << "ui-icon"
259
+ icon_classes << "ui-icon-#{icon}"
260
+ icon_classes << "with-label" if label
261
+
262
+ right_icon_classes = []
263
+ right_icon_classes << "ui-icon" << "right"
264
+ right_icon_classes << "ui-icon-#{right_icon}"
265
+ right_icon_classes << "with-label" if label
266
+
267
+ #url ||= "#"
268
+
269
+ content << content_tag(:span, "", :class => icon_classes * " ") if icon
270
+ content << content_tag(:span, label.html_safe, :class => "label") if label
271
+ content << content_tag(:span, "", :class => right_icon_classes * " ") if right_icon
272
+ (content * "").html_safe
273
+ end
274
+
275
+ # Creates an link with an label and/or jquery-ui-icon
276
+ #
277
+ # Usage:
278
+ # url - url to link to
279
+ # options - the following keys can be used:
280
+ # :class - adds a css class for the link
281
+ # :label - label to show
282
+ # :icon - jquery-ui icon to show. the first part ui-icon- is prefixed automatically
283
+ # :remote - boolean. Then true, link_to_remote is used instead
284
+ # :function - when set, link_to_function is used instead
285
+ # all other options are redirected to the link_to method
286
+ #
287
+ def icon_link_to(url, options = {})
288
+ link_content = icon_link_content options
289
+
290
+ js_function = nil
291
+ link_url = nil
292
+
293
+ if options.delete :remote
294
+ method = options.delete(:method) || :get
295
+ remote_options = {:url => url, :method => method}
296
+
297
+ if options[:confirm].is_a?(String) and confirm = options.delete(:confirm)
298
+ remote_options[:confirm] = confirm
299
+ end
300
+ js_function = remote_function(remote_options)
301
+ link_url = url
302
+ elsif options[:function]
303
+ js_function = options.delete :function
304
+ elsif url
305
+ link_url = url
306
+ end
307
+ if options[:confirm].is_a?(Hash)
308
+ js_function = "document.location.href=\"#{escape_javascript(link_url)}\"" if link_url and js_function.nil?
309
+ end
310
+ if options[:confirm].is_a?(Hash)
311
+ js_function = build_confirm_link(js_function || "", options)
312
+ options.delete :confirm
313
+ end
314
+ if before_click = options.delete(:before_click)
315
+ if js_function
316
+ js_function = "#{before_click}; #{js_function}; return false;"
317
+ elsif link_url
318
+ js_function = "#{before_click}; return true;"
319
+ else
320
+ js_function = "#{before_click}; return false;"
321
+ end
322
+ elsif js_function
323
+ js_function = "#{js_function}; return false;"
324
+ end
325
+
326
+ if link_url and not js_function
327
+ link_to link_content, link_url, options
328
+ else
329
+ options[:onclick] = js_function if js_function
330
+ options[:href] = link_url || "#" if link_url || js_function
331
+ tag = (js_function || link_url) ? :a : :span
332
+ content_tag tag, link_content.html_safe, options
333
+ end
334
+ end
335
+
336
+ def build_confirm_link(js_function, options)
337
+ attributes = options.dup
338
+ confirm_options = {:title => "Bevestiging",
339
+ :icon => :alert,
340
+ :message => "Weet u het zeker?",
341
+ :buttons => {"Ja" => :continue,
342
+ "Nee" => :cancel}}.update(attributes.delete :confirm)
343
+
344
+ dialog_code = %(<div title="#{confirm_options[:title]}">
345
+ <p>#{"<span class=\"ui-icon ui-icon-#{confirm_options[:icon]}\" style=\"float:left; margin:0 7px 20px 0;\"></span>" if confirm_options[:icon]}
346
+ #{confirm_options[:message]}
347
+ </p>
348
+ </div>)
349
+ dialog_code
350
+ button_code = []
351
+ confirm_options[:buttons].each do |label, action|
352
+ action_code = action
353
+ action_code = "$(this).dialog('close'); #{js_function}" if action == :continue
354
+ action_code = "$(this).dialog('close')" if action == :cancel
355
+ button_code << "'#{escape_javascript(label)}': function() { #{action_code}; }"
356
+ end
357
+
358
+ %(
359
+ $('#{escape_javascript(dialog_code)}').dialog({
360
+ resizable: false,
361
+ modal: true,
362
+ position: ['center', 100],
363
+ buttons: {
364
+ #{button_code * ", "}
365
+ }
366
+ })
367
+ )
368
+ end
369
+
370
+
371
+ def add_i18n_support(options, state)
372
+
373
+ options[:label] = "" if options[:label] === false
374
+ options[:icon] = "" if options[:icon] === false
375
+ options[:title] = "" if options[:title] === false
376
+
377
+ if options.has_key? :i18n
378
+ i18n_key = options.delete :i18n
379
+ options[:label] ||= t("label", :scope => [:toolbar, state, i18n_key], :default => "")
380
+ options[:icon] ||= t("icon", :scope => [:toolbar, state, i18n_key], :default => "")
381
+ options[:title] ||= t("hint", :scope => [:toolbar, state, i18n_key], :default => "")
382
+ end
383
+ options.delete :label if options[:label].blank?
384
+ options.delete :icon if options[:icon].blank?
385
+ options.delete :title if options[:title].blank?
386
+ end
387
+
388
+ end
389
+ end
390
+ end
@@ -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,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "bakery-theme/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "bakery-theme"
7
+ s.version = Bakery::Theme::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Matthijs Groen"]
10
+ s.email = ["matthijs.groen@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Website Bakery CMS Theme}
13
+ s.description = %q{This theme includes helper methods, javascripts and stylesheets for the theme of the WebsiteBakery CMS}
14
+
15
+ s.rubyforge_project = "bakery-theme"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
data/config/.gitkeep ADDED
File without changes
@@ -0,0 +1,2 @@
1
+ # nothing special here
2
+ require File.dirname(__FILE__) + '/engine'
@@ -0,0 +1,5 @@
1
+ module Bakery
2
+ module Theme
3
+ VERSION = "0.0.11"
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_theme
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bakery-theme
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 11
10
+ version: 0.0.11
11
+ platform: ruby
12
+ authors:
13
+ - Matthijs Groen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-19 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: This theme includes helper methods, javascripts and stylesheets for the theme of the WebsiteBakery CMS
23
+ email:
24
+ - matthijs.groen@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - Rakefile
35
+ - app/helpers/bakery_theme/object_list_helper.rb
36
+ - app/helpers/bakery_theme/toolbar_helper.rb
37
+ - app/helpers/bakery_theme_helper.rb
38
+ - bakery-theme.gemspec
39
+ - config/.gitkeep
40
+ - lib/bakery-theme.rb
41
+ - lib/bakery-theme/version.rb
42
+ - lib/engine.rb
43
+ has_rdoc: true
44
+ homepage: ""
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ requirements: []
71
+
72
+ rubyforge_project: bakery-theme
73
+ rubygems_version: 1.4.1
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Website Bakery CMS Theme
77
+ test_files: []
78
+