brick_house 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/log/*.log
6
+ test/dummy/tmp/
7
+ db/*.sqlite3
8
+ tmp/**/*
9
+ .DS_Store
10
+ .rvmrc
11
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails', '3.1.0'
4
+ gem 'sqlite3'
5
+
6
+ gemspec
@@ -0,0 +1,107 @@
1
+ = Brick House
2
+
3
+ Brick House was made to be used in conjunction with brick layer. Brick House provides an interface to your
4
+ Brick Layer application. To use Brick House you can include it in the same application as your Brick Layer gem or you
5
+ can add it to another application and consume the Brick Layer data from that location. The idea is that you don't have to use
6
+ Brick House if you just want to consume data, but the option is there.
7
+
8
+ == Features
9
+
10
+ * Templating
11
+ - Just create a template in the 'views/templates' directory and match it's name to the data set you want at the endpoint of the route and voila - it shoud use that template.
12
+
13
+ * Automated Routing
14
+ - Brick House pulls in the routing data from your Brick Layer endpoint and automatically integrates those defined routes into your application.
15
+
16
+ * Search Interface
17
+ - There is a search object created for easy integration with the search feature of the brick house server.
18
+
19
+ == Install and Configuration
20
+
21
+ Within the application in which you want to consume Brick Layer data:
22
+
23
+ # Gemfile
24
+ gem 'brick_house'
25
+
26
+ You also want to create an initialzer file of some sort to set your configuration data.
27
+
28
+ # /config/initializers/brick_house_init.rb
29
+ BrickHouse.brick_layer_endpoint = "yourendpoint:port"
30
+
31
+ example:
32
+
33
+ # /config/initializers/brick_house_init.rb
34
+ BrickHouse.brick_layer_endpoint = "127.0.0.1:3000"
35
+
36
+ If you want to use Brick House within the same application as brick layer, just don't create an endpoint. This endpoint is obviously just an example.
37
+ Now you should be ready to roll.
38
+
39
+ == Templating
40
+
41
+ Once you have your route and endpoints(remember this is optional) setup you can just create a 'templates' directory in your 'app/views' directory. This is where
42
+ you drop your templates into. Your HTML request to the Brick House app should automatically take to you to the dataset based on the page and it'll try to use the template named
43
+ after the data set the conventional Rails manner.
44
+
45
+ Example:
46
+
47
+ ### IN BRICK LAYER ###
48
+
49
+ # This is in /app/models/page_data_set/homepage.rb #
50
+ class PageDataSets::Homepage
51
+ field :my_data_1
52
+ field :my_data_2
53
+ end
54
+
55
+ # You create a page using the Brick Layer Admin and set it to this data set template.
56
+ # Let's assume you set the homepage to use this data set template.
57
+
58
+
59
+
60
+ ### IN BRICK HOUSE ###
61
+
62
+ # After you set the endpoint to your Brick Layer app you create a matching name template in the proper directory.
63
+ # When someone makes a request matching the path to your data set set in Brick Layer a template will be rendered and
64
+ # a @data_set object will be made available.
65
+
66
+ # This is in /app/vew/templates/homepage.html.erb #
67
+ <h1><%= @data_set.title %></h1>
68
+ <p><%= @data_set.my_data_1 %></p>
69
+ <p><%= @data_set.my_data_2 %></p>
70
+
71
+ That's all you need and you are rolling. You have access to the data but you can still develop the application like normal.
72
+
73
+ == Standalone Data Sets
74
+
75
+ "Sooooo..... what if I want to pull the data set from Brick Layer that isn't page specific. The Standalone Data Sets if you will.'"
76
+
77
+ If you are pulling data across the wire and you need access to that standalone data set you can easily do that.
78
+
79
+ Example: You want to pull the data for a brick layer "Employee" data set.
80
+
81
+ ### IN BRICK LAYER ###
82
+
83
+ # This is in /app/models/employee.rb #
84
+ class Employee < BrickLayer::DataSet
85
+ field :first_name
86
+ field :last_name
87
+ end
88
+
89
+ ### IN BRICK HOUSE ###
90
+
91
+ # To get a list of employees
92
+
93
+ @employees = BrickHouse::DataSet.get("/employees")
94
+
95
+ # To get a specific employee
96
+
97
+ @employees = BrickHouse::DataSet.get("/employees/[employee-id]")
98
+
99
+ This actually works with page data sets as well. You just would call it differently.
100
+
101
+ @about_data = BrickHouse::PageDataSet.get("/about-us")
102
+
103
+ == Routing
104
+
105
+ You can pull the routes from brick layer by using the method:
106
+
107
+ BrickHouse::Routes.all
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'BrickHouse'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+ Bundler::GemHelper.install_tasks
28
+
29
+ require 'rake/testtask'
30
+
31
+ Rake::TestTask.new(:test) do |t|
32
+ t.libs << 'lib'
33
+ t.libs << 'test'
34
+ t.pattern = 'test/**/*_test.rb'
35
+ t.verbose = false
36
+ end
37
+
38
+
39
+ task :default => :test
@@ -0,0 +1,21 @@
1
+ class BrickHouse::PagesController < ApplicationController
2
+ def show
3
+ if params[:data_path].blank?
4
+ @data_set = BrickHouse::PageDataSet.get("root")
5
+ else
6
+ @data_set = BrickHouse::PageDataSet.get(params[:data_path])
7
+ end
8
+
9
+ if @data_set
10
+ if @data_set._type == "BrickLayer::DataSet"
11
+ template = "templates/#{@data_set.route.data_set_template.underscore}"
12
+ else
13
+ template = "templates/#{@data_set._type.split('::')[-1].underscore}"
14
+ end
15
+ render :template => template
16
+ else
17
+ render "/404.html", :status => 404
18
+ return
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ class BrickHouse::BrickLayerResource < ActiveResource::Base
2
+ self.site = "http://#{BrickHouse.brick_layer_endpoint}/brick_layer" unless BrickHouse.brick_layer_endpoint.blank?
3
+ self.format = :json
4
+
5
+ def self.get(args)
6
+ begin
7
+ if BrickHouse.brick_layer_endpoint.blank?
8
+ unless args == "root" || args == "home"
9
+ route = BrickLayer::Route.where(:slug => args).first
10
+ else
11
+ route = BrickLayer::Route.where(:slug => "").first
12
+ end
13
+ return route.try(:data_set)
14
+ else
15
+ debugger
16
+ return BrickHouse::DataSetObject.new(super(*args)).results
17
+ end
18
+ rescue => e
19
+ Rails.logger.error("REQUEST ERROR: #{e}")
20
+ nil
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ class BrickHouse::DataSet < BrickHouse::BrickLayerResource
2
+ self.element_name = "data-sets"
3
+ end
@@ -0,0 +1,21 @@
1
+ class BrickHouse::DataSetObject
2
+ attr_accessor :results
3
+
4
+ def initialize(hash_or_array)
5
+ if hash_or_array.is_a?(Array)
6
+ @result = hash_or_array.map { |hash| process_hash_to_object(hash) }
7
+ else
8
+ @result = process_hash_to_object(hash_or_array)
9
+ end
10
+ end
11
+
12
+ def process_hash_to_object(hash)
13
+ hash.each do |k,v|
14
+ k = k.gsub('(','_').gsub(')','_')
15
+ self.instance_variable_set("@#{k}",v)
16
+ self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")})
17
+ self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}",v)})
18
+ end
19
+ return hash
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ class BrickHouse::PageDataSet < BrickHouse::BrickLayerResource
2
+ self.element_name = "pages"
3
+ end
@@ -0,0 +1,7 @@
1
+ if BrickHouse.brick_layer_endpoint.blank?
2
+ class BrickHouse::Routes < BrickLayer::Route
3
+ end
4
+ else
5
+ class BrickHouse::Routes < BrickHouse::BrickLayerResource
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ Rails.application.routes.draw do
2
+ scope :module => :brick_house do
3
+ root :to => "pages#show"
4
+ match "*data_path" => "pages#show", :as => "show_template"
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ require "brick_house/engine"
2
+
3
+ module BrickHouse
4
+ mattr_accessor :app_root, :brick_layer_endpoint, :brick_layer_token
5
+
6
+ def self.setup
7
+ yield self
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module BrickHouse
2
+ class Engine < Rails::Engine
3
+ initializer "brick_house.load_app_instance_data" do |app|
4
+ BrickHouse.setup do |config|
5
+ config.app_root = Rails.root
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :brick_house do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe BrickHouse::PagesController do
4
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe BrickHouse::DataSet do
4
+ it "should grab the data set of an object"
5
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Brick House Routes" do
4
+ # TODO: x2 chack and see why this isn't working! All of a sudden stopped
5
+ # it "route /page-path to brick_house::pages#show for data_path via a GET REQUEST" do
6
+ # { :get => "/my-page" }.should route_to(
7
+ # :controller => "brick_house/pages",
8
+ # :action => "show",
9
+ # :data_path => "my-page"
10
+ # )
11
+ # end
12
+ end
File without changes
@@ -0,0 +1,12 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
4
+ require 'rspec/rails'
5
+ require 'shoulda'
6
+
7
+ # Factories
8
+ require 'factories'
9
+
10
+ # Requires supporting ruby files with custom matchers and macros, etc,
11
+ # in spec/support/ and its subdirectories.
12
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brick_house
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rahsun McAfee
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-20 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: turn
16
+ requirement: &70196496962480 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70196496962480
25
+ - !ruby/object:Gem::Dependency
26
+ name: ruby-debug19
27
+ requirement: &70196496961960 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70196496961960
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec-rails
38
+ requirement: &70196496961100 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '2.4'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70196496961100
47
+ - !ruby/object:Gem::Dependency
48
+ name: autotest
49
+ requirement: &70196496960160 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70196496960160
58
+ - !ruby/object:Gem::Dependency
59
+ name: webrat
60
+ requirement: &70196496951780 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70196496951780
69
+ - !ruby/object:Gem::Dependency
70
+ name: capybara
71
+ requirement: &70196496949860 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70196496949860
80
+ - !ruby/object:Gem::Dependency
81
+ name: factory_girl
82
+ requirement: &70196496934660 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70196496934660
91
+ - !ruby/object:Gem::Dependency
92
+ name: shoulda
93
+ requirement: &70196496932420 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70196496932420
102
+ - !ruby/object:Gem::Dependency
103
+ name: hirb
104
+ requirement: &70196496930800 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *70196496930800
113
+ - !ruby/object:Gem::Dependency
114
+ name: wirble
115
+ requirement: &70196496928380 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *70196496928380
124
+ - !ruby/object:Gem::Dependency
125
+ name: looksee
126
+ requirement: &70196496914640 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: *70196496914640
135
+ description: Brick Layer interface for templates, helpers, and client like use cases.
136
+ email:
137
+ executables: []
138
+ extensions: []
139
+ extra_rdoc_files: []
140
+ files:
141
+ - lib/brick_house/engine.rb
142
+ - lib/brick_house.rb
143
+ - lib/tasks/brick_house_tasks.rake
144
+ - app/controllers/brick_house/pages_controller.rb
145
+ - app/models/brick_house/brick_layer_resource.rb
146
+ - app/models/brick_house/data_set.rb
147
+ - app/models/brick_house/data_set_object.rb
148
+ - app/models/brick_house/page_data_set.rb
149
+ - app/models/brick_house/routes.rb
150
+ - config/routes.rb
151
+ - spec/brick_house/controllers/page_controller_spec.rb
152
+ - spec/brick_house/models/data_set.rb
153
+ - spec/brick_house/routing/brick_house_routing_spec.rb
154
+ - spec/factories.rb
155
+ - spec/spec_helper.rb
156
+ - Rakefile
157
+ - README.rdoc
158
+ - Gemfile
159
+ - .gitignore
160
+ homepage:
161
+ licenses: []
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ none: false
168
+ requirements:
169
+ - - ! '>='
170
+ - !ruby/object:Gem::Version
171
+ version: 1.9.2
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ none: false
174
+ requirements:
175
+ - - ! '>='
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 1.8.15
181
+ signing_key:
182
+ specification_version: 3
183
+ summary: This Rails Engine gem connects to brick layer applications / endpoint and
184
+ imports in templates and helpers.
185
+ test_files: []