betauseraccess 0.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.
data/README.rdoc ADDED
@@ -0,0 +1,9 @@
1
+ ==Introduction
2
+
3
+ This is a simple gem to help limit alpha/beta/early access to a site or features of a site.
4
+
5
+ This gem is very early so please send any feedback via the issues page.
6
+
7
+ There is a demo project available on github: https://github.com/cbrulak/BetaUserAccessApp
8
+
9
+ I used the gem: rails3_engine_demo (https://github.com/krschacht/rails_3_engine_demo) as a basis for this gem.
@@ -0,0 +1,99 @@
1
+ module Betauseraccess
2
+ class SignUpForBetaAccessesController < ApplicationController
3
+ before_filter :isuseramoderator, :except=>[:new,:create,:thanks]
4
+
5
+ def isuseramoderator
6
+ unless(IsCurrentUserModerator?)
7
+ redirect_to root_path
8
+ end
9
+ end
10
+
11
+ def thanks
12
+ respond_to do |format|
13
+ format.html
14
+ end
15
+ end
16
+
17
+ # GET /sign_up_for_beta_accesses
18
+ # GET /sign_up_for_beta_accesses.xml
19
+ def index
20
+ @sign_up_for_beta_accesses = SignUpForBetaAccess.all
21
+
22
+ respond_to do |format|
23
+ format.html # index.html.erb
24
+ format.xml { render :xml => @sign_up_for_beta_accesses }
25
+ end
26
+ end
27
+
28
+ # GET /sign_up_for_beta_accesses/1
29
+ # GET /sign_up_for_beta_accesses/1.xml
30
+ def show
31
+ @sign_up_for_beta_access = SignUpForBetaAccess.find(params[:id])
32
+
33
+ respond_to do |format|
34
+ format.html # show.html.erb
35
+ format.xml { render :xml => @sign_up_for_beta_access }
36
+ end
37
+ end
38
+
39
+ # GET /sign_up_for_beta_accesses/new
40
+ # GET /sign_up_for_beta_accesses/new.xml
41
+ def new
42
+ @sign_up_for_beta_access = SignUpForBetaAccess.new
43
+
44
+ respond_to do |format|
45
+ format.html # new.html.erb
46
+ format.xml { render :xml => @sign_up_for_beta_access }
47
+ end
48
+ end
49
+
50
+ # GET /sign_up_for_beta_accesses/1/edit
51
+ def edit
52
+ @sign_up_for_beta_access = SignUpForBetaAccess.find(params[:id])
53
+ end
54
+
55
+ # POST /sign_up_for_beta_accesses
56
+ # POST /sign_up_for_beta_accesses.xml
57
+ def create
58
+ @sign_up_for_beta_access = SignUpForBetaAccess.new(params[:sign_up_for_beta_access])
59
+
60
+ respond_to do |format|
61
+ if @sign_up_for_beta_access.save
62
+ format.html { redirect_to(@sign_up_for_beta_access, :notice => 'Sign up for beta access was successfully created.') }
63
+ format.xml { render :xml => @sign_up_for_beta_access, :status => :created, :location => @sign_up_for_beta_access }
64
+ else
65
+ format.html { render :action => "new" }
66
+ format.xml { render :xml => @sign_up_for_beta_access.errors, :status => :unprocessable_entity }
67
+ end
68
+ end
69
+ end
70
+
71
+ # PUT /sign_up_for_beta_accesses/1
72
+ # PUT /sign_up_for_beta_accesses/1.xml
73
+ def update
74
+ @sign_up_for_beta_access = SignUpForBetaAccess.find(params[:id])
75
+
76
+ respond_to do |format|
77
+ if @sign_up_for_beta_access.update_attributes(params[:sign_up_for_beta_access])
78
+ format.html { redirect_to(@sign_up_for_beta_access, :notice => 'Sign up for beta access was successfully updated.') }
79
+ format.xml { head :ok }
80
+ else
81
+ format.html { render :action => "edit" }
82
+ format.xml { render :xml => @sign_up_for_beta_access.errors, :status => :unprocessable_entity }
83
+ end
84
+ end
85
+ end
86
+
87
+ # DELETE /sign_up_for_beta_accesses/1
88
+ # DELETE /sign_up_for_beta_accesses/1.xml
89
+ def destroy
90
+ @sign_up_for_beta_access = SignUpForBetaAccess.find(params[:id])
91
+ @sign_up_for_beta_access.destroy
92
+
93
+ respond_to do |format|
94
+ format.html { redirect_to(sign_up_for_beta_accesses_url) }
95
+ format.xml { head :ok }
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,2 @@
1
+ ## Look in lib/application_helper.rb
2
+ ## I can't figure out how to get it included unless I put it that directory
@@ -0,0 +1,9 @@
1
+ module Betauseraccess
2
+ module WidgetsHelper
3
+
4
+ def helper_for_widgets_view
5
+ "this output is coming from a helper method just for the widgets controller"
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ module Betauseraccess
2
+ class SignUpForBetaAccess < ActiveRecord::Base
3
+ end
4
+ end
@@ -0,0 +1,25 @@
1
+ <%= form_for(@sign_up_for_beta_access) do |f| %>
2
+ <% if @sign_up_for_beta_access.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@sign_up_for_beta_access.errors.count, "error") %> prohibited this sign_up_for_beta_access from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @sign_up_for_beta_access.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 :name %><br />
16
+ <%= f.text_field :name %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :twitterid %><br />
20
+ <%= f.text_field :twitterid, :value => session[:beta_user_twitterid] %>
21
+ </div>
22
+ <div class="actions">
23
+ <%= f.submit %>
24
+ </div>
25
+ <% end %>
@@ -0,0 +1,26 @@
1
+ <h1>Editing sign_up_for_beta_access</h1>
2
+
3
+ <%= form_for(@sign_up_for_beta_access) do |f| %>
4
+ <% if @sign_up_for_beta_access.errors.any? %>
5
+ <div id="error_explanation">
6
+ <h2><%= pluralize(@sign_up_for_beta_access.errors.count, "error") %> prohibited this sign_up_for_beta_access from being saved:</h2>
7
+
8
+ <ul>
9
+ <% @sign_up_for_beta_access.errors.full_messages.each do |msg| %>
10
+ <li><%= msg %></li>
11
+ <% end %>
12
+ </ul>
13
+ </div>
14
+ <% end %>
15
+
16
+ <div class="field">
17
+ <%= f.label :allowedaccess %><br />
18
+ <%= f.check_box :allowedaccess,:checked => @sign_up_for_beta_access.allowedaccess %>
19
+ </div>
20
+ <div class="actions">
21
+ <%= f.submit %>
22
+ </div>
23
+ <% end %>
24
+
25
+ <%= link_to 'Show', @sign_up_for_beta_access %> |
26
+ <%= link_to 'Back', sign_up_for_beta_accesses_path %>
@@ -0,0 +1,27 @@
1
+ <h1>Listing sign_up_for_beta_accesses</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Name</th>
6
+ <th>Twitterid</th>
7
+ <th>Allowedaccess</th>
8
+ <th></th>
9
+ <th></th>
10
+ <th></th>
11
+ </tr>
12
+
13
+ <% @sign_up_for_beta_accesses.each do |sign_up_for_beta_access| %>
14
+ <tr>
15
+ <td><%= sign_up_for_beta_access.name %></td>
16
+ <td><%= sign_up_for_beta_access.twitterid %></td>
17
+ <td><%= sign_up_for_beta_access.allowedaccess %></td>
18
+ <td><%= link_to 'Show', sign_up_for_beta_access %></td>
19
+ <td><%= link_to 'Edit', edit_sign_up_for_beta_access_path(sign_up_for_beta_access) %></td>
20
+ <td><%= link_to 'Destroy', sign_up_for_beta_access, :confirm => 'Are you sure?', :method => :delete %></td>
21
+ </tr>
22
+ <% end %>
23
+ </table>
24
+
25
+ <br />
26
+
27
+ <%= link_to 'New Sign up for beta access', new_betauseraccess_sign_up_for_beta_access_path %>
@@ -0,0 +1,6 @@
1
+ <h2>Please add your name and we'll get back to you when the public beta opens</h2>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <h3> Thanks! </h3>
6
+ <%= link_to 'Back', sign_up_for_beta_accesses_path %>
@@ -0,0 +1,20 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <b>Name:</b>
5
+ <%= @sign_up_for_beta_access.name %>
6
+ </p>
7
+
8
+ <p>
9
+ <b>Twitterid:</b>
10
+ <%= @sign_up_for_beta_access.twitterid %>
11
+ </p>
12
+
13
+ <p>
14
+ <b>Allowedaccess:</b>
15
+ <%= @sign_up_for_beta_access.allowedaccess %>
16
+ </p>
17
+
18
+
19
+ <%= link_to 'Edit', edit_sign_up_for_beta_access_path(@sign_up_for_beta_access) %> |
20
+ <%= link_to 'Back', sign_up_for_beta_accesses_path %>
@@ -0,0 +1 @@
1
+ <h2>Thanks for signing up!</h2>
@@ -0,0 +1,12 @@
1
+
2
+ <% content_for :content do %>
3
+
4
+ <%= stylesheet_link_tag("betauseraccess") %>
5
+
6
+ <div class="red_border">
7
+ <%= yield %>
8
+ </div>
9
+
10
+ <% end -%>
11
+
12
+ <%= render :file => 'layouts/application' %>
data/config/routes.rb ADDED
@@ -0,0 +1,19 @@
1
+ Rails.application.routes.draw do |map|
2
+
3
+ mount_at = Betauseraccess::Engine.config.mount_at
4
+
5
+ #match mount_at => 'betauseraccess/sign_up_for_beta_access#index'
6
+
7
+ map.resources :sign_up_for_beta_accesses,
8
+ :controller => "betauseraccess/sign_up_for_beta_accesses",
9
+ :path_prefix => mount_at,
10
+ :name_prefix => "betauseraccess_"
11
+
12
+
13
+ #resources :sign_up_for_beta_accesses do
14
+ # collection do
15
+ # get 'thanks'
16
+ # end
17
+ #end
18
+
19
+ end
@@ -0,0 +1,36 @@
1
+ module Betauseraccess
2
+ module ActsAsWidget
3
+
4
+ ## Define ModelMethods
5
+ module Base
6
+ def self.included(klass)
7
+ klass.class_eval do
8
+ extend Config
9
+ end
10
+ end
11
+
12
+ module Config
13
+ def acts_as_widget
14
+
15
+ # This is where arbitrary code goes that you want to
16
+ # add to the class that declared "acts_as_widget"
17
+
18
+ has_many :widgets, :class_name => 'Betauseraccess::Widget'
19
+
20
+ include Betauseraccess::ActsAsWidget::Base::InstanceMethods
21
+ end
22
+ end
23
+
24
+ module InstanceMethods
25
+
26
+ def factory_name
27
+ "this is an example instance method"
28
+ end
29
+
30
+ end # InstanceMethods
31
+ end
32
+
33
+ end
34
+ end
35
+
36
+ ::ActiveRecord::Base.send :include, Betauseraccess::ActsAsWidget::Base
@@ -0,0 +1,28 @@
1
+ module Betauseraccess
2
+ ## Define ControllerMethods
3
+ module Controller
4
+ ## this one manages the usual self.included, klass_eval stuff
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ before_filter :test_controller_instance_method
9
+ end
10
+
11
+ module InstanceMethods
12
+ def test_controller_instance_method
13
+ puts "###### This text is coming from an application_controller before_filter that is being declared and triggered from inside the engine. This before_filter is automatically integrated in when the engine is installed into an app. Look inside lib/application_controller.rb to find it. ######"
14
+ end
15
+
16
+ # This method is available inside application_controller but it is not being
17
+ # automatically executed. Notice the before_filter line above that is automatically
18
+ # executing the first method.
19
+ def second_controller_instance_method
20
+ puts "###### This method is not automatically run inside application_controller, but it is available inside application_controller. To see this example add 'before_filter :second_controller_instance_method' at the top of your app's application_controller.rb ######"
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ ::ActionController::Base.send :include, Betauseraccess::Controller
27
+
28
+
@@ -0,0 +1,7 @@
1
+ module ApplicationHelper
2
+
3
+ def app_wide_helper_method
4
+ "this output is from an app-wide helper method that is declared within the gem"
5
+ end
6
+
7
+ end
@@ -0,0 +1,5 @@
1
+ module Betauseraccess
2
+ require 'engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
3
+ #require 'acts_as_widget/base'
4
+ require 'application_controller'
5
+ end
data/lib/engine.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'betauseraccess'
2
+ require 'rails'
3
+ require 'action_controller'
4
+ require 'application_helper'
5
+
6
+ module Betauseraccess
7
+ class Engine < Rails::Engine
8
+
9
+ # Config defaults
10
+ config.widget_factory_name = "default factory name"
11
+ config.mount_at = '/'
12
+
13
+ # Load rake tasks
14
+ rake_tasks do
15
+ load File.join(File.dirname(__FILE__), 'rails/railties/tasks.rake')
16
+ end
17
+
18
+ # Check the gem config
19
+ initializer "check config" do |app|
20
+
21
+ # make sure mount_at ends with trailing slash
22
+ config.mount_at += '/' unless config.mount_at.last == '/'
23
+ end
24
+
25
+ initializer "static assets" do |app|
26
+ app.middleware.use ::ActionDispatch::Static, "#{root}/public"
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,82 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ class BetauseraccessGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+
7
+ def self.source_root
8
+ File.join(File.dirname(__FILE__), 'templates')
9
+ end
10
+
11
+ def self.next_migration_number(dirname) #:nodoc:
12
+ if ActiveRecord::Base.timestamped_migrations
13
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
14
+ else
15
+ "%.3d" % (current_migration_number(dirname) + 1)
16
+ end
17
+ end
18
+
19
+
20
+ # Every method that is declared below will be automatically executed when the generator is run
21
+
22
+ def create_migration_file
23
+ f = File.open File.join(File.dirname(__FILE__), 'templates', 'schema.rb')
24
+ schema = f.read; f.close
25
+
26
+ schema.gsub!(/ActiveRecord::Schema.*\n/, '')
27
+ schema.gsub!(/^end\n*$/, '')
28
+
29
+ f = File.open File.join(File.dirname(__FILE__), 'templates', 'migration.rb')
30
+ migration = f.read; f.close
31
+ migration.gsub!(/SCHEMA_AUTO_INSERTED_HERE/, schema)
32
+
33
+ tmp = File.open "tmp/~migration_ready.rb", "w"
34
+ tmp.write migration
35
+ tmp.close
36
+
37
+ migration_template '../../../tmp/~migration_ready.rb',
38
+ 'db/migrate/create_betauseraccess_tables.rb'
39
+ remove_file 'tmp/~migration_ready.rb'
40
+ end
41
+
42
+ def copy_initializer_file
43
+ copy_file 'initializer.rb', 'config/initializers/betauseraccess.rb'
44
+ end
45
+
46
+ def update_application_template
47
+ f = File.open "app/views/layouts/application.html.erb"
48
+ layout = f.read; f.close
49
+
50
+ if layout =~ /<%=[ ]+yield[ ]+%>/
51
+ print " \e[1m\e[34mquestion\e[0m Your layouts/application.html.erb layout currently has the line <%= yield %>. This gem needs to change this line to <%= content_for?(:content) ? yield(:content) : yield %> to support its nested layouts. This change should not affect any of your existing layouts or views. Is this okay? [y/n] "
52
+ begin
53
+ answer = gets.chomp
54
+ end while not answer =~ /[yn]/i
55
+
56
+ if answer =~ /y/i
57
+
58
+ layout.gsub!(/<%=[ ]+yield[ ]+%>/, '<%= content_for?(:content) ? yield(:content) : yield %>')
59
+
60
+ tmp = File.open "tmp/~application.html.erb", "w"
61
+ tmp.write layout; tmp.close
62
+
63
+ remove_file 'app/views/layouts/application.html.erb'
64
+ copy_file '../../../tmp/~application.html.erb',
65
+ 'app/views/layouts/application.html.erb'
66
+ remove_file 'tmp/~application.html.erb'
67
+ end
68
+ elsif layout =~ /<%=[ ]+content_for\?\(:content\) \? yield\(:content\) : yield[ ]+%>/
69
+ puts " \e[1m\e[33mskipping\e[0m layouts/application.html.erb modification is already done."
70
+ else
71
+ puts " \e[1m\e[31mconflict\e[0m The gem is confused by your layouts/application.html.erb. It does not contain the default line <%= yield %>, you may need to make manual changes to get this gem's nested layouts working. Visit ###### for details."
72
+ end
73
+ end
74
+
75
+ def copy_controller
76
+ copy_file '../../../../../app/controllers/betauseraccess/sign_up_for_beta_accesses_controller.rb', 'app/controllers/sign_up_for_beta_accesses_controller.rb'
77
+ end
78
+
79
+ def copy_views
80
+ directory '../../../../../app/views/betauseraccess/sign_up_for_beta_accesses', 'app/views/sign_up_for_beta_accesses/'
81
+ end
82
+ end
@@ -0,0 +1,8 @@
1
+ module Betauseraccess
2
+ class Engine < Rails::Engine
3
+
4
+ config.mount_at = '/betauseraccess'
5
+ #config.widget_factory_name = 'Factory Name'
6
+
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ class CreateBetauseraccessTables < ActiveRecord::Migration
2
+ def self.up
3
+ SCHEMA_AUTO_INSERTED_HERE
4
+ end
5
+
6
+ def self.down
7
+ drop_table :sign_up_for_beta_accesses
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+
3
+ create_table :sign_up_for_beta_accesses do |t|
4
+ t.string :name
5
+ t.string :twitterid
6
+ t.boolean :allowedaccess
7
+
8
+ t.timestamps
9
+ end
10
+
11
+ add_index :sign_up_for_beta_accesses, [:name]
12
+
13
+ end
@@ -0,0 +1,8 @@
1
+ namespace :betauseraccess do
2
+
3
+ desc "example gem rake task"
4
+ task :report => :environment do
5
+ puts "you just ran the example gem rake task"
6
+ end
7
+
8
+ end
Binary file
@@ -0,0 +1,9 @@
1
+ .betauseraccess {
2
+ color: red;
3
+ }
4
+
5
+ .red_border {
6
+ border: 2px solid red;
7
+ margin: 5px;
8
+ padding: 5px;
9
+ }
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: betauseraccess
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Your Name
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-05 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: you@email.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files:
19
+ - README.rdoc
20
+ files:
21
+ - app/controllers/betauseraccess/sign_up_for_beta_accesses_controller.rb
22
+ - app/helpers/application_helper.rb
23
+ - app/helpers/betauseraccess/widgets_helper.rb
24
+ - app/models/betauseraccess/sign_up_for_beta_access.rb
25
+ - app/views/betauseraccess/sign_up_for_beta_accesses/_form.html.erb
26
+ - app/views/betauseraccess/sign_up_for_beta_accesses/edit.html.erb
27
+ - app/views/betauseraccess/sign_up_for_beta_accesses/index.html.erb
28
+ - app/views/betauseraccess/sign_up_for_beta_accesses/new.html.erb
29
+ - app/views/betauseraccess/sign_up_for_beta_accesses/show.html.erb
30
+ - app/views/betauseraccess/sign_up_for_beta_accesses/thanks.html.erb
31
+ - app/views/layouts/betauseraccess.html.erb
32
+ - config/routes.rb
33
+ - lib/acts_as_widget/base.rb
34
+ - lib/application_controller.rb
35
+ - lib/application_helper.rb
36
+ - lib/betauseraccess.rb
37
+ - lib/engine.rb
38
+ - lib/rails/generators/betauseraccess/betauseraccess_generator.rb
39
+ - lib/rails/generators/betauseraccess/templates/initializer.rb
40
+ - lib/rails/generators/betauseraccess/templates/migration.rb
41
+ - lib/rails/generators/betauseraccess/templates/schema.rb
42
+ - lib/rails/railties/tasks.rake
43
+ - public/images/betauseraccess.jpg
44
+ - public/stylesheets/betauseraccess.css
45
+ - README.rdoc
46
+ homepage:
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.23
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Description of your gem
70
+ test_files: []