wheelhouse-banners 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 80065570f906d35e7140cf1b123758e4fbbaaeca
4
+ data.tar.gz: f3702bdfab4b9f653f2a6f3790bcc890bf81e68c
5
+ SHA512:
6
+ metadata.gz: 43b1243516848a89e1d12a8779f2f19c6345994cf9b41195931a5ec90d7e819b00ef04ce45a5ae1bfc1ba0ba181acc95dea7453374e374b493c2c7f00baa743f
7
+ data.tar.gz: 2a5a2f0b0ce990e33146f5976a57cfa6c5cec2da30e0403bf4f41ded3d98492ca3187a725c64865b0a729426555489808c7efc406a0112164eb8723baad5eada
@@ -0,0 +1,9 @@
1
+ @import compass
2
+
3
+ span.tag
4
+ padding: 2px 6px
5
+ background: #dbe2e7
6
+ color: #4e6573
7
+ +border-radius(10px)
8
+ font-size: 90%
9
+
@@ -0,0 +1,17 @@
1
+ class Banners::BannersController < Wheelhouse::ResourceController
2
+ self.resource_class = Banners::Banner
3
+ self.section = :"configuration/banners"
4
+
5
+ before_filter { authorize!(:edit, site) }
6
+
7
+ breadcrumb { ["Banners", banners_path] }
8
+
9
+ def index
10
+ @banners = Banners::Banner.alphabetical
11
+ end
12
+
13
+ protected
14
+ def build_resource
15
+ super.tap { |banner| banner.site = site }
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ class Banners::JavascriptController < Wheelhouse::BaseController
2
+ before_filter { request.format = :js }
3
+ caches_page :all, :tagged
4
+
5
+ def all
6
+ @banners = Banners::Banner.decorate
7
+ render "banners"
8
+ end
9
+
10
+ def tagged
11
+ @banners = Banners::Banner.tagged_with(params[:tag]).decorate
12
+ render "banners"
13
+ end
14
+ end
@@ -0,0 +1,28 @@
1
+ class Banners::BannerDecorator < Wheelhouse::Decorator
2
+ decorates Banners::Banner
3
+
4
+ def as_json(options={})
5
+ result = { :label => source.label, :images => images }
6
+
7
+ if source.url?
8
+ result[:url] = source.url
9
+ result[:target] = source.target if source.target?
10
+ end
11
+
12
+ result
13
+ end
14
+
15
+ private
16
+ def images
17
+ images = {}
18
+ breakpoints.each do |label, breakpoint|
19
+ url = source.image(label).url
20
+ images[breakpoint] = url if url.present?
21
+ end
22
+ images
23
+ end
24
+
25
+ def breakpoints
26
+ Banners::Plugin.config.wheelhouse.banners.breakpoints
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ module Banners::BannerHelper
2
+ def banner(tag=:all)
3
+ javascript_include_tag("/banners/#{tag.to_s.parameterize}", :id => "banner") + noscript_banner_fallback(tag)
4
+ end
5
+
6
+ private
7
+ def noscript_banner_fallback(tag=:all)
8
+ banner = Banners::Banner.default(tag)
9
+ content_tag(:noscript, link_to_if(banner.url?, banner.default_image, banner.url)) if banner && banner.default_image.present?
10
+ end
11
+ end
@@ -0,0 +1,45 @@
1
+ module Banners
2
+ class Banner < Wheelhouse::Resource
3
+ belongs_to :site, :class => 'Wheelhouse::Site'
4
+
5
+ property :label, String, :required => true
6
+ property :url, String
7
+ property :target, String, :default => "_blank"
8
+ property :images, Map[String => Wheelhouse::Media::ImageReference]
9
+ property :tags, Wheelhouse::Tags
10
+
11
+ activities :all
12
+
13
+ icon "banners/banner.png"
14
+
15
+ index :_tags
16
+ before_save { attributes[:_tags] = tags.map(&:parameterize) }
17
+
18
+ scope :alphabetical, order(:label.asc)
19
+ scope :tagged_with, lambda { |tag| where(:_tags => tag.to_s) }
20
+
21
+ after_save :clear_cache!
22
+ after_destroy :clear_cache!
23
+
24
+ self.decorator = Banners::BannerDecorator
25
+
26
+ def image(label)
27
+ images[label] || Wheelhouse::Media::ImageReference.new
28
+ end
29
+
30
+ def default_image
31
+ images.values.first
32
+ end
33
+
34
+ def self.all_tags
35
+ selector = MongoModel::MongoOptions.new(self, {}).to_a.first
36
+ collection.distinct(:tags, selector)
37
+ end
38
+
39
+ def self.default(tag=nil)
40
+ tags = ["default"]
41
+ tags << tag if tag && tag != :all
42
+ tagged_with(tags).first
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,21 @@
1
+ - tab :banner do
2
+ = field :label do
3
+ = form.text_field :label
4
+
5
+ .columns-3
6
+ = field :url, :class => "span-2" do
7
+ = form.text_field :url, :placeholder => "http://"
8
+
9
+ = field :target, :label => "Open link in" do
10
+ = form.select :target, [["New window", "_blank"], ["Current window", nil]]
11
+
12
+ - Banners::Plugin.config.wheelhouse.banners.breakpoints.each do |label, breakpoint|
13
+ = form.fields_for :images do |f|
14
+ = f.field label do
15
+ = f.image label, :value => @banner.image(label)
16
+
17
+ - sidebar :options do
18
+ .shaded
19
+ = field :tags do
20
+ = form.tags :tags, Banners::Banner.all_tags, :placeholder => "Add a tag..."
21
+
@@ -0,0 +1,33 @@
1
+ - title "Banners"
2
+
3
+ .content
4
+ %h2 Current Banners
5
+
6
+ = table_for Banners::Banner do |table|
7
+ = table.rows(@banners) do |row, banner|
8
+ - row.resource = banner
9
+
10
+ = row.icon(banner.icon)
11
+ = row.column(:label, :link => true)
12
+ = row.column(:url)
13
+ = row.column(:tags) { safe_join(banner.tags.map { |tag| content_tag(:span, tag, :class => "tag") }, " ") }
14
+
15
+ = row.controls do |c|
16
+ = c.delete
17
+
18
+ = table.empty do
19
+ No banners have been created.
20
+
21
+ .sidebar
22
+ = render_flash
23
+
24
+ .buttons
25
+ = button "New Banner", :icon => :publish, :url => new_banner_path
26
+
27
+ %hr
28
+
29
+ = render "wheelhouse/admin/configuration/sidebar"
30
+
31
+ = hook(:"site-options.sidebar")
32
+
33
+ - content_for(:head) { stylesheet_link_tag("banners/admin") }
@@ -0,0 +1,74 @@
1
+ (function(window, document) {
2
+
3
+ var banners = [
4
+ <%= safe_join(@banners.map { |banner| banner.to_json.html_safe }, ",\n ") %>
5
+ ];
6
+
7
+ var banner = banners[Math.floor(Math.random() * banners.length)];
8
+
9
+ if (banner) {
10
+ var base = document.createElement("span");
11
+
12
+ var script = document.getElementById('banner');
13
+ script.parentNode.insertBefore(base, script);
14
+
15
+ function matchingImages() {
16
+ var matches = [];
17
+
18
+ for (var breakpoint in banner.images) {
19
+ if (breakpoint !== "default" && banner.images.hasOwnProperty(breakpoint)) {
20
+ if (window.matchMedia && window.matchMedia(breakpoint).matches) {
21
+ matches.push(banner.images[breakpoint]);
22
+ }
23
+ }
24
+ }
25
+
26
+ if (banner.images["default"]) {
27
+ matches.push(banner.images["default"]);
28
+ }
29
+
30
+ return matches;
31
+ }
32
+
33
+ function updateBanner() {
34
+ var matches = matchingImages();
35
+ var img = base.getElementsByTagName("img")[0];
36
+ var el = base.getElementsByTagName("a")[0] || img;
37
+
38
+ if (matches.length) {
39
+ if (!el || el.parentNode.nodeName === "NOSCRIPT") {
40
+ if (banner.url) {
41
+ el = document.createElement("a");
42
+ el.href = banner.url;
43
+ if (banner.target) { el.target = banner.target; }
44
+
45
+ img = document.createElement("img");
46
+ el.appendChild(img);
47
+ } else {
48
+ el = img = document.createElement("img");
49
+ }
50
+
51
+ img.alt = banner.label;
52
+ }
53
+
54
+ img.src = matches[0];
55
+
56
+ base.appendChild(el);
57
+ } else if (img) {
58
+ base.removeChild(el);
59
+ }
60
+ }
61
+
62
+ if (window.addEventListener) {
63
+ window.addEventListener("resize", updateBanner, false);
64
+ window.addEventListener("DOMContentLoaded", function() {
65
+ updateBanner();
66
+ window.removeEventListener("load", updateBanner, false);
67
+ }, false);
68
+ window.addEventListener("load", updateBanner, false);
69
+ } else if (window.attachEvent) {
70
+ window.attachEvent("onload", updateBanner);
71
+ }
72
+ }
73
+
74
+ })(this, document);
@@ -0,0 +1,13 @@
1
+ en:
2
+ resource:
3
+ attributes:
4
+ banners/banner:
5
+ url: URL
6
+
7
+ sections:
8
+ configuration/banners: Edit Banners
9
+
10
+ links:
11
+ configuration/banners:
12
+ new_banner: New Banner
13
+
@@ -0,0 +1,14 @@
1
+ # Admin routes (scoped to /admin)
2
+ Banners::Plugin.routes.draw do
3
+ extend Wheelhouse::RouteExtensions
4
+
5
+ resources :banners
6
+ end
7
+
8
+ # Front-end routes
9
+ Rails.application.routes.draw do
10
+ controller "banners/javascript" do
11
+ get "/banners/all.js" => :all
12
+ get "/banners/:tag.js" => :tagged
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ require 'wheelhouse'
2
+
3
+ module Banners
4
+ class Plugin < Wheelhouse::Plugin
5
+ config.wheelhouse.banners = ActiveSupport::OrderedOptions.new
6
+
7
+ # Set default breakpoints
8
+ config.wheelhouse.banners.breakpoints = { "Default" => :default }
9
+
10
+ isolate_namespace Banners
11
+
12
+ section(:configuration) {
13
+ Section(:"configuration/banners", banners.banners_path,
14
+ :icon => "banners/banner.png",
15
+ :if => proc { can?(:edit, site) }
16
+ ) do |section|
17
+ section.link(:"configuration/banners.new_banner", banners.new_banner_path)
18
+ end
19
+ }
20
+
21
+ config.precompile << "banners/admin.*"
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wheelhouse-banners
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Sam Pohlenz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: wheelhouse
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.0
27
+ description: Allows advertising banners to be added to a Wheelhouse CMS site.
28
+ email: sam@wheelhousecms.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - app/assets/images/banners/banner.png
34
+ - app/assets/stylesheets/banners/admin.sass
35
+ - app/controllers/banners/banners_controller.rb
36
+ - app/controllers/banners/javascript_controller.rb
37
+ - app/decorators/banners/banner_decorator.rb
38
+ - app/helpers/banners/banner_helper.rb
39
+ - app/models/banners/banner.rb
40
+ - app/views/banners/banners/form.haml
41
+ - app/views/banners/banners/index.html.haml
42
+ - app/views/banners/javascript/banners.js.erb
43
+ - config/locales/en.yml
44
+ - config/routes.rb
45
+ - lib/wheelhouse-banners.rb
46
+ homepage: https://www.wheelhousecms.com
47
+ licenses:
48
+ - MIT
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 1.8.7
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 1.3.6
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.4.6
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Responsive banners plugin for Wheelhouse CMS
70
+ test_files: []
71
+ has_rdoc: