impartial 0.0.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.
@@ -0,0 +1,2 @@
1
+ pkg/
2
+ tmp/
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ gemspec
@@ -0,0 +1,90 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ impartial (0.0.1)
5
+ activesupport (~> 3.0)
6
+ hbs (~> 0.1.2)
7
+ railties (~> 3.0)
8
+
9
+ GEM
10
+ specs:
11
+ actionpack (3.1.3)
12
+ activemodel (= 3.1.3)
13
+ activesupport (= 3.1.3)
14
+ builder (~> 3.0.0)
15
+ erubis (~> 2.7.0)
16
+ i18n (~> 0.6)
17
+ rack (~> 1.3.5)
18
+ rack-cache (~> 1.1)
19
+ rack-mount (~> 0.8.2)
20
+ rack-test (~> 0.6.1)
21
+ sprockets (~> 2.0.3)
22
+ activemodel (3.1.3)
23
+ activesupport (= 3.1.3)
24
+ builder (~> 3.0.0)
25
+ i18n (~> 0.6)
26
+ activesupport (3.1.3)
27
+ multi_json (~> 1.0)
28
+ builder (3.0.0)
29
+ cucumber (1.1.3)
30
+ builder (>= 2.1.2)
31
+ diff-lcs (>= 1.1.2)
32
+ gherkin (~> 2.6.7)
33
+ json (>= 1.4.6)
34
+ term-ansicolor (>= 1.0.6)
35
+ diff-lcs (1.1.3)
36
+ erubis (2.7.0)
37
+ gherkin (2.6.9)
38
+ json (>= 1.4.6)
39
+ hbs (0.1.2)
40
+ therubyracer (~> 0.9.4)
41
+ hike (1.2.1)
42
+ i18n (0.6.0)
43
+ json (1.6.3)
44
+ libv8 (3.3.10.4)
45
+ multi_json (1.0.4)
46
+ rack (1.3.5)
47
+ rack-cache (1.1)
48
+ rack (>= 0.4)
49
+ rack-mount (0.8.3)
50
+ rack (>= 1.0.0)
51
+ rack-ssl (1.3.2)
52
+ rack
53
+ rack-test (0.6.1)
54
+ rack (>= 1.0)
55
+ railties (3.1.3)
56
+ actionpack (= 3.1.3)
57
+ activesupport (= 3.1.3)
58
+ rack-ssl (~> 1.3.2)
59
+ rake (>= 0.8.7)
60
+ rdoc (~> 3.4)
61
+ thor (~> 0.14.6)
62
+ rake (0.9.2.2)
63
+ rdoc (3.11)
64
+ json (~> 1.4)
65
+ rspec (2.7.0)
66
+ rspec-core (~> 2.7.0)
67
+ rspec-expectations (~> 2.7.0)
68
+ rspec-mocks (~> 2.7.0)
69
+ rspec-core (2.7.1)
70
+ rspec-expectations (2.7.0)
71
+ diff-lcs (~> 1.1.2)
72
+ rspec-mocks (2.7.0)
73
+ sprockets (2.0.3)
74
+ hike (~> 1.2)
75
+ rack (~> 1.0)
76
+ tilt (~> 1.1, != 1.3.0)
77
+ term-ansicolor (1.0.7)
78
+ therubyracer (0.9.9)
79
+ libv8 (~> 3.3.10)
80
+ thor (0.14.6)
81
+ tilt (1.3.3)
82
+
83
+ PLATFORMS
84
+ ruby
85
+
86
+ DEPENDENCIES
87
+ cucumber
88
+ impartial!
89
+ rake (~> 0.9.2)
90
+ rspec (~> 2.7)
@@ -0,0 +1,20 @@
1
+ Copyright 2011 Logan Lowell
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
File without changes
@@ -0,0 +1,19 @@
1
+ require 'bundler'
2
+ require 'bundler/setup'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ # task :default => :spec
7
+
8
+ require "cucumber/rake/task"
9
+
10
+ Cucumber::Rake::Task.new(:cucumber) do |task|
11
+ task.cucumber_opts = ["features"]
12
+ end
13
+
14
+ desc "Remove all generated artifacts"
15
+ task :clean do
16
+ sh "rm -rf pkg"
17
+ sh "rm -rf tmp"
18
+ end
19
+
@@ -0,0 +1,15 @@
1
+ Feature: Impartials raise errors
2
+
3
+ As a developer
4
+ I want descriptive errors when things go wrong
5
+ So that I dont go completely insane
6
+
7
+ Scenario: An impartial controller is missing
8
+ Given a missing impartial controller named "Waldo"
9
+ When I try to render the impartial
10
+ Then I should get a class not found exception
11
+
12
+ Scenario: An impartial is missing it's template
13
+ Given an impartial named "Waldo"
14
+ And it's missing it's template
15
+ Then I should get a template missing exception
@@ -0,0 +1,22 @@
1
+ Feature: Render an impartial view
2
+
3
+ As a developer
4
+ I want to have self-contained embeddable document
5
+ So that I can DRY up my software
6
+
7
+ Scenario: Simple handlebars with LESS impartial
8
+ Given an impartial named "macguffin"
9
+ And it has a handlebars template
10
+ Then I can render the impartial to a string
11
+
12
+ Scenario: Impartial in a custom location
13
+ Given our impartials are stored in "some/location"
14
+ Given an impartial named "macguffin"
15
+ And it has a handlebars template
16
+ Then I can render the impartial to a string
17
+
18
+ Scenario: Impartial in a set of locations
19
+ Given our impartials are stored in "some/location" or "another/location"
20
+ Given an impartial named "macguffin"
21
+ And it has a handlebars template
22
+ Then I can render the impartial to a string
@@ -0,0 +1,19 @@
1
+ Given /^a missing impartial controller named "([^"]*)"$/ do |name|
2
+ @missing = name
3
+ end
4
+
5
+ When /^I try to render the impartial$/ do
6
+ # noop
7
+ end
8
+
9
+ Then /^I should get a class not found exception$/ do
10
+ lambda { Impartial.render(@missing) }.should raise_error Impartial::Exceptions::ClassNotFound
11
+ end
12
+
13
+ Given /^it's missing it's template$/ do
14
+ # noop
15
+ end
16
+
17
+ Then /^I should get a template missing exception$/ do
18
+ lambda { Impartial.render(@missing) }.should raise_error Impartial::Exceptions::TemplateMissing
19
+ end
@@ -0,0 +1,68 @@
1
+ require 'active_support'
2
+ require 'fileutils'
3
+
4
+ Given /^our impartials are stored in "([^"]*)"$/ do |location|
5
+ @location = location
6
+ Impartial.configure do |config|
7
+ config.paths = [location]
8
+ end
9
+ end
10
+
11
+ Given /^our impartials are stored in "([^"]*)" or "([^"]*)"$/ do |location1, location2|
12
+ @location = location2
13
+ Impartial.configure do |config|
14
+ config.paths = [location1, location2]
15
+ end
16
+ end
17
+
18
+ Given /^an impartial named "([^"]*)"$/ do |name|
19
+ @name = name.underscore
20
+ @shortname = name.demodulize.underscore
21
+ FileUtils.mkdir_p File.join(@location || 'impartials', @name)
22
+ path = File.join(@location || 'impartials', @name, "#{@name}.rb")
23
+ File.open path, "w" do |f|
24
+ f.puts <<-FILE
25
+ require 'impartial'
26
+
27
+ class #{@name.camelize} < Impartial::Base
28
+ end
29
+ FILE
30
+ end
31
+ end
32
+
33
+ Given /^it has a handlebars template$/ do
34
+ path = File.join(@location || 'impartials', @name, "#{@name}.html.hbs")
35
+ File.open path, "w" do |f|
36
+ f.puts <<-FILE
37
+ <html>
38
+ <body>
39
+ <div class="#{@name.camelize.gsub('::', '-')}">Hello World!</div>
40
+ </body>
41
+ </html>
42
+ FILE
43
+ end
44
+ end
45
+
46
+ Given /^it has a LESS stylesheet$/ do
47
+ path = File.join(@location || 'impartials', @name, "#{@name}.css.less")
48
+ File.open path, "w" do |f|
49
+ f.puts <<-FILE
50
+ .#{@name.camelize.gsub('::', '-')} {
51
+ text-shadow: 0px -2px 0px #333, 0px 2px 3px #666;
52
+ }
53
+ FILE
54
+ end
55
+ end
56
+
57
+ Then /^I can render the impartial to a string$/ do
58
+ path = File.join('.', @location || 'impartials', @name, @shortname)
59
+ require path
60
+
61
+ Impartial.render(@shortname).to_s.should eql <<-STRING
62
+ <html>
63
+ <body>
64
+ <div class="#{@name.camelize.gsub('::', '-')}">Hello World!</div>
65
+ </body>
66
+ </html>
67
+ STRING
68
+ end
@@ -0,0 +1,12 @@
1
+ require 'impartial'
2
+
3
+ require 'fileutils'
4
+ require 'active_support/inflector'
5
+
6
+ # Set up our temporary working directory
7
+ Before do
8
+ location = File.join(File.dirname(__FILE__), '..', '..', 'tmp', 'cucumber')
9
+ FileUtils.rm_rf location
10
+ FileUtils.mkdir_p location
11
+ FileUtils.cd location
12
+ end
@@ -0,0 +1,26 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require 'impartial/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "impartial"
6
+ s.version = Impartial::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Logan Lowell", "Charles Lowell"]
9
+ s.email = ["fractaloop@thefrontside.net", "cowboyd@thefrontside.net"]
10
+ s.homepage = "http://github.com/thefrontside/impartial"
11
+ s.summary = 'Partials without prejudice.'
12
+ s.description = 'Impartials are encapsulated reusable view components that obviate controllers.'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_dependency "railties", "~> 3.0"
20
+ s.add_dependency "activesupport", "~> 3.0"
21
+ s.add_dependency "hbs", "~> 0.1.2"
22
+
23
+ s.add_development_dependency "rake", "~> 0.9.2"
24
+ s.add_development_dependency "rspec", "~> 2.7"
25
+ s.add_development_dependency "cucumber"
26
+ end
@@ -0,0 +1,28 @@
1
+ require 'impartial/version'
2
+ require 'impartial/base'
3
+ require 'impartial/configuration'
4
+
5
+ module Impartial
6
+ extend Configuration
7
+
8
+ class << self
9
+ # Alias Impartial::Base.new
10
+ #
11
+ # @return [Impartial::Base]
12
+ def new(options = {})
13
+ Impartial::Base.new(options)
14
+ end
15
+
16
+ # Delegate to Impartial::Base
17
+ def method_missing(method, *args, &block)
18
+ return super unless new.respond_to?(method)
19
+ new.send(method, *args, &block)
20
+ end
21
+
22
+ private
23
+
24
+ def respond_to?(method, include_private = false)
25
+ new.respond_to?(method, include_private) || super(method, include_private)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ require 'impartial/configuration'
2
+ require 'impartial/error'
3
+
4
+ require 'active_support/inflector'
5
+ require 'handlebars'
6
+
7
+ module Impartial
8
+ class Base
9
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
10
+
11
+ def initialize(options={})
12
+ options = Impartial.options.merge(options)
13
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
14
+ send("#{key}=", options[key])
15
+ end
16
+ end
17
+
18
+ def render(name, *args)
19
+ cls = Impartial::Base.find_class name
20
+ view = cls.new *args
21
+ path = cls.name.underscore
22
+ shortname = cls.name.demodulize.underscore
23
+ paths.each do |load_path|
24
+ t = File.join(load_path, path, "#{shortname}.html.hbs")
25
+ if File.exist? t
26
+ return Handlebars.compile(File.open(t).read).call(view).to_s
27
+ end
28
+ end
29
+ raise Impartial::Exceptions::TemplateMissing.new
30
+ end
31
+
32
+ def self.find_class(name)
33
+ name.to_s.camelize.constantize
34
+ rescue NameError => e
35
+ raise Impartial::Exceptions::ClassNotFound.new e.to_s
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,37 @@
1
+ require 'impartial/version'
2
+
3
+ module Impartial
4
+ module Configuration
5
+ VALID_OPTIONS_KEYS = [
6
+ :paths
7
+ ].freeze
8
+
9
+ # Look for impartial templates in this location
10
+ DEFAULT_PATHS = ['./impartials']
11
+
12
+ attr_accessor *VALID_OPTIONS_KEYS
13
+
14
+ # When this module is extended, set all configuration options to their default values
15
+ def self.extended(base)
16
+ base.reset
17
+ end
18
+
19
+ # Convenience method to allow configuration options to be set in a block
20
+ def configure
21
+ yield self
22
+ end
23
+
24
+ # Create a hash of options and their values
25
+ def options
26
+ options = {}
27
+ VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
28
+ options
29
+ end
30
+
31
+ # Reset all configuration options to defaults
32
+ def reset
33
+ self.paths = DEFAULT_PATHS
34
+ self
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,9 @@
1
+ module Impartial
2
+ module Exceptions
3
+ class ClassNotFound < NameError
4
+ end
5
+
6
+ class TemplateMissing < StandardError
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ require 'active_support/inflector'
2
+ require 'handlebars'
3
+
4
+ require 'impartial/error'
5
+
6
+ module Impartial
7
+ module Helper
8
+ module_function
9
+
10
+ def impartial(name, *args)
11
+ cls = Impartial::Helper.find_class name
12
+ puts cls.inspect
13
+ puts cls.class.name
14
+ view = cls.new *args
15
+ path = cls.name.underscore
16
+ shortname = cls.name.demodulize.underscore
17
+ t = Rails.root.join("app", "impartials", path, "#{shortname}.html.hbs")
18
+ Handlebars.compile(t.read).call(view).to_s.html_safe
19
+ end
20
+
21
+ def self.find_class(name)
22
+ name.to_s.camelize.constantize
23
+ rescue NameError => e
24
+ raise Impartial::Exceptions::ClassNotFound.new e.to_s
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module Impartial
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: impartial
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Logan Lowell
9
+ - Charles Lowell
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2011-12-07 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: railties
17
+ requirement: &70124887020560 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70124887020560
26
+ - !ruby/object:Gem::Dependency
27
+ name: activesupport
28
+ requirement: &70124887020000 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *70124887020000
37
+ - !ruby/object:Gem::Dependency
38
+ name: hbs
39
+ requirement: &70124887019520 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 0.1.2
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *70124887019520
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ requirement: &70124887019060 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 0.9.2
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *70124887019060
59
+ - !ruby/object:Gem::Dependency
60
+ name: rspec
61
+ requirement: &70124887018600 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: '2.7'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *70124887018600
70
+ - !ruby/object:Gem::Dependency
71
+ name: cucumber
72
+ requirement: &70124887018220 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *70124887018220
81
+ description: Impartials are encapsulated reusable view components that obviate controllers.
82
+ email:
83
+ - fractaloop@thefrontside.net
84
+ - cowboyd@thefrontside.net
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - .gitignore
90
+ - Gemfile
91
+ - Gemfile.lock
92
+ - MIT-LICENSE
93
+ - README.md
94
+ - Rakefile
95
+ - features/handles_errors.feature
96
+ - features/render_impartial_view.feature
97
+ - features/steps/error_steps.rb
98
+ - features/steps/render_impartial_view_steps.rb
99
+ - features/support/env.rb
100
+ - impartial.gemspec
101
+ - lib/impartial.rb
102
+ - lib/impartial/base.rb
103
+ - lib/impartial/configuration.rb
104
+ - lib/impartial/error.rb
105
+ - lib/impartial/helper.rb
106
+ - lib/impartial/version.rb
107
+ homepage: http://github.com/thefrontside/impartial
108
+ licenses: []
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ segments:
120
+ - 0
121
+ hash: -114931473952914014
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ segments:
129
+ - 0
130
+ hash: -114931473952914014
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 1.8.11
134
+ signing_key:
135
+ specification_version: 3
136
+ summary: Partials without prejudice.
137
+ test_files:
138
+ - features/handles_errors.feature
139
+ - features/render_impartial_view.feature
140
+ - features/steps/error_steps.rb
141
+ - features/steps/render_impartial_view_steps.rb
142
+ - features/support/env.rb