lti_template_builder 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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +7 -0
- data/config.ru +2 -0
- data/lib/lti_template_builder.rb +13 -0
- data/lib/lti_template_builder/builder.rb +51 -0
- data/lib/lti_template_builder/recipe.rb +36 -0
- data/lib/lti_template_builder/recipes/bootstrap_sass/bootstrap_sass.rb +8 -0
- data/lib/lti_template_builder/recipes/bootstrap_sass/template.erb +13 -0
- data/lib/lti_template_builder/recipes/cors_support/cors_support.rb +6 -0
- data/lib/lti_template_builder/recipes/cors_support/template.erb +32 -0
- data/lib/lti_template_builder/recipes/extra/extra.rb +6 -0
- data/lib/lti_template_builder/recipes/extra/template.erb +12 -0
- data/lib/lti_template_builder/recipes/gems/gems.rb +9 -0
- data/lib/lti_template_builder/recipes/gems/template.erb +15 -0
- data/lib/lti_template_builder/recipes/lti_extension/lti_extension.rb +25 -0
- data/lib/lti_template_builder/recipes/lti_extension/template.erb +164 -0
- data/lib/lti_template_builder/recipes/rspec/add_rspec_to_engine_config.erb +7 -0
- data/lib/lti_template_builder/recipes/rspec/rspec.rb +12 -0
- data/lib/lti_template_builder/recipes/rspec/template.erb +61 -0
- data/lib/lti_template_builder/version.rb +3 -0
- data/lti_template_builder.gemspec +27 -0
- data/spec/lib/builder_spec.rb +18 -0
- data/spec/spec_helper.rb +8 -0
- data/web/server.rb +21 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 114b7c3effaf50ca1f87c8f47a40c320a07e03dd
|
4
|
+
data.tar.gz: 4ff676cee26f2c9dda9c2e764a03469b91f92bb1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 74257ed2c94edea6770a58533e97ba28aaba92959fe35f93a80777adbcb9854a2843891185897b39b36800d875c4f473b8fd6aab985b244f4a9efe05abbca2df
|
7
|
+
data.tar.gz: 79d95cd1355e711557efb0ad4a650a5a2ca4c5f27933074db6f7e1aa1290fa61b900cc45017bd4dbf7efb39b16ea0098736269a7c3e12c32a30a56bd59fa1fe8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Instructure
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# LTI Template Builder
|
2
|
+
|
3
|
+
[](https://travis-ci.org/instructure/lti_template_builder)
|
4
|
+
[](https://codeclimate.com/github/instructure/lti_template_builder)
|
5
|
+
[](http://badge.fury.io/rb/lti_template_builder)
|
6
|
+
|
7
|
+
Template generator for building LTI apps quickly on top of Rails
|
8
|
+
mountable engines.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'lti_template_builder'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install lti_template_builder
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
To build a Rails template, you need to instanciate the builder and then
|
27
|
+
add recipes to it.
|
28
|
+
|
29
|
+
Example:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'lti_template_builder'
|
33
|
+
builder = LtiTemplateBuilder::Builder.new
|
34
|
+
|
35
|
+
# Add recipes
|
36
|
+
builder.add :bootstrap_sass
|
37
|
+
builder.add :cors_support
|
38
|
+
builder.add :rspec
|
39
|
+
builder.add :lti_extension, { enabled_extensions: [:editor_button, :resource_selection] }
|
40
|
+
builder.add :extra
|
41
|
+
|
42
|
+
# Print out the generated template.rb
|
43
|
+
puts builder.to_script
|
44
|
+
|
45
|
+
# Write builder to file
|
46
|
+
builder.save_to_file("path/to/template.rb")
|
47
|
+
```
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it ( http://github.com/<my-github-username>/lti_template_builder/fork )
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/config.ru
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "active_support/inflector"
|
2
|
+
|
3
|
+
require "lti_template_builder/builder"
|
4
|
+
require "lti_template_builder/recipe"
|
5
|
+
|
6
|
+
project_root = File.dirname(File.absolute_path(__FILE__))
|
7
|
+
Dir.glob(project_root + '/lti_template_builder/recipes/**/*.rb') {|file| require file}
|
8
|
+
|
9
|
+
require "lti_template_builder/version"
|
10
|
+
|
11
|
+
module LtiTemplateBuilder
|
12
|
+
# Your code goes here...
|
13
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module LtiTemplateBuilder
|
2
|
+
class Builder
|
3
|
+
attr_accessor :recipes, :gem_dependencies, :gem_dev_dependencies, :after_bundle_commands
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@gem_dependencies = []
|
7
|
+
@gem_dev_dependencies = []
|
8
|
+
@after_bundle_commands = []
|
9
|
+
@recipes = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_gem_recipe
|
13
|
+
recipe = LtiTemplateBuilder::Gems.new
|
14
|
+
recipe.setup({
|
15
|
+
gem_dependencies: @gem_dependencies.uniq,
|
16
|
+
gem_dev_dependencies: @gem_dev_dependencies.uniq,
|
17
|
+
after_bundle_commands: @after_bundle_commands.uniq
|
18
|
+
})
|
19
|
+
@recipes.unshift({ name: :gems, recipe: recipe.render })
|
20
|
+
end
|
21
|
+
|
22
|
+
def add(name, args={})
|
23
|
+
klass_name = "LtiTemplateBuilder::#{name.to_s.classify}"
|
24
|
+
recipe_klass = klass_name.constantize
|
25
|
+
recipe = recipe_klass.new
|
26
|
+
recipe.setup(args)
|
27
|
+
recipe.gem_dependencies.each { |dep| @gem_dependencies << dep }
|
28
|
+
recipe.gem_dev_dependencies.each { |dep| @gem_dev_dependencies << dep }
|
29
|
+
recipe.after_bundle_commands.each { |cmd| @after_bundle_commands << cmd }
|
30
|
+
@recipes << { name: name.to_sym, recipe: recipe.render }
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_script
|
34
|
+
add_gem_recipe
|
35
|
+
ret = []
|
36
|
+
@recipes.each do |item|
|
37
|
+
ret << "\n# ---------------------------- Recipe: #{item[:name]} ---------------------------\n\n"
|
38
|
+
ret << item[:recipe]
|
39
|
+
end
|
40
|
+
ret.join("\n\n")
|
41
|
+
end
|
42
|
+
|
43
|
+
def render_to_screen
|
44
|
+
puts self.to_script
|
45
|
+
end
|
46
|
+
|
47
|
+
def save_to_file(path)
|
48
|
+
File.open(path, "w") { |file| file.write(self.to_script) }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module LtiTemplateBuilder
|
4
|
+
class Recipe
|
5
|
+
attr_accessor :gem_dependencies, :gem_dev_dependencies, :after_bundle_commands
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@gem_dependencies = []
|
9
|
+
@gem_dev_dependencies = []
|
10
|
+
@after_bundle_commands = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def setup(args={})
|
14
|
+
raise "Please override this method!!!"
|
15
|
+
end
|
16
|
+
|
17
|
+
def template(template_name)
|
18
|
+
erb = ERB.new(File.read(File.expand_path("../recipes/#{recipe_name}/#{template_name}.erb", __FILE__)))
|
19
|
+
erb.result(self.instance_eval { binding })
|
20
|
+
end
|
21
|
+
|
22
|
+
def render
|
23
|
+
puts "CLASS: #{self.class.name}"
|
24
|
+
erb = ERB.new(File.read(File.expand_path("../recipes/#{recipe_name}/template.erb", __FILE__)))
|
25
|
+
erb.result(self.instance_eval { binding })
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def recipe_name
|
31
|
+
class_name = self.class.name
|
32
|
+
class_name.split("::").last.underscore
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# TODO: This should be done differently!!!!
|
2
|
+
|
3
|
+
remove_file "app/assets/stylesheets/#{name}/application.css"
|
4
|
+
create_file "app/assets/stylesheets/#{name}/application.scss" do <<-'RUBY'
|
5
|
+
@import "bootstrap";
|
6
|
+
RUBY
|
7
|
+
end
|
8
|
+
|
9
|
+
inject_into_file "lib/#{name}.rb", before: "module" do <<-'RUBY'
|
10
|
+
require "bootstrap-sass"
|
11
|
+
|
12
|
+
RUBY
|
13
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
inject_into_file "app/controllers/#{name}/application_controller.rb", after: "ActionController::Base\n" do <<-'RUBY'
|
2
|
+
before_action :set_default_headers
|
3
|
+
before_filter :cors_preflight_check
|
4
|
+
after_filter :cors_set_access_control_headers
|
5
|
+
|
6
|
+
def set_default_headers
|
7
|
+
response.headers['X-Frame-Options'] = 'ALLOWALL'
|
8
|
+
end
|
9
|
+
|
10
|
+
# For all responses in this controller, return the CORS access control headers.
|
11
|
+
def cors_set_access_control_headers
|
12
|
+
headers['Access-Control-Allow-Origin'] = '*'
|
13
|
+
headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'
|
14
|
+
headers['Access-Control-Request-Method'] = '*'
|
15
|
+
headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
|
16
|
+
headers['Access-Control-Max-Age'] = "1728000"
|
17
|
+
end
|
18
|
+
|
19
|
+
# If this is a preflight OPTIONS request, then short-circuit the
|
20
|
+
# request, return only the necessary headers and return an empty
|
21
|
+
# text/plain.
|
22
|
+
def cors_preflight_check
|
23
|
+
if request.method == :options
|
24
|
+
headers['Access-Control-Allow-Origin'] = '*'
|
25
|
+
headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
|
26
|
+
headers['Access-Control-Allow-Headers'] = '*'
|
27
|
+
headers['Access-Control-Max-Age'] = '1728000'
|
28
|
+
render :text => '', :content_type => 'text/plain'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
RUBY
|
32
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
inject_into_file "#{name}.gemspec", after: "s.add_development_dependency \"sqlite3\"\n" do <<-'RUBY'
|
2
|
+
<% @gem_dependencies.each do |dep| %>
|
3
|
+
s.add_dependency <%= dep.map { |str| "\"#{str}\"" }.join(", ") %>
|
4
|
+
<% end %>
|
5
|
+
<% @gem_dev_dependencies.each do |dep| %>
|
6
|
+
s.add_development_dependency <%= dep.map { |str| "\"#{str}\"" }.join(", ") %>
|
7
|
+
<% end %>
|
8
|
+
RUBY
|
9
|
+
end
|
10
|
+
|
11
|
+
run "bundle install"
|
12
|
+
|
13
|
+
<% @after_bundle_commands.each do |cmd| %>
|
14
|
+
<%= cmd %>
|
15
|
+
<% end %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module LtiTemplateBuilder
|
2
|
+
class LtiExtension < Recipe
|
3
|
+
def setup(args)
|
4
|
+
@gem_dependencies << ["ims-lti"]
|
5
|
+
@enabled_extensions = args[:enabled_extensions] || []
|
6
|
+
@after_bundle_commands << "generate 'controller lti index'"
|
7
|
+
|
8
|
+
@additional_configs = []
|
9
|
+
@additional_configs << " tc.canvas_homework_submission!(enabled: true)" if @enabled_extensions.include? :homework_submission
|
10
|
+
@additional_configs << " tc.canvas_editor_button!(enabled: true)" if @enabled_extensions.include? :editor_button
|
11
|
+
@additional_configs << " tc.canvas_resource_selection!(enabled: true)" if @enabled_extensions.include? :resource_selection
|
12
|
+
@additional_configs << " tc.canvas_account_navigation!(enabled: true)" if @enabled_extensions.include? :account_navigation
|
13
|
+
@additional_configs << " tc.canvas_course_navigation!(enabled: true)" if @enabled_extensions.include? :course_navigation
|
14
|
+
@additional_configs << " tc.canvas_user_navigation!(enabled: true)" if @enabled_extensions.include? :user_navigation
|
15
|
+
|
16
|
+
@extra_expects = ["\n"]
|
17
|
+
@extra_expects << " expect(response.body).to include('<lticm:options name=\"homework_submission\">')" if @enabled_extensions.include? :homework_submission
|
18
|
+
@extra_expects << " expect(response.body).to include('<lticm:options name=\"editor_button\">')" if @enabled_extensions.include? :editor_button
|
19
|
+
@extra_expects << " expect(response.body).to include('<lticm:options name=\"resource_selection\">')" if @enabled_extensions.include? :resource_selection
|
20
|
+
@extra_expects << " expect(response.body).to include('<lticm:options name=\"account_navigation\">')" if @enabled_extensions.include? :account_navigation
|
21
|
+
@extra_expects << " expect(response.body).to include('<lticm:options name=\"course_navigation\">')" if @enabled_extensions.include? :course_navigation
|
22
|
+
@extra_expects << " expect(response.body).to include('<lticm:options name=\"user_navigation\">')" if @enabled_extensions.include? :user_navigation
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
inject_into_file "app/controllers/#{name}/lti_controller.rb", after: "def index\n" do <<-"RUBY"
|
2
|
+
@launch_params = params.reject!{ |k,v| ['controller','action'].include? k }
|
3
|
+
end
|
4
|
+
|
5
|
+
def embed
|
6
|
+
launch_params = JSON.parse(params[:launch_params] || "{}")
|
7
|
+
|
8
|
+
tp = IMS::LTI::ToolProvider.new(nil, nil, launch_params)
|
9
|
+
tp.extend IMS::LTI::Extensions::Content::ToolProvider
|
10
|
+
|
11
|
+
# The following code is used as an example of content being returned.
|
12
|
+
# This should be replaced by actual logic.
|
13
|
+
embed_type = params[:embed_type]
|
14
|
+
if embed_type =~ /Video/
|
15
|
+
@title = "Getting Started in Canvas Network"
|
16
|
+
@url = "//player.vimeo.com/video/79702646"
|
17
|
+
@width = "500"
|
18
|
+
@height = "284"
|
19
|
+
elsif embed_type =~ /Picture/
|
20
|
+
@title = "Laughing Dog"
|
21
|
+
@url = "https://dl.dropboxusercontent.com/u/2176587/laughing_dog.jpeg"
|
22
|
+
@width = "284"
|
23
|
+
@height = "177"
|
24
|
+
else
|
25
|
+
@title = "My Lti App"
|
26
|
+
@url = "\#{root_url}" # <-- build return URL
|
27
|
+
@width = 500 # <-- modal width (if applicable)
|
28
|
+
@height = 530 # <-- modal height (if applicable)
|
29
|
+
end
|
30
|
+
|
31
|
+
redirect_url = build_url(tp, @title, @url, @width, @height)
|
32
|
+
|
33
|
+
if redirect_url.present?
|
34
|
+
redirect_to redirect_url
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def xml_config
|
39
|
+
host = "\#{request.protocol}\#{request.host_with_port}"
|
40
|
+
url = "\#{host}\#{root_path}"
|
41
|
+
title = "#{name.humanize.titleize}"
|
42
|
+
tool_id = "#{name}"
|
43
|
+
tc = IMS::LTI::ToolConfig.new(:title => title, :launch_url => url)
|
44
|
+
tc.extend IMS::LTI::Extensions::Canvas::ToolConfig
|
45
|
+
tc.description = "[description goes here]"
|
46
|
+
tc.canvas_privacy_anonymous!
|
47
|
+
tc.canvas_domain!(request.host)
|
48
|
+
tc.canvas_icon_url!("\#{host}/assets/#{name}/icon.png")
|
49
|
+
tc.canvas_text!(title)
|
50
|
+
tc.set_ext_param('canvas.instructure.com', :tool_id, tool_id)
|
51
|
+
<%= @additional_configs.join("\n") %>
|
52
|
+
render xml: tc.to_xml
|
53
|
+
end
|
54
|
+
|
55
|
+
def health_check
|
56
|
+
head 200
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def build_url(tp, title, url, width, height)
|
62
|
+
if tp.accepts_content?
|
63
|
+
if tp.accepts_iframe?
|
64
|
+
redirect_url = tp.iframe_content_return_url(url, width, height, title)
|
65
|
+
elsif tp.accepts_url?
|
66
|
+
redirect_url = tp.url_content_return_url(url, title)
|
67
|
+
elsif tp.accepts_lti_launch_url?
|
68
|
+
redirect_url = tp.lti_launch_content_return_url(url, title, title)
|
69
|
+
end
|
70
|
+
return redirect_url
|
71
|
+
end
|
72
|
+
RUBY
|
73
|
+
end
|
74
|
+
|
75
|
+
route 'root "lti#index"'
|
76
|
+
route 'match "/" => "lti#index", via: [:get, :post]'
|
77
|
+
route 'get "health_check" => "lti#health_check"'
|
78
|
+
route 'get "config(.xml)" => "lti#xml_config", as: :lti_xml_config'
|
79
|
+
|
80
|
+
remove_file "app/views/#{name}/lti/index.html.erb"
|
81
|
+
create_file "app/views/#{name}/lti/index.html.erb" do <<-'RUBY'
|
82
|
+
<div class="container">
|
83
|
+
<h4 class="page-header">
|
84
|
+
<%%= link_to "config.xml", lti_xml_config_path, class: "btn btn-xs btn-primary pull-right" %>
|
85
|
+
<%%= image_tag "NAME/icon.png" %> My LTI App
|
86
|
+
</h4>
|
87
|
+
|
88
|
+
<p>
|
89
|
+
This is an example of how you can select a resource and have it be embedded via LTI.
|
90
|
+
</p>
|
91
|
+
|
92
|
+
<%%= form_tag lti_embed_path do %>
|
93
|
+
<input type="hidden" name="launch_params" value="<%%= @launch_params.to_json %>" />
|
94
|
+
<div class="row">
|
95
|
+
<div class="col-xs-6">
|
96
|
+
<input type="submit" name="embed_type" class="btn btn-large btn-info btn-block"
|
97
|
+
value="Embed a Video" />
|
98
|
+
</div>
|
99
|
+
<div class="col-xs-6">
|
100
|
+
<input type="submit" name="embed_type" class="btn btn-large btn-success btn-block"
|
101
|
+
value="Embed a Picture" />
|
102
|
+
</div>
|
103
|
+
</div>
|
104
|
+
<%% end %>
|
105
|
+
</div>
|
106
|
+
RUBY
|
107
|
+
end
|
108
|
+
|
109
|
+
gsub_file "app/views/#{name}/lti/index.html.erb", "NAME", name
|
110
|
+
|
111
|
+
create_file "app/views/#{name}/lti/embed.html.erb" do <<-'RUBY'
|
112
|
+
<div class="container">
|
113
|
+
<h4 class="page-header">Embed Code Generated</h4>
|
114
|
+
<p>
|
115
|
+
You're not in a system that supports auto-inserting content,
|
116
|
+
so you'll need to copy and past the following code by hand
|
117
|
+
in order to insert it into your content.
|
118
|
+
</p>
|
119
|
+
|
120
|
+
<textarea class="form-control" rows="4"><iframe title="<%%= @title %>" width="<%%= @width %>" height="<%%= @height %>" src="<%%= @url %>" /></textarea>
|
121
|
+
</div>
|
122
|
+
RUBY
|
123
|
+
end
|
124
|
+
|
125
|
+
inject_into_file "app/controllers/#{name}/lti_controller.rb", after: "require_dependency \"#{name}/application_controller\"\n" do <<-"RUBY"
|
126
|
+
|
127
|
+
require "ims/lti"
|
128
|
+
RUBY
|
129
|
+
end
|
130
|
+
|
131
|
+
gsub_file "spec/controllers/#{name}/lti_controller_spec.rb", "get 'index'\n", "get 'index', use_route: :#{name}\n"
|
132
|
+
|
133
|
+
route 'post "embed" => "lti#embed", as: :lti_embed'
|
134
|
+
|
135
|
+
inject_into_file "spec/controllers/#{name}/lti_controller_spec.rb", after: "response.should be_success\n end\n" do <<-"RUBY"
|
136
|
+
describe "GET config" do
|
137
|
+
it "should generate a valid xml cartridge" do
|
138
|
+
request.stub(:env).and_return({
|
139
|
+
"SCRIPT_NAME" => "/#{name}",
|
140
|
+
"rack.url_scheme" => "http",
|
141
|
+
"HTTP_HOST" => "test.host",
|
142
|
+
"PATH_INFO" => "/#{name}"
|
143
|
+
})
|
144
|
+
get 'xml_config', use_route: :#{name}
|
145
|
+
expect(response.body).to include('<blti:title>#{name.humanize.titleize}</blti:title>')
|
146
|
+
expect(response.body).to include('<blti:description>[description goes here]</blti:description>')
|
147
|
+
expect(response.body).to include('<lticm:property name="text">#{name.humanize.titleize}</lticm:property>')
|
148
|
+
expect(response.body).to include('<lticm:property name="tool_id">#{name}</lticm:property>')
|
149
|
+
expect(response.body).to include('<lticm:property name=\"icon_url\">http://test.host/assets/#{name}/icon.png</lticm:property>')
|
150
|
+
end
|
151
|
+
end
|
152
|
+
RUBY
|
153
|
+
end
|
154
|
+
|
155
|
+
inject_into_file "spec/controllers/#{name}/lti_controller_spec.rb", after: "icon.png</lticm:property>')" do <<-"RUBY"
|
156
|
+
|
157
|
+
<%= @extra_expects.join("\n") %>
|
158
|
+
RUBY
|
159
|
+
end
|
160
|
+
|
161
|
+
inside("app/assets/images/#{name}") do
|
162
|
+
run "curl -O https://dl.dropboxusercontent.com/u/2176587/icon.png"
|
163
|
+
end
|
164
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module LtiTemplateBuilder
|
2
|
+
class Rspec < Recipe
|
3
|
+
def setup(args={})
|
4
|
+
@gem_dev_dependencies << ["rspec-rails"]
|
5
|
+
@gem_dev_dependencies << ["capybara"]
|
6
|
+
@gem_dev_dependencies << ["poltergeist"]
|
7
|
+
@after_bundle_commands << "generate 'rspec:install'"
|
8
|
+
@after_bundle_commands << template("add_rspec_to_engine_config")
|
9
|
+
@after_bundle_commands << "generate 'controller test backdoor'"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# append_file ".gitignore" do <<-'RUBY'
|
2
|
+
# spec/test_app/db/*.sqlite3
|
3
|
+
# spec/test_app/db/*.sqlite3-journal
|
4
|
+
# spec/test_app/log/*.log
|
5
|
+
# spec/test_app/tmp/
|
6
|
+
# spec/test_app/.sass-cache
|
7
|
+
# spec/test_app/config/lti_public_resources_config.yml
|
8
|
+
# spec/test_app/config/*.yml
|
9
|
+
# RUBY
|
10
|
+
# end
|
11
|
+
|
12
|
+
append_file "Rakefile" do <<-'RUBY'
|
13
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
|
14
|
+
require 'rspec/core/rake_task'
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
16
|
+
task :default => :spec
|
17
|
+
RUBY
|
18
|
+
end
|
19
|
+
|
20
|
+
inject_into_file "lib/#{name}/engine.rb", after: "isolate_namespace #{name.classify}\n" do <<-"RUBY"
|
21
|
+
|
22
|
+
config.generators do |g|
|
23
|
+
g.test_framework :rspec
|
24
|
+
end
|
25
|
+
RUBY
|
26
|
+
end
|
27
|
+
|
28
|
+
gsub_file "spec/spec_helper.rb", "../../config/environment", "../test_app/config/environment"
|
29
|
+
|
30
|
+
inject_into_file "spec/spec_helper.rb", after: "require 'rspec/autorun'\n" do <<-"RUBY"
|
31
|
+
require 'capybara/rspec'
|
32
|
+
require 'capybara/rails'
|
33
|
+
require 'capybara/poltergeist'
|
34
|
+
|
35
|
+
Capybara.javascript_driver = :poltergeist
|
36
|
+
RUBY
|
37
|
+
end
|
38
|
+
|
39
|
+
remove_file "app/views/#{name}/test/backdoor.html.erb"
|
40
|
+
create_file "app/views/#{name}/test/backdoor.html.erb" do <<-"RUBY"
|
41
|
+
<p>Form to access root page via POST. Used for tests.</p>
|
42
|
+
<%%= form_tag root_path do %>
|
43
|
+
<button type="submit" id="submit">Submit</button>
|
44
|
+
<%% end %>
|
45
|
+
RUBY
|
46
|
+
end
|
47
|
+
|
48
|
+
gsub_file "spec/controllers/#{name}/test_controller_spec.rb", "get 'backdoor'\n", "get 'backdoor', use_route: :#{name}\n"
|
49
|
+
|
50
|
+
create_file "spec/features/#{name}/workflow_spec.rb" do <<-"RUBY"
|
51
|
+
require 'spec_helper'
|
52
|
+
|
53
|
+
describe 'Workflow', type: :request, js: true do
|
54
|
+
it 'app should be accessible via POST' do
|
55
|
+
visit '/#{name}/test/backdoor'
|
56
|
+
click_button('Submit')
|
57
|
+
expect(page).to have_content 'My LTI App'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
RUBY
|
61
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'lti_template_builder/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lti_template_builder"
|
8
|
+
spec.version = LtiTemplateBuilder::VERSION
|
9
|
+
spec.authors = ["Eric Berry"]
|
10
|
+
spec.email = ["cavneb@gmail.com"]
|
11
|
+
spec.summary = %q{Rails mountable engine templates for LTI development}
|
12
|
+
spec.description = %q{Rails mountable engine templates for LTI development}
|
13
|
+
spec.homepage = "https://github.com/instructure/lti_template_builder"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activesupport", ">= 3.2.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "sinatra"
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module LtiTemplateBuilder
|
4
|
+
describe Builder do
|
5
|
+
it "should build a template" do
|
6
|
+
builder = Builder.new
|
7
|
+
|
8
|
+
builder.add :cors_support
|
9
|
+
builder.add :rspec
|
10
|
+
builder.add :lti_extension, { enabled_extensions: [:editor_button, :resource_selection] }
|
11
|
+
|
12
|
+
builder.render_to_screen
|
13
|
+
|
14
|
+
builder.gem_dependencies.count.should eq(1)
|
15
|
+
builder.gem_dev_dependencies.count.should eq(3)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/web/server.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require File.expand_path('../../lib/lti_template_builder', __FILE__)
|
3
|
+
|
4
|
+
class Server < Sinatra::Base
|
5
|
+
|
6
|
+
get '/' do
|
7
|
+
"rails plugin new my_lti_app -T --mountable --dummy-path=spec/test_app -m http://localhost:9292/template"
|
8
|
+
end
|
9
|
+
|
10
|
+
get '/template' do
|
11
|
+
content_type :text
|
12
|
+
builder = LtiTemplateBuilder::Builder.new
|
13
|
+
builder.add :bootstrap_sass
|
14
|
+
builder.add :cors_support
|
15
|
+
builder.add :rspec
|
16
|
+
builder.add :lti_extension, { enabled_extensions: [:editor_button, :resource_selection] }
|
17
|
+
builder.add :extra
|
18
|
+
builder.to_script
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lti_template_builder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Berry
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sinatra
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Rails mountable engine templates for LTI development
|
84
|
+
email:
|
85
|
+
- cavneb@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .rspec
|
92
|
+
- .travis.yml
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- config.ru
|
98
|
+
- lib/lti_template_builder.rb
|
99
|
+
- lib/lti_template_builder/builder.rb
|
100
|
+
- lib/lti_template_builder/recipe.rb
|
101
|
+
- lib/lti_template_builder/recipes/bootstrap_sass/bootstrap_sass.rb
|
102
|
+
- lib/lti_template_builder/recipes/bootstrap_sass/template.erb
|
103
|
+
- lib/lti_template_builder/recipes/cors_support/cors_support.rb
|
104
|
+
- lib/lti_template_builder/recipes/cors_support/template.erb
|
105
|
+
- lib/lti_template_builder/recipes/extra/extra.rb
|
106
|
+
- lib/lti_template_builder/recipes/extra/template.erb
|
107
|
+
- lib/lti_template_builder/recipes/gems/gems.rb
|
108
|
+
- lib/lti_template_builder/recipes/gems/template.erb
|
109
|
+
- lib/lti_template_builder/recipes/lti_extension/lti_extension.rb
|
110
|
+
- lib/lti_template_builder/recipes/lti_extension/template.erb
|
111
|
+
- lib/lti_template_builder/recipes/rspec/add_rspec_to_engine_config.erb
|
112
|
+
- lib/lti_template_builder/recipes/rspec/rspec.rb
|
113
|
+
- lib/lti_template_builder/recipes/rspec/template.erb
|
114
|
+
- lib/lti_template_builder/version.rb
|
115
|
+
- lti_template_builder.gemspec
|
116
|
+
- spec/lib/builder_spec.rb
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
- web/server.rb
|
119
|
+
homepage: https://github.com/instructure/lti_template_builder
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.2.1
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: Rails mountable engine templates for LTI development
|
143
|
+
test_files:
|
144
|
+
- spec/lib/builder_spec.rb
|
145
|
+
- spec/spec_helper.rb
|
146
|
+
has_rdoc:
|