buzzard 0.1.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.
- data/.gitignore +2 -0
- data/LICENSE +28 -0
- data/Rakefile +19 -0
- data/TODO +1 -0
- data/VERSION +1 -0
- data/bin/buzzard +73 -0
- data/buzzard.gemspec +69 -0
- data/data/app.css.erb +8 -0
- data/data/app.js.erb +0 -0
- data/data/app.rb.erb +31 -0
- data/data/helpers.rb.erb +4 -0
- data/data/home.rb.erb +10 -0
- data/data/index.erb.erb +4 -0
- data/data/layout.erb.erb +12 -0
- data/data/server.rb.erb +6 -0
- data/data/test_func.rb.erb +20 -0
- data/lib/buzzard/dbi.rb +115 -0
- data/lib/buzzard/helpers.rb +7 -0
- data/lib/buzzard/json.rb +12 -0
- data/lib/buzzard/security.rb +74 -0
- data/lib/buzzard/session.rb +21 -0
- metadata +135 -0
    
        data/.gitignore
    ADDED
    
    
    
        data/LICENSE
    ADDED
    
    | @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            Copyright (c) 2010, Thomas Lee
         | 
| 2 | 
            +
            All rights reserved.
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            Redistribution and use in source and binary forms, with or without
         | 
| 5 | 
            +
            modification, are permitted provided that the following conditions are met:
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            1. Redistributions of source code must retain the above copyright
         | 
| 8 | 
            +
               notice, this list of conditions and the following disclaimer.
         | 
| 9 | 
            +
            2. Redistributions in binary form must reproduce the above copyright
         | 
| 10 | 
            +
               notice, this list of conditions and the following disclaimer in the
         | 
| 11 | 
            +
               documentation and/or other materials provided with the distribution.
         | 
| 12 | 
            +
            3. All advertising materials mentioning features or use of this software
         | 
| 13 | 
            +
               must display the following acknowledgement:
         | 
| 14 | 
            +
               This product includes software developed by the <organization>.
         | 
| 15 | 
            +
            4. Neither the name of the <organization> nor the
         | 
| 16 | 
            +
               names of its contributors may be used to endorse or promote products
         | 
| 17 | 
            +
               derived from this software without specific prior written permission.
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY
         | 
| 20 | 
            +
            EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
         | 
| 21 | 
            +
            WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
         | 
| 22 | 
            +
            DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
         | 
| 23 | 
            +
            DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
         | 
| 24 | 
            +
            (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
         | 
| 25 | 
            +
            LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
         | 
| 26 | 
            +
            ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
         | 
| 27 | 
            +
            (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
         | 
| 28 | 
            +
            SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            require 'rubygems'
         | 
| 2 | 
            +
            require 'jeweler'
         | 
| 3 | 
            +
            Jeweler::Tasks.new do |gemspec|
         | 
| 4 | 
            +
              gemspec.name = "buzzard"
         | 
| 5 | 
            +
              gemspec.summary = "Sane web app microframework built on Sinatra."
         | 
| 6 | 
            +
              gemspec.description = "Buzzard is a framework and application generator"
         | 
| 7 | 
            +
              gemspec.email = "buzzard@tomlee.co"
         | 
| 8 | 
            +
              gemspec.homepage = "http://github.com/thomaslee/buzzard"
         | 
| 9 | 
            +
              gemspec.authors = ["Thomas Lee"]
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              gemspec.add_dependency('dbi', '>= 0.4.4')
         | 
| 12 | 
            +
              gemspec.add_dependency('sinatra', '>= 1.1.0')
         | 
| 13 | 
            +
            #  gemspec.add_dependency('erubis', '>= 2.6.0')
         | 
| 14 | 
            +
              gemspec.add_dependency('rack-flash', '>= 0.1.1')
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              gemspec.rubyforge_project = gemspec.name
         | 
| 17 | 
            +
            end
         | 
| 18 | 
            +
            Jeweler::GemcutterTasks.new
         | 
| 19 | 
            +
             | 
    
        data/VERSION
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            0.1.1
         | 
    
        data/bin/buzzard
    ADDED
    
    | @@ -0,0 +1,73 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require "erb"
         | 
| 4 | 
            +
            require "fileutils"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            include FileUtils
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            BUZZARDDIR = File.dirname(__FILE__)
         | 
| 9 | 
            +
            TEMPLATEDIR = File.join(BUZZARDDIR, "..", "data")
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            def usage
         | 
| 12 | 
            +
              puts "usage: #{ARGV[0]} appname [ModuleName]"
         | 
| 13 | 
            +
              exit 1
         | 
| 14 | 
            +
            end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            def render_template(name, binding)
         | 
| 17 | 
            +
              ERB.new(File.open(File.join(TEMPLATEDIR, "#{name}.erb")) { |f| f.read }).result(binding)
         | 
| 18 | 
            +
            end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            def main
         | 
| 21 | 
            +
              appname = ARGV[0]
         | 
| 22 | 
            +
              modname = ARGV[1]
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              dirname = appname + ".git"
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              usage if appname.nil? || appname.empty?
         | 
| 27 | 
            +
              modname = appname.capitalize if modname.nil? || modname.empty?
         | 
| 28 | 
            +
              modname.gsub!(/[-_]([a-z])/) { |s| s.gsub(/[-_]/, "").upcase }
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              #
         | 
| 31 | 
            +
              # Build directory structure
         | 
| 32 | 
            +
              #
         | 
| 33 | 
            +
              ["app", "test", "views", "public/css", "public/js", "script"].each do |dir|
         | 
| 34 | 
            +
                path = File.join(dirname, dir)
         | 
| 35 | 
            +
                if !File.exists?(path)
         | 
| 36 | 
            +
                  mkdir_p path
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
              #
         | 
| 41 | 
            +
              # Generate skeleton files
         | 
| 42 | 
            +
              #
         | 
| 43 | 
            +
              [
         | 
| 44 | 
            +
                ["app.rb", "#{appname}.rb"],
         | 
| 45 | 
            +
                ["home.rb", "app/home.rb"],
         | 
| 46 | 
            +
                ["app.css", "public/css/style.css"],
         | 
| 47 | 
            +
                ["app.js", "public/js/#{appname}.js"],
         | 
| 48 | 
            +
                ["helpers.rb", "app/helpers.rb"],
         | 
| 49 | 
            +
                ["index.erb", "views/index.erb"],
         | 
| 50 | 
            +
                ["layout.erb", "views/layout.erb"],
         | 
| 51 | 
            +
                ["server.rb", "script/server"],
         | 
| 52 | 
            +
                ["test_func.rb", "test/functional.rb"]
         | 
| 53 | 
            +
              ].each do |source, target|
         | 
| 54 | 
            +
                target_path = File.join(dirname, target)
         | 
| 55 | 
            +
                if !File.exists?(target_path)
         | 
| 56 | 
            +
                  File.open(target_path, "w+b") do |stream|
         | 
| 57 | 
            +
                    stream.write(render_template(source, binding))
         | 
| 58 | 
            +
                  end
         | 
| 59 | 
            +
                else
         | 
| 60 | 
            +
                  STDERR.puts "WARN: #{target_path} already exists: skipping."
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
              #
         | 
| 65 | 
            +
              # Mark scripts as executable
         | 
| 66 | 
            +
              #
         | 
| 67 | 
            +
              Dir.glob(File.join(dirname, "script", "*")).each do |filename|
         | 
| 68 | 
            +
                chmod 0755, filename
         | 
| 69 | 
            +
              end
         | 
| 70 | 
            +
            end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
            main
         | 
| 73 | 
            +
             | 
    
        data/buzzard.gemspec
    ADDED
    
    | @@ -0,0 +1,69 @@ | |
| 1 | 
            +
            # Generated by jeweler
         | 
| 2 | 
            +
            # DO NOT EDIT THIS FILE DIRECTLY
         | 
| 3 | 
            +
            # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
         | 
| 4 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |s|
         | 
| 7 | 
            +
              s.name = %q{buzzard}
         | 
| 8 | 
            +
              s.version = "0.1.1"
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 11 | 
            +
              s.authors = ["Thomas Lee"]
         | 
| 12 | 
            +
              s.date = %q{2010-11-14}
         | 
| 13 | 
            +
              s.default_executable = %q{buzzard}
         | 
| 14 | 
            +
              s.description = %q{Buzzard is a framework and application generator}
         | 
| 15 | 
            +
              s.email = %q{buzzard@tomlee.co}
         | 
| 16 | 
            +
              s.executables = ["buzzard"]
         | 
| 17 | 
            +
              s.extra_rdoc_files = [
         | 
| 18 | 
            +
                "LICENSE",
         | 
| 19 | 
            +
                 "TODO"
         | 
| 20 | 
            +
              ]
         | 
| 21 | 
            +
              s.files = [
         | 
| 22 | 
            +
                ".gitignore",
         | 
| 23 | 
            +
                 "LICENSE",
         | 
| 24 | 
            +
                 "Rakefile",
         | 
| 25 | 
            +
                 "VERSION",
         | 
| 26 | 
            +
                 "bin/buzzard",
         | 
| 27 | 
            +
                 "buzzard.gemspec",
         | 
| 28 | 
            +
                 "data/app.css.erb",
         | 
| 29 | 
            +
                 "data/app.js.erb",
         | 
| 30 | 
            +
                 "data/app.rb.erb",
         | 
| 31 | 
            +
                 "data/helpers.rb.erb",
         | 
| 32 | 
            +
                 "data/home.rb.erb",
         | 
| 33 | 
            +
                 "data/index.erb.erb",
         | 
| 34 | 
            +
                 "data/layout.erb.erb",
         | 
| 35 | 
            +
                 "data/server.rb.erb",
         | 
| 36 | 
            +
                 "data/test_func.rb.erb",
         | 
| 37 | 
            +
                 "lib/buzzard/dbi.rb",
         | 
| 38 | 
            +
                 "lib/buzzard/helpers.rb",
         | 
| 39 | 
            +
                 "lib/buzzard/json.rb",
         | 
| 40 | 
            +
                 "lib/buzzard/security.rb",
         | 
| 41 | 
            +
                 "lib/buzzard/session.rb"
         | 
| 42 | 
            +
              ]
         | 
| 43 | 
            +
              s.homepage = %q{http://github.com/thomaslee/buzzard}
         | 
| 44 | 
            +
              s.rdoc_options = ["--charset=UTF-8"]
         | 
| 45 | 
            +
              s.require_paths = ["lib"]
         | 
| 46 | 
            +
              s.rubyforge_project = %q{buzzard}
         | 
| 47 | 
            +
              s.rubygems_version = %q{1.3.7}
         | 
| 48 | 
            +
              s.summary = %q{Sane web app microframework built on Sinatra.}
         | 
| 49 | 
            +
             | 
| 50 | 
            +
              if s.respond_to? :specification_version then
         | 
| 51 | 
            +
                current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
         | 
| 52 | 
            +
                s.specification_version = 3
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
         | 
| 55 | 
            +
                  s.add_runtime_dependency(%q<dbi>, [">= 0.4.4"])
         | 
| 56 | 
            +
                  s.add_runtime_dependency(%q<sinatra>, [">= 1.1.0"])
         | 
| 57 | 
            +
                  s.add_runtime_dependency(%q<rack-flash>, [">= 0.1.1"])
         | 
| 58 | 
            +
                else
         | 
| 59 | 
            +
                  s.add_dependency(%q<dbi>, [">= 0.4.4"])
         | 
| 60 | 
            +
                  s.add_dependency(%q<sinatra>, [">= 1.1.0"])
         | 
| 61 | 
            +
                  s.add_dependency(%q<rack-flash>, [">= 0.1.1"])
         | 
| 62 | 
            +
                end
         | 
| 63 | 
            +
              else
         | 
| 64 | 
            +
                s.add_dependency(%q<dbi>, [">= 0.4.4"])
         | 
| 65 | 
            +
                s.add_dependency(%q<sinatra>, [">= 1.1.0"])
         | 
| 66 | 
            +
                s.add_dependency(%q<rack-flash>, [">= 0.1.1"])
         | 
| 67 | 
            +
              end
         | 
| 68 | 
            +
            end
         | 
| 69 | 
            +
             | 
    
        data/data/app.css.erb
    ADDED
    
    
    
        data/data/app.js.erb
    ADDED
    
    | 
            File without changes
         | 
    
        data/data/app.rb.erb
    ADDED
    
    | @@ -0,0 +1,31 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'rubygems'
         | 
| 4 | 
            +
            require 'sinatra/base'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            require 'buzzard/dbi'
         | 
| 7 | 
            +
            require 'buzzard/helpers'
         | 
| 8 | 
            +
            require 'buzzard/json'
         | 
| 9 | 
            +
            require 'buzzard/session'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            require 'app/helpers'
         | 
| 12 | 
            +
            require 'app/home'
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            module <%= modname %>
         | 
| 15 | 
            +
              class Application < Sinatra::Base
         | 
| 16 | 
            +
                include Buzzard::Helpers
         | 
| 17 | 
            +
                include Buzzard::DBI
         | 
| 18 | 
            +
                include Buzzard::JSON
         | 
| 19 | 
            +
                include Buzzard::Session
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                set :public, 'public'
         | 
| 22 | 
            +
                set :dbi_dsn, "DBI:Mysql:<%= appname %>"
         | 
| 23 | 
            +
                set :dbi_username, "<%= appname %>"
         | 
| 24 | 
            +
                set :dbi_password, "<%= appname %>"
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                helpers App::Helpers
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                register App::Home
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
            end
         | 
| 31 | 
            +
             | 
    
        data/data/helpers.rb.erb
    ADDED
    
    
    
        data/data/home.rb.erb
    ADDED
    
    
    
        data/data/index.erb.erb
    ADDED
    
    
    
        data/data/layout.erb.erb
    ADDED
    
    | @@ -0,0 +1,12 @@ | |
| 1 | 
            +
            <!DOCTYPE html>
         | 
| 2 | 
            +
            <html>
         | 
| 3 | 
            +
              <head>
         | 
| 4 | 
            +
                <title><%= appname %> v1.0</title>
         | 
| 5 | 
            +
                <link rel="stylesheet" href="/css/style.css">
         | 
| 6 | 
            +
                <script type="text/javascript" src="/js/<%= appname %>.js"></script>
         | 
| 7 | 
            +
              </head>
         | 
| 8 | 
            +
              <body>
         | 
| 9 | 
            +
                <%= "<%= yield %" + ">" %>
         | 
| 10 | 
            +
              </body>
         | 
| 11 | 
            +
            </html>
         | 
| 12 | 
            +
             | 
    
        data/data/server.rb.erb
    ADDED
    
    
| @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            require "rubygems"
         | 
| 2 | 
            +
            require "<%= appname %>"
         | 
| 3 | 
            +
            require "test/unit"
         | 
| 4 | 
            +
            require "rack/test"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            module <%= modname %>
         | 
| 7 | 
            +
              class ApplicationTest < Test::Unit::TestCase
         | 
| 8 | 
            +
                include Rack::Test::Methods
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def app
         | 
| 11 | 
            +
                  <%= modname %>::Application
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def test_home_works
         | 
| 15 | 
            +
                  get "/"
         | 
| 16 | 
            +
                  assert last_response.ok?
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| 20 | 
            +
             | 
    
        data/lib/buzzard/dbi.rb
    ADDED
    
    | @@ -0,0 +1,115 @@ | |
| 1 | 
            +
            require 'dbi'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Buzzard
         | 
| 4 | 
            +
              module DBI
         | 
| 5 | 
            +
                def with_db(&block)
         | 
| 6 | 
            +
                  dsn = settings.dbi_dsn
         | 
| 7 | 
            +
                  username = settings.dbi_username
         | 
| 8 | 
            +
                  password = settings.dbi_password
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  dbh = ::DBI.connect(dsn, username, password)
         | 
| 11 | 
            +
                  begin
         | 
| 12 | 
            +
                    return yield Wrapper.new(self, dbh)
         | 
| 13 | 
            +
                  ensure
         | 
| 14 | 
            +
                    dbh.disconnect
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                def with_sql(sql, *params, &block)
         | 
| 19 | 
            +
                  with_db do |db|
         | 
| 20 | 
            +
                    db.all(sql, *params, &block)
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                class Wrapper
         | 
| 25 | 
            +
                  def initialize(app, dbh)
         | 
| 26 | 
            +
                    @app = app
         | 
| 27 | 
            +
                    @dbh = dbh
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  def one(sql, *params)
         | 
| 31 | 
            +
                    sth = @dbh.prepare(sql)
         | 
| 32 | 
            +
                    res = nil
         | 
| 33 | 
            +
                    begin
         | 
| 34 | 
            +
                      sth.execute(*params)
         | 
| 35 | 
            +
                      row = sth.fetch
         | 
| 36 | 
            +
                      res = row.shift if row
         | 
| 37 | 
            +
                    ensure
         | 
| 38 | 
            +
                      sth.finish
         | 
| 39 | 
            +
                    end
         | 
| 40 | 
            +
                    res
         | 
| 41 | 
            +
                  end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                  def row(sql, *params)
         | 
| 44 | 
            +
                    sth = @dbh.prepare(sql)
         | 
| 45 | 
            +
                    res = nil
         | 
| 46 | 
            +
                    begin
         | 
| 47 | 
            +
                      sth.execute(*params)
         | 
| 48 | 
            +
                      res = sth.fetch_hash
         | 
| 49 | 
            +
                    ensure
         | 
| 50 | 
            +
                      sth.finish
         | 
| 51 | 
            +
                    end
         | 
| 52 | 
            +
                    _maybe_normalize(res)
         | 
| 53 | 
            +
                  end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                  def all(sql, *params, &block)
         | 
| 56 | 
            +
                    sth = @dbh.prepare(sql)
         | 
| 57 | 
            +
                    res = []
         | 
| 58 | 
            +
                    begin
         | 
| 59 | 
            +
                      sth.execute(*params)
         | 
| 60 | 
            +
                      while row=sth.fetch_hash do
         | 
| 61 | 
            +
                        if block
         | 
| 62 | 
            +
                          yield _maybe_normalize(row)
         | 
| 63 | 
            +
                        else
         | 
| 64 | 
            +
                          res << row
         | 
| 65 | 
            +
                        end
         | 
| 66 | 
            +
                      end
         | 
| 67 | 
            +
                    ensure
         | 
| 68 | 
            +
                      sth.finish
         | 
| 69 | 
            +
                    end
         | 
| 70 | 
            +
                    _maybe_normalize_all(res)
         | 
| 71 | 
            +
                  end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                  def exec(sql, *params)
         | 
| 74 | 
            +
                    @dbh.do(sql, *params)
         | 
| 75 | 
            +
                  end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                  def _symbolic_keys?
         | 
| 78 | 
            +
                    if @app.settings.respond_to?(:dbi_symbolic_keys)
         | 
| 79 | 
            +
                      @app.settings.dbi_symbolic_keys 
         | 
| 80 | 
            +
                    else
         | 
| 81 | 
            +
                      true
         | 
| 82 | 
            +
                    end
         | 
| 83 | 
            +
                  end
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                  def _maybe_normalize(hash)
         | 
| 86 | 
            +
                    _symbolic_keys? ? _normalize(hash) : hash
         | 
| 87 | 
            +
                  end
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                  def _maybe_normalize_all(arr)
         | 
| 90 | 
            +
                    if _symbolic_keys?
         | 
| 91 | 
            +
                      r = []
         | 
| 92 | 
            +
                      arr.each_with_index do |hash, index|
         | 
| 93 | 
            +
                        r[index] = _normalize(hash)
         | 
| 94 | 
            +
                      end
         | 
| 95 | 
            +
                      r
         | 
| 96 | 
            +
                    else
         | 
| 97 | 
            +
                      arr
         | 
| 98 | 
            +
                    end
         | 
| 99 | 
            +
                  end
         | 
| 100 | 
            +
             | 
| 101 | 
            +
                  def _normalize(hash)
         | 
| 102 | 
            +
                    if !hash.nil? && hash.kind_of?(Hash)
         | 
| 103 | 
            +
                      r = {}
         | 
| 104 | 
            +
                      hash.each_pair do |key,value|
         | 
| 105 | 
            +
                        key = key.to_s if !key.kind_of?(Symbol)
         | 
| 106 | 
            +
                        key = key.to_sym if key.kind_of?(String)
         | 
| 107 | 
            +
                        r[key] = value
         | 
| 108 | 
            +
                      end
         | 
| 109 | 
            +
                      r
         | 
| 110 | 
            +
                    end
         | 
| 111 | 
            +
                  end
         | 
| 112 | 
            +
                end
         | 
| 113 | 
            +
              end
         | 
| 114 | 
            +
            end
         | 
| 115 | 
            +
             | 
    
        data/lib/buzzard/json.rb
    ADDED
    
    
| @@ -0,0 +1,74 @@ | |
| 1 | 
            +
            #
         | 
| 2 | 
            +
            # Simple security module providing login/logout
         | 
| 3 | 
            +
            #
         | 
| 4 | 
            +
            # Dependencies:
         | 
| 5 | 
            +
            #
         | 
| 6 | 
            +
            #   * Buzzard::Session
         | 
| 7 | 
            +
            #   * Buzzard::DBI (optional)
         | 
| 8 | 
            +
            #
         | 
| 9 | 
            +
            module Buzzard
         | 
| 10 | 
            +
              module Security
         | 
| 11 | 
            +
                module Extension
         | 
| 12 | 
            +
                  def self.registered(app)
         | 
| 13 | 
            +
                    app.get("/login") do
         | 
| 14 | 
            +
                      redirect "/" if logged_in?
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                      erb :login
         | 
| 17 | 
            +
                    end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                    app.post("/login") do
         | 
| 20 | 
            +
                      redirect "/" if logged_in?
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                      user = authenticate(params[:username], params[:password])
         | 
| 23 | 
            +
                      if !user.nil?
         | 
| 24 | 
            +
                        session[:user] = user
         | 
| 25 | 
            +
                        redirect post_auth_url
         | 
| 26 | 
            +
                      else
         | 
| 27 | 
            +
                        flash[:errors] = ["Invalid username or password"]
         | 
| 28 | 
            +
                        redirect "/login"
         | 
| 29 | 
            +
                      end
         | 
| 30 | 
            +
                    end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                    app.get("/logout") do
         | 
| 33 | 
            +
                      redirect "/" if !logged_in?
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                      session.delete(:user)
         | 
| 36 | 
            +
                      flash[:messages] = ["You have been logged out"]
         | 
| 37 | 
            +
                      redirect "/login"
         | 
| 38 | 
            +
                    end
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                def self.included(base)
         | 
| 43 | 
            +
                  base.register Extension
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                def current_user
         | 
| 47 | 
            +
                  session[:user]
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                def logged_in?
         | 
| 51 | 
            +
                  !session[:user].nil?
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                #
         | 
| 55 | 
            +
                # Default implementation of login. Assumes use of Sinatra::DBI.
         | 
| 56 | 
            +
                #
         | 
| 57 | 
            +
                def authenticate(username, password)
         | 
| 58 | 
            +
                  with_db do |db|
         | 
| 59 | 
            +
                    db.row("
         | 
| 60 | 
            +
                      SELECT * FROM users
         | 
| 61 | 
            +
                      WHERE
         | 
| 62 | 
            +
                        (username=? OR email=?) AND
         | 
| 63 | 
            +
                        password=SHA(?)
         | 
| 64 | 
            +
                    ", username, username, password)
         | 
| 65 | 
            +
                  end
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                #
         | 
| 69 | 
            +
                # The URL a user is sent to following a successful login.
         | 
| 70 | 
            +
                #
         | 
| 71 | 
            +
                def post_auth_url; "/"; end
         | 
| 72 | 
            +
              end
         | 
| 73 | 
            +
            end
         | 
| 74 | 
            +
             | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            require 'rack/flash'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Buzzard
         | 
| 4 | 
            +
              module Session
         | 
| 5 | 
            +
                module Extension
         | 
| 6 | 
            +
                  def self.registered(app)
         | 
| 7 | 
            +
                    app.enable :sessions
         | 
| 8 | 
            +
                    app.use Rack::Flash
         | 
| 9 | 
            +
                  end
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def self.included(base)
         | 
| 13 | 
            +
                  base.register Extension
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                def flash
         | 
| 17 | 
            +
                  env["x-rack.flash"]
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
            end
         | 
| 21 | 
            +
             | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,135 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification 
         | 
| 2 | 
            +
            name: buzzard
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            +
              hash: 25
         | 
| 5 | 
            +
              prerelease: false
         | 
| 6 | 
            +
              segments: 
         | 
| 7 | 
            +
              - 0
         | 
| 8 | 
            +
              - 1
         | 
| 9 | 
            +
              - 1
         | 
| 10 | 
            +
              version: 0.1.1
         | 
| 11 | 
            +
            platform: ruby
         | 
| 12 | 
            +
            authors: 
         | 
| 13 | 
            +
            - Thomas Lee
         | 
| 14 | 
            +
            autorequire: 
         | 
| 15 | 
            +
            bindir: bin
         | 
| 16 | 
            +
            cert_chain: []
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            date: 2010-11-14 00:00:00 +11:00
         | 
| 19 | 
            +
            default_executable: buzzard
         | 
| 20 | 
            +
            dependencies: 
         | 
| 21 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 22 | 
            +
              name: dbi
         | 
| 23 | 
            +
              prerelease: false
         | 
| 24 | 
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         | 
| 25 | 
            +
                none: false
         | 
| 26 | 
            +
                requirements: 
         | 
| 27 | 
            +
                - - ">="
         | 
| 28 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 29 | 
            +
                    hash: 7
         | 
| 30 | 
            +
                    segments: 
         | 
| 31 | 
            +
                    - 0
         | 
| 32 | 
            +
                    - 4
         | 
| 33 | 
            +
                    - 4
         | 
| 34 | 
            +
                    version: 0.4.4
         | 
| 35 | 
            +
              type: :runtime
         | 
| 36 | 
            +
              version_requirements: *id001
         | 
| 37 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 38 | 
            +
              name: sinatra
         | 
| 39 | 
            +
              prerelease: false
         | 
| 40 | 
            +
              requirement: &id002 !ruby/object:Gem::Requirement 
         | 
| 41 | 
            +
                none: false
         | 
| 42 | 
            +
                requirements: 
         | 
| 43 | 
            +
                - - ">="
         | 
| 44 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 45 | 
            +
                    hash: 19
         | 
| 46 | 
            +
                    segments: 
         | 
| 47 | 
            +
                    - 1
         | 
| 48 | 
            +
                    - 1
         | 
| 49 | 
            +
                    - 0
         | 
| 50 | 
            +
                    version: 1.1.0
         | 
| 51 | 
            +
              type: :runtime
         | 
| 52 | 
            +
              version_requirements: *id002
         | 
| 53 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 54 | 
            +
              name: rack-flash
         | 
| 55 | 
            +
              prerelease: false
         | 
| 56 | 
            +
              requirement: &id003 !ruby/object:Gem::Requirement 
         | 
| 57 | 
            +
                none: false
         | 
| 58 | 
            +
                requirements: 
         | 
| 59 | 
            +
                - - ">="
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 61 | 
            +
                    hash: 25
         | 
| 62 | 
            +
                    segments: 
         | 
| 63 | 
            +
                    - 0
         | 
| 64 | 
            +
                    - 1
         | 
| 65 | 
            +
                    - 1
         | 
| 66 | 
            +
                    version: 0.1.1
         | 
| 67 | 
            +
              type: :runtime
         | 
| 68 | 
            +
              version_requirements: *id003
         | 
| 69 | 
            +
            description: Buzzard is a framework and application generator
         | 
| 70 | 
            +
            email: buzzard@tomlee.co
         | 
| 71 | 
            +
            executables: 
         | 
| 72 | 
            +
            - buzzard
         | 
| 73 | 
            +
            extensions: []
         | 
| 74 | 
            +
             | 
| 75 | 
            +
            extra_rdoc_files: 
         | 
| 76 | 
            +
            - LICENSE
         | 
| 77 | 
            +
            - TODO
         | 
| 78 | 
            +
            files: 
         | 
| 79 | 
            +
            - .gitignore
         | 
| 80 | 
            +
            - LICENSE
         | 
| 81 | 
            +
            - Rakefile
         | 
| 82 | 
            +
            - VERSION
         | 
| 83 | 
            +
            - bin/buzzard
         | 
| 84 | 
            +
            - buzzard.gemspec
         | 
| 85 | 
            +
            - data/app.css.erb
         | 
| 86 | 
            +
            - data/app.js.erb
         | 
| 87 | 
            +
            - data/app.rb.erb
         | 
| 88 | 
            +
            - data/helpers.rb.erb
         | 
| 89 | 
            +
            - data/home.rb.erb
         | 
| 90 | 
            +
            - data/index.erb.erb
         | 
| 91 | 
            +
            - data/layout.erb.erb
         | 
| 92 | 
            +
            - data/server.rb.erb
         | 
| 93 | 
            +
            - data/test_func.rb.erb
         | 
| 94 | 
            +
            - lib/buzzard/dbi.rb
         | 
| 95 | 
            +
            - lib/buzzard/helpers.rb
         | 
| 96 | 
            +
            - lib/buzzard/json.rb
         | 
| 97 | 
            +
            - lib/buzzard/security.rb
         | 
| 98 | 
            +
            - lib/buzzard/session.rb
         | 
| 99 | 
            +
            - TODO
         | 
| 100 | 
            +
            has_rdoc: true
         | 
| 101 | 
            +
            homepage: http://github.com/thomaslee/buzzard
         | 
| 102 | 
            +
            licenses: []
         | 
| 103 | 
            +
             | 
| 104 | 
            +
            post_install_message: 
         | 
| 105 | 
            +
            rdoc_options: 
         | 
| 106 | 
            +
            - --charset=UTF-8
         | 
| 107 | 
            +
            require_paths: 
         | 
| 108 | 
            +
            - lib
         | 
| 109 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 110 | 
            +
              none: false
         | 
| 111 | 
            +
              requirements: 
         | 
| 112 | 
            +
              - - ">="
         | 
| 113 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 114 | 
            +
                  hash: 3
         | 
| 115 | 
            +
                  segments: 
         | 
| 116 | 
            +
                  - 0
         | 
| 117 | 
            +
                  version: "0"
         | 
| 118 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 119 | 
            +
              none: false
         | 
| 120 | 
            +
              requirements: 
         | 
| 121 | 
            +
              - - ">="
         | 
| 122 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 123 | 
            +
                  hash: 3
         | 
| 124 | 
            +
                  segments: 
         | 
| 125 | 
            +
                  - 0
         | 
| 126 | 
            +
                  version: "0"
         | 
| 127 | 
            +
            requirements: []
         | 
| 128 | 
            +
             | 
| 129 | 
            +
            rubyforge_project: buzzard
         | 
| 130 | 
            +
            rubygems_version: 1.3.7
         | 
| 131 | 
            +
            signing_key: 
         | 
| 132 | 
            +
            specification_version: 3
         | 
| 133 | 
            +
            summary: Sane web app microframework built on Sinatra.
         | 
| 134 | 
            +
            test_files: []
         | 
| 135 | 
            +
             |