gnarus_activity 1.1.0

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.
Files changed (76) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +73 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/stylesheets/gnarus_activity/application.css +13 -0
  5. data/app/controllers/gnarus_activity/application_controller.rb +7 -0
  6. data/app/controllers/gnarus_activity/attempts_controller.rb +13 -0
  7. data/app/controllers/gnarus_activity/executions_controller.rb +14 -0
  8. data/app/controllers/gnarus_activity/exercises_controller.rb +55 -0
  9. data/app/controllers/gnarus_activity/status_controller.rb +11 -0
  10. data/app/helpers/gnarus_activity/application_helper.rb +4 -0
  11. data/app/models/activity_processor.rb +5 -0
  12. data/app/models/gnarus_activity/attempt.rb +15 -0
  13. data/app/models/gnarus_activity/execution.rb +6 -0
  14. data/app/models/gnarus_activity/exercise.rb +7 -0
  15. data/app/views/gnarus_activity/exercises/_form.html.erb +27 -0
  16. data/app/views/gnarus_activity/exercises/_my_fields.html.erb +0 -0
  17. data/app/views/gnarus_activity/exercises/edit.html.erb +6 -0
  18. data/app/views/gnarus_activity/exercises/index.html.erb +25 -0
  19. data/app/views/gnarus_activity/exercises/new.html.erb +5 -0
  20. data/app/views/gnarus_activity/exercises/show.html.erb +15 -0
  21. data/app/views/layouts/gnarus_activity/application.html.erb +15 -0
  22. data/bin/gnarus +32 -0
  23. data/config/initializers/gnarus_activity.rb +1 -0
  24. data/config/routes.rb +13 -0
  25. data/db/migrate/20120405185453_create_gnarus_exercise_exercises.rb +11 -0
  26. data/db/migrate/20120405185533_create_gnarus_exercise_attempts.rb +12 -0
  27. data/db/migrate/20120408064126_create_gnarus_exercise_executions.rb +12 -0
  28. data/lib/activity_template.rb +46 -0
  29. data/lib/assets/javascripts/gnarus_activity/application.js +15 -0
  30. data/lib/assets/javascripts/gnarus_activity/attempt.js +62 -0
  31. data/lib/gnarus_activity.rb +4 -0
  32. data/lib/gnarus_activity/engine.rb +5 -0
  33. data/lib/gnarus_activity/version.rb +3 -0
  34. data/lib/templates/gnarus_activity/attempts/index.html.erb +35 -0
  35. data/test/dummy/README.rdoc +261 -0
  36. data/test/dummy/Rakefile +7 -0
  37. data/test/dummy/app/assets/javascripts/application.js +15 -0
  38. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  39. data/test/dummy/app/controllers/application_controller.rb +3 -0
  40. data/test/dummy/app/helpers/application_helper.rb +2 -0
  41. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  42. data/test/dummy/config.ru +4 -0
  43. data/test/dummy/config/application.rb +56 -0
  44. data/test/dummy/config/boot.rb +10 -0
  45. data/test/dummy/config/database.yml +25 -0
  46. data/test/dummy/config/environment.rb +5 -0
  47. data/test/dummy/config/environments/development.rb +37 -0
  48. data/test/dummy/config/environments/production.rb +67 -0
  49. data/test/dummy/config/environments/test.rb +37 -0
  50. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  51. data/test/dummy/config/initializers/inflections.rb +15 -0
  52. data/test/dummy/config/initializers/mime_types.rb +5 -0
  53. data/test/dummy/config/initializers/secret_token.rb +7 -0
  54. data/test/dummy/config/initializers/session_store.rb +8 -0
  55. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  56. data/test/dummy/config/locales/en.yml +5 -0
  57. data/test/dummy/config/routes.rb +4 -0
  58. data/test/dummy/log/development.log +0 -0
  59. data/test/dummy/log/test.log +0 -0
  60. data/test/dummy/public/404.html +26 -0
  61. data/test/dummy/public/422.html +26 -0
  62. data/test/dummy/public/500.html +25 -0
  63. data/test/dummy/public/favicon.ico +0 -0
  64. data/test/dummy/script/rails +6 -0
  65. data/test/fixtures/gnarus_exercise/attempts.yml +11 -0
  66. data/test/fixtures/gnarus_exercise/executions.yml +11 -0
  67. data/test/fixtures/gnarus_exercise/exercises.yml +9 -0
  68. data/test/fixtures/gnarus_exercise/users.yml +11 -0
  69. data/test/gnarus_exercise_test.rb +7 -0
  70. data/test/integration/navigation_test.rb +10 -0
  71. data/test/test_helper.rb +10 -0
  72. data/test/unit/gnarus_activity/attempt_test.rb +9 -0
  73. data/test/unit/gnarus_activity/execution_test.rb +9 -0
  74. data/test/unit/gnarus_activity/exercise_test.rb +9 -0
  75. data/test/unit/gnarus_activity/user_test.rb +9 -0
  76. metadata +196 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
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.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ GnarusActivity
2
+ ==============
3
+
4
+ This project rocks and uses MIT-LICENSE. Install
5
+
6
+ ```
7
+ gem install gnarus_activity
8
+ ```
9
+
10
+ Configuring a new project
11
+ =========================
12
+
13
+ ```
14
+ gnarus activity my_project
15
+ ```
16
+
17
+ You will be prompted about adding <code>devise</code> into your application, then it is up
18
+ to you accept it (if you want authentication in your exercises) or not.
19
+
20
+ Default execution
21
+ =================
22
+
23
+ The default index.html.erb displays a solution field where the user types his response.
24
+
25
+ Due to the invocation of:
26
+
27
+ ```javascript
28
+ gnarus.attemptForm({ solution : function() {},
29
+ callback : function(result) {},
30
+ gnarusUri : '',
31
+ allowsSkip : true }).setup();
32
+ ```
33
+
34
+ When clicking in the try button, the solution function is invoked. It should return
35
+ the response to send to the rails server for processing.
36
+
37
+ ### Processing the user response
38
+
39
+ The method <code>ActivityProcessor#process(attempt, params)</code> is invoked.
40
+ It should return an Execution with the field succeded=true or false.
41
+ Example:
42
+
43
+ ```ruby
44
+ class ActivityProcessor
45
+ def self.process(attempt, params)
46
+ isCorrect = params[:solution]=="42"
47
+ attempt.executions.create (
48
+ solution: params[:solution],
49
+ suceeded: isCorrect
50
+ )
51
+ end
52
+ end
53
+ ```
54
+
55
+ The default implementation of this method *always* return suceeded = true.
56
+
57
+ ### Showing the response to the user
58
+
59
+ After processing, the callback is invoked with the result.succeeded.
60
+
61
+ (1) If it is false, you should display an error message.
62
+ (2) If it is true, display what you want. In this case, the page will be AUTOMATICALLY
63
+ redirected to the gnarusUri. The exercise finishes
64
+
65
+
66
+ TODO
67
+ ====
68
+
69
+ - the SOLUTION member should be renamed to something more meaningful (response)
70
+ - generated template should add gnarus_activity version to gemfile
71
+ - update method UPDATE from exercise to be safe
72
+ - we are using the index file to show an attempt, nasty. a GET to a better named method
73
+ - automatic reload from ActivityProcessor
data/Rakefile ADDED
@@ -0,0 +1,40 @@
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 = 'GnarusActivity'
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
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -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
+ */
@@ -0,0 +1,7 @@
1
+ module GnarusActivity
2
+ class ApplicationController < ActionController::Base
3
+ def after_sign_in_path_for(resource)
4
+ return root_path
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ module GnarusActivity
2
+ class AttemptsController < ApplicationController
3
+
4
+ skip_before_filter :verify_authenticity_token
5
+
6
+ def index
7
+ exercise = Exercise.find(params[:exercise_id])
8
+ @attempt = exercise.attempts.create(params[:attempt])
9
+ @attempt.save
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module GnarusActivity
2
+ class ExecutionsController < ApplicationController
3
+
4
+ skip_before_filter :verify_authenticity_token
5
+
6
+ def create
7
+ @attempt = Attempt.find params[:attempt_id]
8
+ execution = ::ActivityProcessor.process @attempt, params
9
+ execution.save
10
+ render :json => execution.to_json(:includes => :attempt)
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,55 @@
1
+ module GnarusActivity
2
+ class ExercisesController < ApplicationController
3
+
4
+ before_filter :authenticate_user! if defined?(Devise)
5
+
6
+ def index
7
+ @exercises = Exercise.all.select{|e| e.author.id == current_user.id}
8
+ end
9
+
10
+ def show
11
+ @exercise = Exercise.find(params[:id])
12
+ end
13
+
14
+ def new
15
+ @exercise = Exercise.new
16
+ end
17
+
18
+ # GET /exercises/1/edit
19
+ def edit
20
+ @exercise = Exercise.find(params[:id])
21
+ end
22
+
23
+ def create
24
+ @exercise = Exercise.new(params[:exercise])
25
+ @exercise.author = current_user if defined?(Devise)
26
+
27
+ if @exercise.save
28
+ redirect_to @exercise, notice: 'Exercise was successfully created.'
29
+ else
30
+ render action: "new"
31
+ end
32
+ end
33
+
34
+ def update
35
+ @exercise = Exercise.find(params[:id])
36
+ if defined?(Devise) && @exercise.author == current_user
37
+ params[:exercise].delete :author_id
38
+ @exercise.update_attributes(params[:exercise])
39
+ end
40
+
41
+ redirect_to @exercise, notice: 'Exercise was successfully updated.'
42
+ end
43
+
44
+ # DELETE /exercises/1
45
+ # DELETE /exercises/1.json
46
+ def destroy
47
+ @exercise = Exercise.find(params[:id])
48
+ if defined?(Devise) && @exercise.author == current_user
49
+ @exercise.destroy
50
+ end
51
+
52
+ redirect_to exercises_url
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,11 @@
1
+ module GnarusActivity
2
+ class StatusController < ApplicationController
3
+
4
+ skip_before_filter :verify_authenticity_token
5
+
6
+ def ping
7
+ render :json => {:status => "alive"}
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ module GnarusActivity
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,5 @@
1
+ class ActivityProcessor
2
+ def self.process(attempt, params)
3
+ attempt.executions.create :solution => params[:solution], :suceeded => true
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ module GnarusActivity
2
+ class Attempt < ActiveRecord::Base
3
+ belongs_to :exercise
4
+ has_many :executions
5
+ attr_accessible :return_uri, :author_id
6
+
7
+ def full_return_uri
8
+ (return_uri || "") + "?answer=" + (solution || "")
9
+ end
10
+
11
+ def process(params)
12
+ executions.create :solution => params[:solution], :suceeded => params[:suceeded]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ module GnarusActivity
2
+ class Execution < ActiveRecord::Base
3
+ attr_accessible :attempt, :solution, :suceeded
4
+ belongs_to :attempt
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ module GnarusActivity
2
+ class Exercise < ActiveRecord::Base
3
+ attr_accessible :author_id, :content, :title
4
+ has_many :attempts
5
+ belongs_to :author, :class_name => User if defined?(User)
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ <%= form_for(@exercise) do |f| %>
2
+ <% if @exercise.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@exercise.errors.count, "error") %> prohibited this exercise from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @exercise.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 :title %><br />
16
+ <%= f.text_area :title %>
17
+ </div>
18
+
19
+ <div class="field">
20
+ <%= f.label :content %><br />
21
+ <%= f.text_area :content %>
22
+ </div>
23
+ <%= render :partial => "my_fields", :locals => { :f => f} %>
24
+ <div class="actions">
25
+ <%= f.submit %>
26
+ </div>
27
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing exercise</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @exercise %> |
6
+ <%= link_to 'Back', exercises_path %>
@@ -0,0 +1,25 @@
1
+ <h1>Listing exercises</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Title</th>
6
+ <th>Content</th>
7
+ <th></th>
8
+ <th></th>
9
+ <th></th>
10
+ </tr>
11
+
12
+ <% @exercises.each do |exercise| %>
13
+ <tr>
14
+ <td><%= exercise.title %></td>
15
+ <td><%= exercise.content %></td>
16
+ <td><%= link_to 'Show', exercise %></td>
17
+ <td><%= link_to 'Edit', edit_exercise_path(exercise) %></td>
18
+ <td><%= link_to 'Destroy', exercise, confirm: 'Are you sure?', method: :delete %></td>
19
+ </tr>
20
+ <% end %>
21
+ </table>
22
+
23
+ <br />
24
+
25
+ <%= link_to 'New Exercise', new_exercise_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New exercise</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', exercises_path %>
@@ -0,0 +1,15 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <b>Title:</b>
5
+ <%= @exercise.title %>
6
+ </p>
7
+
8
+ <p>
9
+ <b>Content:</b>
10
+ <%= @exercise.content %>
11
+ </p>
12
+
13
+ <a href="/exercises/<%= @exercise.id%>/attempts">Preview</a> |
14
+ <%= link_to 'Edit', edit_exercise_path(@exercise) %> |
15
+ <%= link_to 'Back', exercises_path %>
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Gnarus Activity</title>
5
+ <%= stylesheet_link_tag "gnarus_activity/application", :media => "all" %>
6
+ <%= javascript_include_tag "gnarus_activity/application" %>
7
+ <%= javascript_include_tag "application" %>
8
+ <%= csrf_meta_tags %>
9
+ </head>
10
+ <body>
11
+
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>
data/bin/gnarus ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding:utf-8
3
+ template = File.expand_path("../../lib/activity_template.rb", __FILE__)
4
+
5
+ puts ":::::::::::::::::::::::"
6
+ puts "gnarus activity utility"
7
+ puts ":::::::::::::::::::::::\n\n"
8
+
9
+ if !ARGV[0]
10
+ puts "ooops, what do you want me to do?"
11
+ puts "did you want to create an activity?"
12
+ puts " if so: gnarus activity [project]\n\n"
13
+ exit(0)
14
+ end
15
+
16
+ command = ARGV[0]
17
+ option = ARGV[1]
18
+
19
+ if command == "activity"
20
+ if !option
21
+ puts "you need a project name, try: gnarus activity [project]\n\n"
22
+ exit(0)
23
+ end
24
+ execution = "rails new #{option} -m #{template}"
25
+ puts "executando: #{execution}"
26
+ system(execution)
27
+ exit(0)
28
+ end
29
+
30
+ puts "i don't know any [#{command}]"
31
+ puts "Y U NO TELL ME WHAT TO DO?!?!?\n\n"
32
+ exit(0)