spark_plugs 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +15 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +26 -0
  4. data/app/assets/javascripts/spark_plugs/application.js +13 -0
  5. data/app/assets/javascripts/spark_plugs/static_pages.js +2 -0
  6. data/app/assets/stylesheets/spark_plugs/application.css +15 -0
  7. data/app/assets/stylesheets/spark_plugs/static_pages.css +4 -0
  8. data/app/controllers/spark_plugs/application_controller.rb +2 -0
  9. data/app/controllers/spark_plugs/static_pages_controller.rb +23 -0
  10. data/app/helpers/spark_plugs/application_helper.rb +4 -0
  11. data/app/helpers/spark_plugs/static_pages_helper.rb +7 -0
  12. data/app/models/spark_plugs/static_page.rb +27 -0
  13. data/app/views/spark_plugs/static_pages/show.html.erb +4 -0
  14. data/config/initializers/spark_plugs.rb +11 -0
  15. data/config/routes.rb +3 -0
  16. data/db/migrate/20150306172808_create_spark_plugs_static_pages.rb +11 -0
  17. data/lib/generators/spark_plugs/install_generator.rb +18 -0
  18. data/lib/generators/spark_plugs/templates/initializer.erb +13 -0
  19. data/lib/generators/spark_plugs/views_generator.rb +22 -0
  20. data/lib/spark_plugs.rb +4 -0
  21. data/lib/spark_plugs/engine.rb +16 -0
  22. data/lib/spark_plugs/version.rb +3 -0
  23. data/lib/tasks/spark_plugs_tasks.rake +20 -0
  24. data/spec/controllers/spark_plugs/static_pages_controller_spec.rb +29 -0
  25. data/spec/dummy/README.rdoc +28 -0
  26. data/spec/dummy/Rakefile +6 -0
  27. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  28. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  29. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  30. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  31. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  32. data/spec/dummy/bin/bundle +3 -0
  33. data/spec/dummy/bin/rails +4 -0
  34. data/spec/dummy/bin/rake +4 -0
  35. data/spec/dummy/bin/setup +29 -0
  36. data/spec/dummy/config.ru +4 -0
  37. data/spec/dummy/config/application.rb +33 -0
  38. data/spec/dummy/config/boot.rb +5 -0
  39. data/spec/dummy/config/database.yml +25 -0
  40. data/spec/dummy/config/environment.rb +5 -0
  41. data/spec/dummy/config/environments/development.rb +41 -0
  42. data/spec/dummy/config/environments/production.rb +79 -0
  43. data/spec/dummy/config/environments/test.rb +42 -0
  44. data/spec/dummy/config/initializers/assets.rb +11 -0
  45. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  46. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  47. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  48. data/spec/dummy/config/initializers/inflections.rb +16 -0
  49. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  50. data/spec/dummy/config/initializers/session_store.rb +3 -0
  51. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  52. data/spec/dummy/config/locales/en.yml +23 -0
  53. data/spec/dummy/config/routes.rb +3 -0
  54. data/spec/dummy/config/secrets.yml +22 -0
  55. data/spec/dummy/db/schema.rb +24 -0
  56. data/spec/dummy/db/test.sqlite3 +0 -0
  57. data/spec/dummy/log/test.log +83 -0
  58. data/spec/dummy/public/404.html +67 -0
  59. data/spec/dummy/public/422.html +67 -0
  60. data/spec/dummy/public/500.html +66 -0
  61. data/spec/dummy/public/favicon.ico +0 -0
  62. data/spec/factories/spark_plugs_static_pages.rb +22 -0
  63. data/spec/helpers/spark_plugs/static_pages_helper_spec.rb +25 -0
  64. data/spec/models/spark_plugs/static_page_spec.rb +48 -0
  65. data/spec/rails_helper.rb +65 -0
  66. data/spec/routing/spark_plugs/static_pages_routing_spec.rb +19 -0
  67. data/spec/spec_helper.rb +42 -0
  68. metadata +187 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODBiMjJlM2I1NzhjMjNhZDRjYTQyZmI0ZDZlNDM4NDg2M2ZlZWJiMQ==
5
+ data.tar.gz: !binary |-
6
+ MWY3Mzg5NjE3YWMyMjBkNWJiYzkyY2NjZDc1NmQ1YjA3M2ExMzdiNw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MDAzY2FhZGI2NWQ3Y2E0ZmZkOTE1MzkwMzEzNjM3NDBhYTdlMWQzMDc0NGZl
10
+ NDJkNTMzNjBmYWVhZDg2NzQwMThkYjZjZGYzNmU1MWJjZTc2OWVkNWExMDUx
11
+ ZGE3MzlhMjZiZmIyNDMzOGJlYTM2NzUxNjJlZWY2ZjJjZmMxOWE=
12
+ data.tar.gz: !binary |-
13
+ MWQ3NjlkZDljMmU5MTlmNjEyOGY3NDAwZjliYTViYTFjYmQwYzM0MDMwZDMy
14
+ ODY0NjZlZjNmOWE5NWI4YWIxZmI3ZjEwMjEyNDQxNjFkMGU3NGFkYWVmNmFh
15
+ Y2IwYjJkNzY3ZmM0YmFkMTFlMzM5ZGRmZDc4YzU1Nzg3MzRmMjY=
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Whatisinternet
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/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'SparkPlugs'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
@@ -0,0 +1,13 @@
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 any plugin's vendor/assets/javascripts directory 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
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,15 @@
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 any plugin's vendor/assets/stylesheets directory 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 bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,2 @@
1
+ class SparkPlugs::ApplicationController < ApplicationController
2
+ end
@@ -0,0 +1,23 @@
1
+ require_dependency "spark_plugs/application_controller"
2
+
3
+ module SparkPlugs
4
+ class StaticPagesController < ApplicationController
5
+
6
+ def show
7
+ page = StaticPage.get_page(params[:page])
8
+ if page
9
+ @static_page = page
10
+ expires_in 2.hours, :public => true
11
+ else
12
+ raise ActionController::RoutingError.new("That page could not be found by SparkPlugs")
13
+ end
14
+ end
15
+
16
+
17
+ private
18
+ # Only allow a trusted parameter "white list" through.
19
+ def static_page_params
20
+ params.require(:static_page).permit(:page, :title, :content)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,4 @@
1
+ module SparkPlugs
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ module SparkPlugs
2
+ module StaticPagesHelper
3
+ def set_title
4
+ @title = @static_page.title.to_s
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ # == Schema Information
2
+ #
3
+ # Table name: spark_plugs_static_pages
4
+ #
5
+ # id :integer not null, primary key
6
+ # page :string not null
7
+ # title :string not null
8
+ # content :text
9
+ # created_at :datetime not null
10
+ # updated_at :datetime not null
11
+ #
12
+
13
+ module SparkPlugs
14
+ class StaticPage < ActiveRecord::Base
15
+ validates :page, uniqueness: true
16
+ validates :page, presence: true
17
+ validates :page, length: { minimum: 3 }
18
+ validates :title, presence: true
19
+ validates :title, length: { minimum: 5 }
20
+ validates :content, presence: true
21
+ validates :content, length: { minimum: 5 }
22
+
23
+ def self.get_page(resource)
24
+ StaticPage.find_by_page(resource.to_s)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ <% set_title %>
2
+ <div id="static_content">
3
+ <%= @static_page.content.html_safe %>
4
+ </div>
@@ -0,0 +1,11 @@
1
+ module SparkPlugs
2
+ module ApplicationHelper
3
+ def method_missing(method, *args, &block)
4
+ if (method.to_s.end_with?('_path') || method.to_s.end_with?('_url')) && main_app.respond_to?(method)
5
+ main_app.send(method, *args)
6
+ else
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ SparkPlugs::Engine.routes.draw do
2
+ match '/:page' => 'static_pages#show', via: [:get]
3
+ end
@@ -0,0 +1,11 @@
1
+ class CreateSparkPlugsStaticPages < ActiveRecord::Migration
2
+ def change
3
+ create_table :spark_plugs_static_pages do |t|
4
+ t.string :page, null: false, unique: true
5
+ t.string :title, null: false
6
+ t.text :content
7
+
8
+ t.timestamps null: false
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ require 'rails/generators'
2
+
3
+ module SparkPlugs
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates',__FILE__)
6
+
7
+ argument :_namespace, type: :string, required: false, desc: 'SparkPlug namespace'
8
+
9
+ def install
10
+ namespace = defined?(::HighVoltage) ? "pages" : "static_pages"
11
+ namespace = ask("Where would you like to mount spark_plugs? [#{namespace}] is default")
12
+ route("mount SparkPlugs::Engine => '/#{namespace}', as: 'spark_plugs'")
13
+ rake("db:migrate")
14
+ #template 'initializer.erb', 'config/initializers/spark_plugs.rb'
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ SparkPlugs.config do |config|
2
+
3
+ # TODO: Implement these
4
+ # Devise
5
+ # config.authenticate_with do
6
+ # warden.authenticate! scope: :user
7
+ # end
8
+ # config.current_user_method(&:crrent_user)
9
+ #
10
+ # CanCan
11
+ # config.authorize_with :cancan
12
+
13
+ end
@@ -0,0 +1,22 @@
1
+ #Thanks to devise and rapidfire
2
+
3
+ require 'rails/generators'
4
+
5
+ module SparkPlugs
6
+ module Generators
7
+ class ViewsGenerator < Rails::Generators::Base
8
+ source_root File.expand_path("../../../../app/views/spark_plugs", __FILE__)
9
+ desc "Copies the default SparkPlug views into your application."
10
+
11
+ def copy_views
12
+ view_directory :static_pages
13
+ end
14
+
15
+ protected
16
+ def view_directory(name)
17
+ directory name.to_s, "app/views/spark_plugs/#{name}"
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ require "spark_plugs/engine"
2
+
3
+ module SparkPlugs
4
+ end
@@ -0,0 +1,16 @@
1
+ module SparkPlugs
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace SparkPlugs
4
+ config.generators do |g|
5
+ g.test_framework :rspec, :view_specs => false
6
+ g.fixture_replacement :factory_girl, :dir => 'spec/factories'
7
+ end
8
+ initializer :append_migrations do |app|
9
+ unless app.root.to_s.match root.to_s
10
+ config.paths["db/migrate"].expanded.each do |expanded_path|
11
+ app.config.paths["db/migrate"] << expanded_path
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module SparkPlugs
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,20 @@
1
+ # desc "Explaining what the task does"
2
+ # task :spark_plugs do
3
+ # # Task goes here
4
+ # end
5
+ namespace :spark_plugs do
6
+ desc 'Install spark_plugs'
7
+ task :install do
8
+ system 'rails g spark_plugs:install'
9
+ end
10
+
11
+ desc 'Uninstall spark_plugs'
12
+ task :uninstall do
13
+ system 'rails g spark_plugs:uninstall'
14
+ end
15
+
16
+ desc 'Generate spark_plug views'
17
+ task :views do
18
+ system 'rails g spark_plugs:views'
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ require 'rails_helper'
2
+ require 'faker'
3
+
4
+
5
+ module SparkPlugs
6
+ RSpec.describe StaticPagesController, type: :controller do
7
+ routes { SparkPlugs::Engine.routes }
8
+
9
+ before :all do
10
+ Rails.cache.clear
11
+ @static_page = FactoryGirl.create :spark_plugs_static_page
12
+ end
13
+
14
+ let (:valid_session) { {} }
15
+
16
+ describe "GET #show" do
17
+ it "assigns the requested static_page as @static_page" do
18
+ get :show, {:id => @static_page.to_param, page: @static_page.page.to_param}, valid_session
19
+ expect(assigns(:static_page)).to eq(@static_page)
20
+ end
21
+ it "raises an error on invalid data" do
22
+ expect {
23
+ get :show, {id: @static_page.to_param, page: 'invalidinvalid'}
24
+ }.to raise_exception(ActionController::RoutingError)
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
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 any plugin's vendor/assets/javascripts directory 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
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
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 any plugin's vendor/assets/stylesheets directory 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 bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end