Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2b1b095
Showing
13 changed files
with
308 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
*.gem | ||
*.rbc | ||
.bundle | ||
.config | ||
.yardoc | ||
Gemfile.lock | ||
InstalledFiles | ||
_yardoc | ||
coverage | ||
doc/ | ||
lib/bundler/man | ||
pkg | ||
rdoc | ||
spec/reports | ||
test/tmp | ||
test/version_tmp | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in ress.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2013 Matthew Robertson | ||
|
||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Ress | ||
|
||
TODO: Write a gem description | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
gem 'ress' | ||
|
||
And then execute: | ||
|
||
$ bundle | ||
|
||
Or install it yourself as: | ||
|
||
$ gem install ress | ||
|
||
## Usage | ||
|
||
TODO: Write usage instructions here | ||
|
||
## Contributing | ||
|
||
1. Fork it | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Commit your changes (`git commit -am 'Add some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
5. Create new Pull Request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require "bundler/gem_tasks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require "ress/version" | ||
require "ress/device_category" | ||
|
||
module Ress | ||
|
||
@@categories = [] | ||
|
||
def self.register_category(options) | ||
category = DeviceCategory.new(options.delete(:name), options.delete(:media_type), options) | ||
@@categories << category | ||
end | ||
|
||
def self.categories | ||
@@categories | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Ress | ||
|
||
# This module is automatically included into all controllers. | ||
module ControllerAdditions | ||
module ClassMethods | ||
# class methods go here | ||
end | ||
|
||
def self.included(base) | ||
base.extend ClassMethods | ||
# base.helper_method :can?, :cannot?, :current_ability | ||
base.before_filter :prepend_category_view_path | ||
end | ||
|
||
def prepend_category_view_path | ||
Ress.categories.each do |cat| | ||
prepend_view_path(cat.view_path) if cat.matches?(request.subdomain) | ||
end | ||
end | ||
|
||
end | ||
end | ||
|
||
if defined? ActionController::Base | ||
ActionController::Base.class_eval do | ||
include CanCan::ControllerAdditions | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Ress | ||
|
||
class DeviceCategory | ||
|
||
attr_reader :name, :subdomain, :view_path | ||
|
||
def initialize(name, media_query, options = {}) | ||
@name = name | ||
@media_query = media_query | ||
@subdomain = options.fetch(:subdomain, name) | ||
@view_path = options.fetch(:view_path, default_view_path) | ||
end | ||
|
||
def matches?(subdomain) | ||
self.subdomain == subdomain.split('.').first | ||
end | ||
|
||
private | ||
|
||
def default_view_path | ||
name | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Ress | ||
VERSION = "0.0.1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- encoding: utf-8 -*- | ||
lib = File.expand_path('../lib', __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require 'ress/version' | ||
|
||
Gem::Specification.new do |gem| | ||
gem.name = "ress" | ||
gem.version = Ress::VERSION | ||
gem.authors = ["Matthew Robertson"] | ||
gem.email = ["matthewrobertson03@gmail.com"] | ||
gem.description = %q{TODO: Write a gem description} | ||
gem.summary = %q{TODO: Write a gem summary} | ||
gem.homepage = "" | ||
|
||
gem.files = `git ls-files`.split($/) | ||
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } | ||
gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) | ||
gem.require_paths = ["lib"] | ||
|
||
gem.add_development_dependency("rspec") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require_relative '../../lib/ress/controller_additions' | ||
|
||
class ActionControllerStub | ||
|
||
attr_accessor :request | ||
|
||
def self.before_filter(action) | ||
@@action = action | ||
end | ||
|
||
def self.action | ||
@@action | ||
end | ||
|
||
end | ||
|
||
ActionControllerStub.class_eval do | ||
include Ress::ControllerAdditions | ||
end | ||
|
||
describe Ress::ControllerAdditions do | ||
|
||
it 'adds a before_filter to all actions when it is included' do | ||
ActionControllerStub.action.should == :prepend_category_view_path | ||
end | ||
|
||
describe '#prepend_category_view_path' do | ||
|
||
let(:controller) { ActionControllerStub.new } | ||
|
||
before do | ||
request = stub('request', :subdomain => 'foo') | ||
controller.request = request | ||
end | ||
|
||
it 'prepends view paths of matching categories' do | ||
category = stub('category', :matches? => true, :view_path => 'foo/bar') | ||
Ress.stub(:categories => [category]) | ||
|
||
controller.should_receive(:prepend_view_path).with('foo/bar') | ||
controller.prepend_category_view_path | ||
end | ||
|
||
it 'does not prepend view paths of categories that dont match' do | ||
category = stub('category', :matches? => false, :view_path => 'foo/bar') | ||
Ress.stub(:categories => [category]) | ||
|
||
controller.should_not_receive(:prepend_view_path) | ||
controller.prepend_category_view_path | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require_relative '../../lib/ress/device_category' | ||
|
||
describe Ress::DeviceCategory do | ||
|
||
describe '#subdomain' do | ||
|
||
it 'defaults to the name of the category' do | ||
category = Ress::DeviceCategory.new('mobile', 'some media query') | ||
category.subdomain.should == 'mobile' | ||
end | ||
|
||
it 'can be overridden by an optional parameter' do | ||
category = Ress::DeviceCategory.new('mobile', 'some media query', :subdomain => 'foo') | ||
category.subdomain.should == 'foo' | ||
end | ||
|
||
end | ||
|
||
describe '#view_path' do | ||
|
||
it 'defaults to something' | ||
|
||
it 'can be overridden by an optional parameter' do | ||
category = Ress::DeviceCategory.new('mobile', 'some media query', :view_path => 'foo') | ||
category.view_path.should == 'foo' | ||
end | ||
|
||
end | ||
|
||
describe '#matches?' do | ||
|
||
let(:category) { Ress::DeviceCategory.new('mobile', 'some media query', :subdomain => 'foo') } | ||
|
||
it 'returns true if the subdomain matches' do | ||
category.matches?('foo').should be_true | ||
end | ||
|
||
it 'returns false if the subdomain does not match' do | ||
category.matches?('bar').should be_false | ||
end | ||
|
||
context 'when there are multiple subdomains' do | ||
|
||
it 'returns true if the first subdomain matches' do | ||
category.matches?('foo.bar').should be_true | ||
end | ||
|
||
it 'returns false if the first subdomain does not match' do | ||
category.matches?('bar.baz').should be_false | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require_relative '../lib/ress' | ||
|
||
describe Ress do | ||
|
||
describe '.configure' do | ||
|
||
it 'yeilds Ress' | ||
|
||
end | ||
|
||
describe '.register_category' do | ||
|
||
it 'adds a category to list' do | ||
expect { | ||
Ress.register_category({:name => 'stuff', :media_query => 'foo'}) | ||
}.to change { Ress.categories.count }.by(1) | ||
end | ||
|
||
it 'sets the name and media_query of the category' do | ||
Ress.register_category({:name => 'stuff', :media_query => 'foo'}) | ||
Ress.categories.last.name.should == 'stuff' | ||
end | ||
|
||
it 'passes options tot he category' do | ||
Ress.register_category({:name => 'stuff', :media_query => 'foo', :subdomain => 'm'}) | ||
Ress.categories.last.subdomain.should == 'm' | ||
end | ||
|
||
end | ||
|
||
end |