stachio 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.
- data/.gitignore +9 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -0
- data/.simplecov +21 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +152 -0
- data/MIT-LICENSE +20 -0
- data/README.md +3 -0
- data/Rakefile +50 -0
- data/app/assets/images/stachio/.gitkeep +0 -0
- data/app/assets/javascripts/stachio/application.js +15 -0
- data/app/assets/javascripts/stachio/templates.js +2 -0
- data/app/assets/stylesheets/scaffold.css +56 -0
- data/app/assets/stylesheets/stachio/application.css +13 -0
- data/app/assets/stylesheets/stachio/templates.css +4 -0
- data/app/controllers/stachio/application_controller.rb +4 -0
- data/app/controllers/stachio/templates_controller.rb +87 -0
- data/app/helpers/stachio/application_helper.rb +4 -0
- data/app/helpers/stachio/templates_helper.rb +4 -0
- data/app/models/stachio/template.rb +21 -0
- data/app/views/layouts/stachio/application.html.erb +14 -0
- data/app/views/stachio/templates/_form.html.erb +25 -0
- data/app/views/stachio/templates/edit.html.erb +6 -0
- data/app/views/stachio/templates/index.html.erb +25 -0
- data/app/views/stachio/templates/new.html.erb +5 -0
- data/app/views/stachio/templates/show.html.erb +15 -0
- data/config/routes.rb +4 -0
- data/db/migrate/20130509172418_create_stachio_templates.rb +10 -0
- data/lib/stachio.rb +4 -0
- data/lib/stachio/engine.rb +17 -0
- data/lib/stachio/proxy.rb +20 -0
- data/lib/stachio/version.rb +3 -0
- data/lib/tasks/stachio_tasks.rake +4 -0
- data/script/rails +8 -0
- data/spec/controllers/stachio/templates_controller_spec.rb +167 -0
- data/spec/dummy/.rspec +1 -0
- data/spec/dummy/.ruby-version +1 -0
- data/spec/dummy/README.md +3 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +66 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/db/schema.rb +23 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/helpers/stachio/templates_helper_spec.rb +17 -0
- data/spec/models/stachio/template_spec.rb +54 -0
- data/spec/requests/stachio/stachio_templates_spec.rb +11 -0
- data/spec/routing/stachio/templates_routing_spec.rb +37 -0
- data/spec/spec_helper.rb +50 -0
- data/stachio.gemspec +33 -0
- metadata +374 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'stachio/proxy'
|
2
|
+
|
3
|
+
module Stachio
|
4
|
+
class Template < ActiveRecord::Base
|
5
|
+
lookup_by :template_name
|
6
|
+
|
7
|
+
attr_accessible :template_name, :content
|
8
|
+
validates_presence_of :template_name, :content
|
9
|
+
|
10
|
+
attr_accessor :proxied
|
11
|
+
|
12
|
+
def proxy
|
13
|
+
@proxy ||= Stachio::Proxy.new(proxied) unless proxied.nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
def compose
|
17
|
+
proxy.template = content
|
18
|
+
proxy.render
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Stachio</title>
|
5
|
+
<%= stylesheet_link_tag "stachio/application", :media => "all" %>
|
6
|
+
<%= javascript_include_tag "stachio/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<%= form_for(@template) do |f| %>
|
2
|
+
<% if @template.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(@template.errors.count, "error") %> prohibited this template from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% @template.errors.full_messages.each do |msg| %>
|
8
|
+
<li><%= msg %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="field">
|
15
|
+
<%= f.label :template_name %><br />
|
16
|
+
<%= f.text_field :template_name %>
|
17
|
+
</div>
|
18
|
+
<div class="field">
|
19
|
+
<%= f.label :content %><br />
|
20
|
+
<%= f.text_area :content %>
|
21
|
+
</div>
|
22
|
+
<div class="actions">
|
23
|
+
<%= f.submit %>
|
24
|
+
</div>
|
25
|
+
<% end %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<h1>Listing templates</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<th>Template name</th>
|
6
|
+
<th>Content</th>
|
7
|
+
<th></th>
|
8
|
+
<th></th>
|
9
|
+
<th></th>
|
10
|
+
</tr>
|
11
|
+
|
12
|
+
<% @templates.each do |template| %>
|
13
|
+
<tr>
|
14
|
+
<td><%= template.template_name %></td>
|
15
|
+
<td><%= template.content %></td>
|
16
|
+
<td><%= link_to 'Show', template %></td>
|
17
|
+
<td><%= link_to 'Edit', edit_template_path(template) %></td>
|
18
|
+
<td><%= link_to 'Destroy', template, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
19
|
+
</tr>
|
20
|
+
<% end %>
|
21
|
+
</table>
|
22
|
+
|
23
|
+
<br />
|
24
|
+
|
25
|
+
<%= link_to 'New Template', new_template_path %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
<b>Template name:</b>
|
5
|
+
<%= @template.template_name %>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
<p>
|
9
|
+
<b>Content:</b>
|
10
|
+
<%= @template.content %>
|
11
|
+
</p>
|
12
|
+
|
13
|
+
|
14
|
+
<%= link_to 'Edit', edit_template_path(@template) %> |
|
15
|
+
<%= link_to 'Back', templates_path %>
|
data/config/routes.rb
ADDED
data/lib/stachio.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Stachio
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace Stachio
|
4
|
+
|
5
|
+
require 'lookup_by'
|
6
|
+
require "jquery-rails"
|
7
|
+
|
8
|
+
require "mustache"
|
9
|
+
require "stache" ## use mustache/handlebars for views
|
10
|
+
Stache.use :mustache
|
11
|
+
|
12
|
+
config.generators do |g|
|
13
|
+
g.test_framework :rspec
|
14
|
+
g.integration_tool :rspec
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Stachio
|
2
|
+
class Proxy < Mustache
|
3
|
+
self.raise_on_context_miss = true
|
4
|
+
attr_accessor :proxied
|
5
|
+
|
6
|
+
def initialize(proxied)
|
7
|
+
self.proxied = proxied
|
8
|
+
end
|
9
|
+
|
10
|
+
def respond_to?(method, include_privates=false)
|
11
|
+
return true if proxied.respond_to? method
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(method, *args, &block)
|
16
|
+
super unless proxied.respond_to?(method)
|
17
|
+
proxied.send method, *args, &block
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/script/rails
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
5
|
+
ENGINE_PATH = File.expand_path('../../lib/stachio/engine', __FILE__)
|
6
|
+
|
7
|
+
require 'rails/all'
|
8
|
+
require 'rails/engine/commands'
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
4
|
+
# It demonstrates how one might use RSpec to specify the controller code that
|
5
|
+
# was generated by Rails when you ran the scaffold generator.
|
6
|
+
#
|
7
|
+
# It assumes that the implementation code is generated by the rails scaffold
|
8
|
+
# generator. If you are using any extension libraries to generate different
|
9
|
+
# controller code, this generated spec may or may not pass.
|
10
|
+
#
|
11
|
+
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
12
|
+
# of tools you can use to make these specs even more expressive, but we're
|
13
|
+
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
14
|
+
#
|
15
|
+
# Compared to earlier versions of this generator, there is very limited use of
|
16
|
+
# stubs and message expectations in this spec. Stubs are only used when there
|
17
|
+
# is no simpler way to get a handle on the object needed for the example.
|
18
|
+
# Message expectations are only used when there is no simpler way to specify
|
19
|
+
# that an instance is receiving a specific message.
|
20
|
+
|
21
|
+
module Stachio
|
22
|
+
describe TemplatesController do
|
23
|
+
|
24
|
+
# This should return the minimal set of attributes required to create a valid
|
25
|
+
# Template. As you add validations to Template, be sure to
|
26
|
+
# adjust the attributes here as well.
|
27
|
+
let(:valid_attributes) do
|
28
|
+
{ "template_name" => "MyString",
|
29
|
+
"content" => "I am a {{teapot}}",
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
# This should return the minimal set of values that should be in the session
|
34
|
+
# in order to pass any filters (e.g. authentication) defined in
|
35
|
+
# TemplatesController. Be sure to keep this updated too.
|
36
|
+
let(:valid_session) { {} }
|
37
|
+
|
38
|
+
describe "GET index" do
|
39
|
+
it "assigns all templates as @templates" do
|
40
|
+
template = Template.create! valid_attributes
|
41
|
+
get :index, {}, valid_session
|
42
|
+
assigns(:templates).should eq([template])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "GET show" do
|
47
|
+
it "assigns the requested template as @template" do
|
48
|
+
template = Template.create! valid_attributes
|
49
|
+
get :show, {:id => template.to_param}, valid_session
|
50
|
+
assigns(:template).should eq(template)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "GET new" do
|
55
|
+
it "assigns a new template as @template" do
|
56
|
+
get :new, {}, valid_session
|
57
|
+
assigns(:template).should be_a_new(Template)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "GET edit" do
|
62
|
+
it "assigns the requested template as @template" do
|
63
|
+
template = Template.create! valid_attributes
|
64
|
+
get :edit, {:id => template.to_param}, valid_session
|
65
|
+
assigns(:template).should eq(template)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "POST create" do
|
70
|
+
describe "with valid params" do
|
71
|
+
it "creates a new Template" do
|
72
|
+
expect {
|
73
|
+
post :create, {:template => valid_attributes}, valid_session
|
74
|
+
}.to change(Template, :count).by(1)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "assigns a newly created template as @template" do
|
78
|
+
post :create, {:template => valid_attributes}, valid_session
|
79
|
+
assigns(:template).should be_a(Template)
|
80
|
+
assigns(:template).should be_persisted
|
81
|
+
end
|
82
|
+
|
83
|
+
it "redirects to the created template" do
|
84
|
+
post :create, {:template => valid_attributes}, valid_session
|
85
|
+
response.should redirect_to(Template.last)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "with invalid params" do
|
90
|
+
it "assigns a newly created but unsaved template as @template" do
|
91
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
92
|
+
Template.any_instance.stub(:save).and_return(false)
|
93
|
+
post :create, {:template => { "template_name" => "invalid value" }}, valid_session
|
94
|
+
assigns(:template).should be_a_new(Template)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "re-renders the 'new' template" do
|
98
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
99
|
+
Template.any_instance.stub(:save).and_return(false)
|
100
|
+
post :create, {:template => { "template_name" => "invalid value" }}, valid_session
|
101
|
+
response.should render_template("new")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "PUT update" do
|
107
|
+
describe "with valid params" do
|
108
|
+
it "updates the requested template" do
|
109
|
+
template = Template.create! valid_attributes
|
110
|
+
# Assuming there are no other templates in the database, this
|
111
|
+
# specifies that the Template created on the previous line
|
112
|
+
# receives the :update_attributes message with whatever params are
|
113
|
+
# submitted in the request.
|
114
|
+
Template.any_instance.should_receive(:update_attributes).with({ "template_name" => "MyString" })
|
115
|
+
put :update, {:id => template.to_param, :template => { "template_name" => "MyString" }}, valid_session
|
116
|
+
end
|
117
|
+
|
118
|
+
it "assigns the requested template as @template" do
|
119
|
+
template = Template.create! valid_attributes
|
120
|
+
put :update, {:id => template.to_param, :template => valid_attributes}, valid_session
|
121
|
+
assigns(:template).should eq(template)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "redirects to the template" do
|
125
|
+
template = Template.create! valid_attributes
|
126
|
+
put :update, {:id => template.to_param, :template => valid_attributes}, valid_session
|
127
|
+
response.should redirect_to(template)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "with invalid params" do
|
132
|
+
it "assigns the template as @template" do
|
133
|
+
template = Template.create! valid_attributes
|
134
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
135
|
+
Template.any_instance.stub(:save).and_return(false)
|
136
|
+
put :update, {:id => template.to_param, :template => { "template_name" => "invalid value" }}, valid_session
|
137
|
+
assigns(:template).should eq(template)
|
138
|
+
end
|
139
|
+
|
140
|
+
it "re-renders the 'edit' template" do
|
141
|
+
template = Template.create! valid_attributes
|
142
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
143
|
+
Template.any_instance.stub(:save).and_return(false)
|
144
|
+
put :update, {:id => template.to_param, :template => { "template_name" => "invalid value" }}, valid_session
|
145
|
+
response.should render_template("edit")
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "DELETE destroy" do
|
151
|
+
it "destroys the requested template" do
|
152
|
+
template = Template.create! valid_attributes
|
153
|
+
expect {
|
154
|
+
delete :destroy, {:id => template.to_param}, valid_session
|
155
|
+
}.to change(Template, :count).by(-1)
|
156
|
+
end
|
157
|
+
|
158
|
+
it "redirects to the templates list" do
|
159
|
+
template = Template.create! valid_attributes
|
160
|
+
delete :destroy, {:id => template.to_param}, valid_session
|
161
|
+
#response.should redirect_to(templates_url) ## Requires default_host_url to be set, but we're in an engine.
|
162
|
+
response.should redirect_to(templates_path) ## So, instead, we test the redirection against the relative path
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
end
|
data/spec/dummy/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p194
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|