reel_template 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4a3da30c5f5e211234f8ca91fedc32b98fd6b668
4
+ data.tar.gz: 943201d030eb8a7a20e40ff7fd74be34698593fa
5
+ SHA512:
6
+ metadata.gz: da247a5f43b544eb381d7b995eb12d949d35fbc905323cdd2e82c3f5e635e997c8bb9ee467c13cc06e7f86262837f9f16a1c79cdf6ff359727af564a2a26d9e4
7
+ data.tar.gz: b7dd3565d3acf6be572ea331115dcc2338099b44f4dc6106b6b6f7a0ee4b83d394c7cb14764e02435b0da09fbe2ccdf07b4025c4c9007f91639150749cbc44c7
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Kyle Dayton <kyle@grol.ly>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Reel/Webmachine Project Generator
2
+ This is a simple project generator based a "framework" I developed for another project.
3
+
4
+ # Usage
5
+ 1. Install the `reel-template` gem
6
+
7
+ ```shell
8
+ $ gem install reel-template
9
+ ```
10
+
11
+ 2. Use the `reel-generate` command to make a new project
12
+
13
+ ```shell
14
+ $ reel-generate my_new_app && cd my_new_app
15
+ ```
16
+
17
+ 3. Install Dependencies
18
+
19
+ ```shell
20
+ $ bundle
21
+ ```
22
+
23
+ 4. Start the App
24
+
25
+ ```shell
26
+ $ rake start
27
+ ```
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require './lib/reel_app_generator'
2
+
3
+ task :generate, :appname do |t, args|
4
+ raise "Must provide an app name" unless args[:appname]
5
+
6
+ ReelAppGenerator.new(args[:appname]).generate!
7
+ end
data/bin/reel-generate ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'reel_template'
4
+
5
+ app_name = ARGV[0]
6
+
7
+ raise "You must provide an application name!\nUsage: reel-generate <app name>\n" unless app_name
8
+
9
+ ReelTemplate.new(app_name, Dir.getwd).generate!
@@ -0,0 +1,3 @@
1
+ module ReelTemplate
2
+ VERSION = %w(0 0 1).join('.')
3
+ end
@@ -0,0 +1,62 @@
1
+ require 'erb'
2
+ require 'active_support'
3
+
4
+ class ReelTemplate
5
+ include ActiveSupport::Inflector
6
+
7
+ def initialize(app_name, directory)
8
+ @app_name = app_name
9
+ @app_module = camelize(app_name)
10
+ @app_const = app_name.upcase
11
+ @directory = directory
12
+
13
+ @generator_root = File.expand_path("../../", __FILE__)
14
+ end
15
+
16
+ def generate!
17
+ create_output_dir!
18
+ configure_template!
19
+ end
20
+
21
+ private
22
+
23
+ def output_dir
24
+ "#{@directory}/#{app_name}"
25
+ end
26
+
27
+ def create_output_dir!
28
+ FileUtils.mkdir(output_dir) unless Dir.exist?(output_dir)
29
+ end
30
+
31
+ def template_directory
32
+ "#{@generator_root}/template/"
33
+ end
34
+
35
+ def configure_template!
36
+ Dir["#{template_directory}/**/*.erb"].each do |file|
37
+ configure_file! file
38
+ end
39
+ end
40
+
41
+ def configure_file!(file_path)
42
+ puts "Processing: #{file_path}"
43
+ file = File.open(file_path, 'r')
44
+
45
+ contents = file.read
46
+ @output = ""
47
+
48
+ ERB.new(contents, nil, nil, "@output").result binding
49
+
50
+ file_path = "#{output_dir}/#{@file_name}"
51
+ FileUtils.mkdir_p(File.dirname(file_path)) unless Dir.exist?(File.dirname(file_path))
52
+
53
+ File.open(file_path, 'w') do |f|
54
+ f.puts @output
55
+ end
56
+
57
+ file.close
58
+ end
59
+
60
+ end
61
+
62
+
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "reel_template/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "reel_template"
7
+ s.version = ReelTemplate::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Kyle Dayton"]
10
+ s.email = ["kyle@grol.ly"]
11
+ s.homepage = "http://github.com/kyledayton/reel-template"
12
+ s.summary = %q{A project generator for Reel/Webmachine apps}
13
+ s.description = s.summary
14
+
15
+ s.add_runtime_dependency "launchy"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,28 @@
1
+ <%
2
+ @file_name = "Gemfile"
3
+ %>
4
+
5
+ source 'https://rubygems.org'
6
+
7
+ gem 'reel'
8
+ gem 'webmachine'
9
+ gem 'settingslogic'
10
+ gem 'multi_json'
11
+ gem 'oj', platforms: :ruby
12
+ gem 'json-jruby', platforms: :jruby
13
+ gem 'hashie'
14
+ gem 'mongo_mapper', git: "https://github.com/mongomapper/mongomapper.git"
15
+ gem 'bson_ext', platforms: :ruby
16
+
17
+ group :development do
18
+ gem 'yard'
19
+ gem 'pry'
20
+ end
21
+
22
+ group :test do
23
+ gem 'rspec'
24
+ gem 'simplecov', require: false
25
+ gem 'webmachine-test'
26
+ gem 'factory_girl'
27
+ gem 'database_cleaner'
28
+ end
@@ -0,0 +1,12 @@
1
+ <%
2
+ @file_name = "README.md"
3
+ %>
4
+
5
+ # <%= @app_name %>
6
+
7
+ TODO: Write a description
8
+
9
+ # Running the Server
10
+
11
+ 1. Run `bundle` to install dependencies
12
+ 2. Run `rake start` to start the server
@@ -0,0 +1,10 @@
1
+ <%
2
+ @file_name = "Rakefile"
3
+ %>
4
+
5
+ $: << File.expand_path("./lib")
6
+
7
+ task :start do
8
+ require '<%= @app_name %>'
9
+ <%= @app_module %>::Server.new.start!
10
+ end
@@ -0,0 +1,10 @@
1
+ <%
2
+ @file_name = "config/development.yml"
3
+ %>
4
+
5
+ base_url: "http://localhost:3000"
6
+ server:
7
+ host: "localhost"
8
+ port: 3000
9
+ database:
10
+ uri: "mongodb://localhost/<%= @app_name %>"
@@ -0,0 +1,8 @@
1
+ <%
2
+ @file_name = "config/locale/en.yml"
3
+ %>
4
+
5
+ en:
6
+ <%= @app_name %>:
7
+ not_found: "The requested %{model} was not found."
8
+ invalid: "The %{model} parameters were invalid."
@@ -0,0 +1,10 @@
1
+ <%
2
+ @file_name = "config/production.yml"
3
+ %>
4
+
5
+ base_url: "http://api.myapp.tld/"
6
+ server:
7
+ host: "localhost"
8
+ port: 3000
9
+ database:
10
+ uri: "mongodb://mongodbservice.com/<%= @app_name %>"
@@ -0,0 +1,9 @@
1
+ <%
2
+ @file_name = "config/test.yml"
3
+ %>
4
+
5
+ server:
6
+ host: "localhost"
7
+ port: 3000
8
+ database:
9
+ uri: "mongodb://localhost/<%= @app_name %>"
@@ -0,0 +1,28 @@
1
+ <%
2
+ @file_name = "lib/#{@app_name}.rb"
3
+ %>
4
+
5
+ require 'rubygems'
6
+ require 'bundler'; Bundler.require
7
+
8
+ require 'reel'
9
+ require 'webmachine'
10
+ require 'multi_json'
11
+ require 'mongo_mapper'
12
+
13
+ require '<%= @app_name %>/core'
14
+
15
+ module <%= @app_module %>
16
+ include Core
17
+
18
+ <%= @app_const %>_ROOT = File.expand_path("../../", __FILE__).freeze
19
+
20
+ require '<%= @app_name %>/config'
21
+ require '<%= @app_name %>/translation'
22
+ require '<%= @app_name %>/models'
23
+ require '<%= @app_name %>/response'
24
+ require '<%= @app_name %>/commands'
25
+ require '<%= @app_name %>/endpoints'
26
+ require '<%= @app_name %>/server'
27
+
28
+ end
@@ -0,0 +1,52 @@
1
+ <%
2
+ @file_name = "lib/#{@app_name}/commands/base.rb"
3
+ %>
4
+
5
+ module <%= @app_module %>
6
+ module Commands
7
+
8
+ # The base class for all <%= @app_name %> commands
9
+ class Command
10
+ include Translation
11
+
12
+ attr_reader :params
13
+
14
+ # Commands receive a params map containing the URL params, along with params
15
+ # received from parsing the request body
16
+ def initialize(params)
17
+ @params = params
18
+ end
19
+
20
+ # Called when commands are executed.
21
+ # Command is expected to return an instance of {<%= @app_module %>::Response},
22
+ # usually either a Success or Failure.
23
+ def execute
24
+ raise NotImplementedError
25
+ end
26
+
27
+ protected
28
+
29
+ # Returns a {<%= @app_module %>::Success} response
30
+ def success(*args)
31
+ <%= @app_module %>::Success.new(*args)
32
+ end
33
+
34
+ # Returns a {<%= @app_module %>::Failure} response
35
+ def failure(*args)
36
+ <%= @app_module %>::Failure.new(*args)
37
+ end
38
+
39
+ # Returns a Failure with 422 (Unprocessable Entity) response code
40
+ def invalid(object, message = nil)
41
+ failure object, (message || "Invalid"), 422
42
+ end
43
+
44
+ # Returns a Failure with 404 (Not Found) response code
45
+ def not_found(object, message = nil)
46
+ failure object, (message || "Not Found"), 404
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,17 @@
1
+ <%
2
+ @file_name = "lib/#{@app_name}/commands/test.rb"
3
+ %>
4
+
5
+ module <%= @app_module %>
6
+ module Commands
7
+
8
+ class Test < Command
9
+
10
+ def execute
11
+ success nil, "Test Command completed successfully"
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ <%
2
+ @file_name = "lib/#{@app_name}/commands.rb"
3
+ %>
4
+
5
+ module <%= @app_module %>
6
+ module Commands
7
+
8
+ require '<%= @app_name %>/commands/base'
9
+
10
+ # REQUIRE YOUR COMMMANDS HERE
11
+ require '<%= @app_name %>/commands/test'
12
+
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ <%
2
+ @file_name = "lib/#{@app_name}/config.rb"
3
+ %>
4
+ require 'settingslogic'
5
+
6
+ module <%= @app_module %>
7
+ # Provides access to configuration settings located in "config/CURRENT_ENVIRONMENT.yml" file
8
+ class Config < Settingslogic
9
+
10
+ source "#{<%= @app_module %>.root_dir}/config/#{<%= @app_module %>.env}.yml"
11
+ load!
12
+
13
+ end
14
+ end
@@ -0,0 +1,43 @@
1
+ <%
2
+ @file_name = "lib/#{@app_name}/core.rb"
3
+ %>
4
+
5
+ module <%= @app_module %>
6
+ module Core
7
+
8
+ def self.included(base)
9
+ base.extend(ClassMethods)
10
+ end
11
+
12
+ module ClassMethods
13
+
14
+ # Calculates the root directory of the server installation
15
+ # @return [String] The absolute path to the server's root directory
16
+ def root_dir
17
+ <%= @app_const %>_ROOT
18
+ end
19
+
20
+ # Determines the current environment from the system ENV variable. Defaults to development
21
+ # @return [String] The current application environment
22
+ def env
23
+ @current_env ||= get_env_from_system || "development"
24
+ end
25
+
26
+ # Attempts to return an environment from a list of known ENV variable names.
27
+ # @return [String,nil] The first located environment, otherwise nil
28
+ def get_env_from_system # :nodoc:
29
+ %w(ENV RACK_ENV RAILS_ENV).each do |env|
30
+ return ENV[env] if ENV[env] != nil
31
+ end
32
+
33
+ nil
34
+ end
35
+
36
+ def config
37
+ <%= @app_module %>::Config
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,75 @@
1
+ <%
2
+ @file_name = "lib/#{@app_name}/endpoints/base.rb"
3
+ %>
4
+ require 'hashie/mash'
5
+
6
+ module <%= @app_module %>::Endpoints
7
+
8
+ class Endpoint < Webmachine::Resource
9
+
10
+ # Returns the result of the endpoint as a JSON string during GET requests
11
+ # @return [String] the JSON result of this endpoint
12
+ def to_json
13
+ raise NotImplementedError
14
+ end
15
+
16
+ # Handles incoming JSON data during POST/PUT requests
17
+ def from_json
18
+ raise NotImplementedError
19
+ end
20
+
21
+ # Returns the routing path to this resource
22
+ # @return [Array] the router path for this resource
23
+ def self.path
24
+ raise NotImplementedError
25
+ end
26
+
27
+ def send_response!(api_resp)
28
+ response.code = api_resp.status_code
29
+ response.body = api_resp.to_json
30
+ end
31
+
32
+ # @private
33
+ def content_types_provided
34
+ [["application/json", :to_json]]
35
+ end
36
+
37
+ # @private
38
+ def content_types_accepted
39
+ [["application/json", :from_json]]
40
+ end
41
+
42
+ # Retrieves request parameters from body and URL
43
+ # @return [Hashie::Mash] All available request paramaters
44
+ def params
45
+ @params ||= Hashie::Mash.new( combined_params )
46
+ end
47
+
48
+ def current_user
49
+ @current_user || nil
50
+ end
51
+
52
+ private
53
+
54
+ # Retrieves all parameters from request body, URL segments and URL query string
55
+ # and combines them into one params hash
56
+ # @return [Hash] Parameters from JSON request body, matched URL segments and query string
57
+ # @private
58
+ def combined_params
59
+ params_from_body.merge(request.path_info).merge(request.query)
60
+ end
61
+
62
+ # Attempts to load and parse params from JSON encoded request body
63
+ # @return [Hash] The parsed parameters, or an empty hash if the body couldn't be parsed
64
+ # @private
65
+ def params_from_body
66
+ begin
67
+ MultiJson.load(request.body.to_s)
68
+ rescue Exception
69
+ Hash.new
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ end
@@ -0,0 +1,39 @@
1
+ <%
2
+ @file_name = "lib/#{@app_name}/endpoints/registry.rb"
3
+ %>
4
+
5
+ module <%= @app_module %>
6
+ module Endpoints
7
+ module Registry
8
+
9
+ def self.included(base)
10
+ base.extend(ClassMethods)
11
+ end
12
+
13
+ module ClassMethods
14
+
15
+ @@registry = Array.new
16
+
17
+ # Registers an endpoint
18
+ # @param [Endpoint] endpoint the endpoint to register
19
+ # @raise [ArgumentError] if endpoint does not inherit from +<%= @app_module %>::Endpoints::Endpoint+
20
+ # @return [nil]
21
+ def register(endpoint)
22
+ if endpoint.ancestors.include? Endpoint
23
+ @@registry << endpoint
24
+ return nil
25
+ else
26
+ raise ArgumentError.new("endpoint must inherit from <%= @app_module %>::Endpoints::Endpoint")
27
+ end
28
+ end
29
+
30
+ # Gets all registered endpoints
31
+ # @return [Array(Endpoint)] the registered endpoints
32
+ def all
33
+ @@registry
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,27 @@
1
+ <%
2
+ @file_name = "lib/#{@app_name}/endpoints/test_endpoint.rb"
3
+ %>
4
+
5
+ module <%= @app_module %>
6
+ module Endpoints
7
+
8
+ class TestEndpoint < Endpoint
9
+
10
+ def allowed_methods
11
+ %w(GET)
12
+ end
13
+
14
+ def self.path
15
+ ["test"]
16
+ end
17
+
18
+ def to_json
19
+ test = <%= @app_module %>::Commands::Test.new(params)
20
+ send_response! test.execute
21
+ end
22
+ end
23
+
24
+ end
25
+ end
26
+
27
+ <%= @app_module %>::Endpoints.register <%= @app_module %>::Endpoints::TestEndpoint
@@ -0,0 +1,18 @@
1
+ <%
2
+ @file_name = "lib/#{@app_name}/endpoints.rb"
3
+ %>
4
+
5
+ require '<%= @app_name %>/endpoints/registry'
6
+
7
+ module <%= @app_module %>
8
+ module Endpoints
9
+ include Registry
10
+
11
+ require '<%= @app_name %>/endpoints/base'
12
+ require '<%= @app_name %>/support/authentication'
13
+
14
+ # REQUIRE YOUR ENDPOINTS HERE
15
+ require '<%= @app_name %>/endpoints/test_endpoint'
16
+
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ <%
2
+ @file_name = "lib/#{@app_name}/models/test.rb"
3
+ %>
4
+
5
+ module <%= @app_module %>
6
+ module Models
7
+
8
+ class Test
9
+ include MongoMapper::Document
10
+ include SerializableAttributes
11
+
12
+ set_collection_name 'test'
13
+
14
+ key :test_field, String
15
+
16
+ serialize_attributes :id, :test_field
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ <%
2
+ @file_name = "lib/#{@app_name}/models.rb"
3
+ %>
4
+
5
+ module <%= @app_module %>
6
+ module Models
7
+
8
+ MongoMapper.setup({<%= @app_module %>.env => <%= @app_module %>.config.database}, <%= @app_module %>.env)
9
+
10
+ require '<%= @app_name %>/support/serializable_attributes'
11
+
12
+ # REQUIRE YOUR MODELS HERE
13
+ # require '<%= @app_name %>/models/user'
14
+
15
+ end
16
+ end
@@ -0,0 +1,69 @@
1
+ <%
2
+ @file_name = "lib/#{@app_name}/response.rb"
3
+ %>
4
+
5
+ module <%= @app_module %>
6
+
7
+ class Response
8
+
9
+ attr_reader :object, :message, :status_code
10
+
11
+ def initialize(object, message = nil, status = 200)
12
+ @object = object
13
+ @message = message
14
+ @status_code = status
15
+ end
16
+
17
+ def success?
18
+ raise NotImplementedError
19
+ end
20
+
21
+ def id
22
+ @object.try(:persisted?) ? @object.id : nil
23
+ end
24
+
25
+ def to_json
26
+ response = {
27
+ 'success' => success?
28
+ }
29
+
30
+ if success?
31
+ add_message_or_data(response)
32
+ else
33
+ add_errors(response)
34
+ end
35
+
36
+ response.to_json
37
+ end
38
+
39
+ def failure?; !success?; end
40
+
41
+ private
42
+
43
+ def add_message_or_data(hash)
44
+ if @message
45
+ hash['message'] = @message
46
+ elsif @object
47
+ hash['data'] = @object
48
+ end
49
+ end
50
+
51
+ def add_errors(hash)
52
+ hash['errors'] = @object.errors.full_messages if @object.try(:errors)
53
+ end
54
+
55
+ end
56
+
57
+ class Success < Response
58
+ def success?
59
+ true
60
+ end
61
+ end
62
+
63
+ class Failure < Response
64
+ def success?
65
+ false
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,55 @@
1
+ <%
2
+ @file_name = "lib/#{@app_name}/server.rb"
3
+ %>
4
+
5
+ module <%= @app_module %>
6
+ class Server
7
+
8
+ attr_reader :application
9
+
10
+ # Instantiates the server application
11
+ def initialize
12
+ @application = init_application
13
+ end
14
+
15
+ # Runs the server application
16
+ def start!
17
+ puts "#{self.class} started in #{<%= @app_module %>.env} mode on port #{<%= @app_module %>.config.server.port}"
18
+ @application.run
19
+ end
20
+
21
+ private
22
+
23
+ # Initializes a new Webmachine application
24
+ # @return [Webmachine::Application] the created application
25
+ def init_application
26
+ Webmachine::Application.new do |app|
27
+ init_routes(app)
28
+ init_config(app)
29
+ end
30
+ end
31
+
32
+ # Adds registered endpoints to +app+ routes
33
+ # @param [Webmachine::Application] app the application to add routes to
34
+ def init_routes(app)
35
+ app.routes do
36
+ # Add each registered endpoint to router
37
+ <%= @app_module %>::Endpoints.all.each do |ep|
38
+ add ep.path, ep
39
+ end
40
+ end
41
+ end
42
+
43
+ # Configures application settings using +<%= @app_module %>::Config+
44
+ # @param [Webmachine::Application] app the application to configure
45
+ def init_config(app)
46
+ app.configure do |config|
47
+ config.ip = <%= @app_module %>.config.server.host
48
+ config.port = <%= @app_module %>.config.server.port
49
+
50
+ config.adapter = :Reel
51
+ end
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,23 @@
1
+ <%
2
+ @file_name = "lib/#{@app_name}/support/authentication.rb"
3
+ %>
4
+
5
+ module <%= @app_module %>::Endpoints::Authentication
6
+
7
+ def self.included(base)
8
+ base.send(:include, Webmachine::Resource::Authentication)
9
+ base.send(:include, InstanceMethods) unless defined?($BITPLOYEE_TEST)
10
+ end
11
+
12
+ module InstanceMethods
13
+
14
+ def is_authorized?(auth_header = nil)
15
+ basic_auth(auth_header, "<%= @app_name %>") do |user, password|
16
+ # Authenticate with username/password
17
+ # Can also set @current_user
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,48 @@
1
+ <%
2
+ @file_name = "lib/#{@app_name}/support/serializable_attributes.rb"
3
+ %>
4
+
5
+ module SerializableAttributes
6
+
7
+ def self.included(base)
8
+ raise "SerializableAttributes must be included in a MongoMapper::Document
9
+ or MongoMapper::EmbeddedDocument" unless is_supported?(base)
10
+
11
+ # Unfortunately metaprogramming is the only way to make this work properly
12
+ base.class_eval """
13
+ @@serializable_attributes = nil
14
+
15
+ # Defines which attributes will be included in the JSON serialization
16
+ def self.serialize_attrs(*args)
17
+ @@serializable_attrs ||= Array.new
18
+ @@serializable_attrs += args.to_a
19
+ @@serializable_attrs.uniq!
20
+ nil
21
+ end
22
+
23
+ # Overrides the default serialization to only include defined attributes
24
+ # Transforms Timestamps into Integers
25
+ # See `serialize_attrs`
26
+ def serializable_hash(opts = {})
27
+ convert_timestamps super({only: @@serializable_attrs}.merge(opts))
28
+ end
29
+
30
+ private
31
+
32
+ def convert_timestamps(attr_hash = {})
33
+ attr_hash.each do |k,v|
34
+ attr_hash[k] = v.to_i if v.is_a? Time
35
+ end
36
+ end
37
+
38
+ """
39
+ end
40
+
41
+ private
42
+
43
+ def self.is_supported?(klass)
44
+ klass.ancestors.include?(MongoMapper::Document) ||
45
+ klass.ancestors.include?(MongoMapper::EmbeddedDocument)
46
+ end
47
+
48
+ end
@@ -0,0 +1,17 @@
1
+ <%
2
+ @file_name = "lib/#{@app_name}/translation.rb"
3
+ %>
4
+
5
+ require 'i18n'
6
+ I18n.enforce_available_locales = true
7
+ I18n.load_path << "#{<%= @app_module %>.root_dir}/config/locale/en.yml"
8
+
9
+ module <%= @app_module %>
10
+ module Translation
11
+
12
+ def t(key, opts = {})
13
+ ::I18n.t(key, opts.merge(scope: :<%= @app_name %>))
14
+ end
15
+
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reel_template
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kyle Dayton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: launchy
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A project generator for Reel/Webmachine apps
28
+ email:
29
+ - kyle@grol.ly
30
+ executables:
31
+ - reel-generate
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - bin/reel-generate
40
+ - lib/reel_template.rb
41
+ - lib/reel_template/version.rb
42
+ - reel_template.gemspec
43
+ - template/Gemfile.erb
44
+ - template/README.md.erb
45
+ - template/Rakefile.erb
46
+ - template/config/development.yml.erb
47
+ - template/config/locale/en.yml.erb
48
+ - template/config/production.yml.erb
49
+ - template/config/test.yml.erb
50
+ - template/lib/app.rb.erb
51
+ - template/lib/appname/commands.rb.erb
52
+ - template/lib/appname/commands/base.rb.erb
53
+ - template/lib/appname/commands/test.rb.erb
54
+ - template/lib/appname/config.rb.erb
55
+ - template/lib/appname/core.rb.erb
56
+ - template/lib/appname/endpoints.rb.erb
57
+ - template/lib/appname/endpoints/base.rb.erb
58
+ - template/lib/appname/endpoints/registry.rb.erb
59
+ - template/lib/appname/endpoints/test_endpoint.rb.erb
60
+ - template/lib/appname/models.rb.erb
61
+ - template/lib/appname/models/test.rb.erb
62
+ - template/lib/appname/response.rb.erb
63
+ - template/lib/appname/server.rb.erb
64
+ - template/lib/appname/support/authentication.rb.erb
65
+ - template/lib/appname/support/serializable_attributes.rb.erb
66
+ - template/lib/appname/translation.rb.erb
67
+ homepage: http://github.com/kyledayton/reel-template
68
+ licenses: []
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.2.2
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: A project generator for Reel/Webmachine apps
90
+ test_files: []
91
+ has_rdoc: