danwrong-evil 0.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/CHANGELOG ADDED
@@ -0,0 +1 @@
1
+ v0.1 Initial release
data/Manifest ADDED
@@ -0,0 +1,22 @@
1
+ assets/config.ru
2
+ assets/evil.css
3
+ assets/evil.js
4
+ bin/evil
5
+ CHANGELOG
6
+ lib/evil/application.rb
7
+ lib/evil/models/config_pair.rb
8
+ lib/evil/models/plugin.rb
9
+ lib/evil/models/template.rb
10
+ lib/evil/models/whitelist.rb
11
+ lib/evil/models.rb
12
+ lib/evil/setup/db_tool.rb
13
+ lib/evil/setup/generator.rb
14
+ lib/evil/setup/migration.rb
15
+ lib/evil.rb
16
+ Rakefile
17
+ test/harness/config.ru
18
+ test/harness/evil.db
19
+ test/harness/public/javascripts/evil.js
20
+ test/harness/public/stylesheets/evil.css
21
+ test/harness/tmp/restart.txt
22
+ Manifest
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'echoe'
2
+
3
+ Echoe.new("evil") do |p|
4
+ p.author = "Dan Webb"
5
+ p.email = 'dan@danwebb.net'
6
+ p.summary = "A simple framework for creating sites from 3rd party data and services"
7
+ p.url = "http://www.evilmashups.com"
8
+ p.runtime_dependencies = ["sinatra", "activerecord",
9
+ "sqlite3-ruby", "clip", "haml"]
10
+ p.retain_gemspec = true
11
+ end
data/assets/config.ru ADDED
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'evil'
3
+
4
+ Evil.app_root = File.expand_path(File.dirname(__FILE__))
5
+
6
+ require 'evil/application'
7
+
8
+ run Sinatra::Application
data/assets/evil.css ADDED
@@ -0,0 +1,24 @@
1
+ body {
2
+ background: black;
3
+ color: white;
4
+ font-family: Monaco, Courier, fixed-width;
5
+ text-align: center;
6
+ }
7
+
8
+ #page {
9
+ width: 60%;
10
+ margin: 3em auto;
11
+ text-align: left;
12
+ background: #333;
13
+ }
14
+
15
+ #banner {
16
+ padding: 0.2em 1em;
17
+ }
18
+
19
+ #content {
20
+ margin: 0.5em;
21
+ padding: 0.5em;
22
+ background: #111;
23
+ }
24
+
data/assets/evil.js ADDED
File without changes
data/bin/evil ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'clip'
5
+ require 'evil'
6
+
7
+ options = Clip do |p|
8
+ end
9
+
10
+ command = options.remainder.first
11
+
12
+ case command
13
+ when "init"
14
+ path = options.remainder[1]
15
+ Evil::Setup::Generator.new(path).generate!
16
+ when "whitelist"
17
+ pattern = options.remainder[1]
18
+ path = options.remainder[2]
19
+ Evil::Setup::DbTool.new(path || Dir.pwd).whitelist pattern
20
+ when 'unwhitelist'
21
+ pattern = options.remainder[1]
22
+ path = options.remainder[2]
23
+ Evil::Setup::DbTool.new(path || Dir.pwd).remove_from_whitelist pattern
24
+ else
25
+ puts "Command not recognised...either init, whitelist or unwhitelist"
26
+ end
27
+
28
+
data/evil.gemspec ADDED
@@ -0,0 +1,48 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{evil}
5
+ s.version = "0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Dan Webb"]
9
+ s.date = %q{2009-03-18}
10
+ s.default_executable = %q{evil}
11
+ s.description = %q{A simple framework for creating sites from 3rd party data and services}
12
+ s.email = %q{dan@danwebb.net}
13
+ s.executables = ["evil"]
14
+ s.extra_rdoc_files = ["bin/evil", "CHANGELOG", "lib/evil/application.rb", "lib/evil/models/config_pair.rb", "lib/evil/models/plugin.rb", "lib/evil/models/template.rb", "lib/evil/models/whitelist.rb", "lib/evil/models.rb", "lib/evil/setup/db_tool.rb", "lib/evil/setup/generator.rb", "lib/evil/setup/migration.rb", "lib/evil.rb"]
15
+ s.files = ["assets/config.ru", "assets/evil.css", "assets/evil.js", "bin/evil", "CHANGELOG", "lib/evil/application.rb", "lib/evil/models/config_pair.rb", "lib/evil/models/plugin.rb", "lib/evil/models/template.rb", "lib/evil/models/whitelist.rb", "lib/evil/models.rb", "lib/evil/setup/db_tool.rb", "lib/evil/setup/generator.rb", "lib/evil/setup/migration.rb", "lib/evil.rb", "Rakefile", "test/harness/config.ru", "test/harness/evil.db", "test/harness/public/javascripts/evil.js", "test/harness/public/stylesheets/evil.css", "test/harness/tmp/restart.txt", "Manifest", "evil.gemspec"]
16
+ s.has_rdoc = true
17
+ s.homepage = %q{http://www.evilmashups.com}
18
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Evil", "--main", "README.textile"]
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{evil}
21
+ s.rubygems_version = %q{1.3.1}
22
+ s.summary = %q{A simple framework for creating sites from 3rd party data and services}
23
+
24
+ if s.respond_to? :specification_version then
25
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
+ s.specification_version = 2
27
+
28
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
29
+ s.add_runtime_dependency(%q<sinatra>, [">= 0"])
30
+ s.add_runtime_dependency(%q<activerecord>, [">= 0"])
31
+ s.add_runtime_dependency(%q<sqlite3-ruby>, [">= 0"])
32
+ s.add_runtime_dependency(%q<clip>, [">= 0"])
33
+ s.add_runtime_dependency(%q<haml>, [">= 0"])
34
+ else
35
+ s.add_dependency(%q<sinatra>, [">= 0"])
36
+ s.add_dependency(%q<activerecord>, [">= 0"])
37
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
38
+ s.add_dependency(%q<clip>, [">= 0"])
39
+ s.add_dependency(%q<haml>, [">= 0"])
40
+ end
41
+ else
42
+ s.add_dependency(%q<sinatra>, [">= 0"])
43
+ s.add_dependency(%q<activerecord>, [">= 0"])
44
+ s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
45
+ s.add_dependency(%q<clip>, [">= 0"])
46
+ s.add_dependency(%q<haml>, [">= 0"])
47
+ end
48
+ end
@@ -0,0 +1,21 @@
1
+ require 'sinatra'
2
+ require 'evil/models'
3
+
4
+ configure do
5
+ Sinatra.register Evil::Models
6
+
7
+ set :sessions => true,
8
+ :static => File.join(Evil.app_root, 'public'),
9
+ :views => File.join(Evil.gem_root, 'views'),
10
+ :haml => { :format => :html5 }
11
+
12
+ connect_to_database
13
+ end
14
+
15
+ include Evil::Models
16
+
17
+ get '/admin' do
18
+ @thing = Whitelist.find(:first).pattern
19
+ haml :index
20
+ end
21
+
@@ -0,0 +1,11 @@
1
+ module Evil
2
+
3
+ module Models
4
+
5
+ class ConfigPair < ActiveRecord::Base
6
+ set_table_name :evil_config_pairs
7
+ end
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,13 @@
1
+ module Evil
2
+
3
+ module Models
4
+
5
+ class Plugin < ActiveRecord::Base
6
+ set_table_name :evil_plugins
7
+
8
+ has_many :config_pairs
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,28 @@
1
+ module Evil
2
+
3
+ module Models
4
+
5
+ class Template < ActiveRecord::Base
6
+ set_table_name :evil_templates
7
+
8
+ validates_presence_of :route, :source
9
+ validates_uniqueness_of :route
10
+ validates_format_of :route, :with => /^((\/)|(((\/|\.):?[a-z0-9\_]+)+))$/
11
+
12
+ after_save :reload_template_routes
13
+ after_destroy :reload_template_routes
14
+
15
+ has_many :cached_pages
16
+
17
+ named_scope :in_order, :order => 'position ASC'
18
+
19
+ protected
20
+
21
+ def reload_template_routes
22
+ Evil::Routes.reload_template_routes
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,32 @@
1
+ module Evil
2
+
3
+ module Models
4
+
5
+ class Whitelist < ActiveRecord::Base
6
+ set_table_name :evil_whitelists
7
+
8
+ validates_presence_of :pattern
9
+
10
+ after_save :clear_pattern_cache
11
+ after_destroy :clear_pattern_cache
12
+
13
+ def self.add(pattern)
14
+ Whitelist.create! :pattern => pattern
15
+ end
16
+
17
+ def self.authorize(identity_url)
18
+ @@patterns ||= find(:all).collect { |t| Regexp.new "^#{t.pattern.gsub('*', '(.*)')}$" }
19
+ @@patterns.any? { |p| identity_url.gsub(/^http\:\/\//, '') =~ p }
20
+ end
21
+
22
+ protected
23
+
24
+ def clear_pattern_cache
25
+ @@patterns = nil
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,17 @@
1
+ require 'activerecord'
2
+ require 'evil/models/config_pair'
3
+ require 'evil/models/plugin'
4
+ require 'evil/models/template'
5
+ require 'evil/models/whitelist'
6
+
7
+ module Evil
8
+ module Models
9
+
10
+ def connect_to_database
11
+ ActiveRecord::Base.establish_connection :adapter => 'sqlite3',
12
+ :database => File.join(Evil.app_root, 'evil.db')
13
+ end
14
+
15
+ end
16
+ end
17
+
@@ -0,0 +1,25 @@
1
+ require 'evil/models'
2
+
3
+ module Evil
4
+ module Setup
5
+ class DbTool
6
+ include Evil::Models
7
+
8
+ def initialize(app_root)
9
+ ActiveRecord::Base.establish_connection :adapter => 'sqlite3',
10
+ :database => File.join(app_root, 'evil.db')
11
+ end
12
+
13
+ def whitelist(pattern)
14
+ puts "Adding #{pattern} to admin whitelist..."
15
+ Whitelist.create(:pattern => pattern)
16
+ end
17
+
18
+ def remove_from_whitelist(pattern)
19
+ puts "Removing #{pattern} to admin whitelist..."
20
+ Whitelist.find_by_pattern(pattern).destroy
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,60 @@
1
+ require 'fileutils'
2
+ require 'evil/models'
3
+ require 'evil/setup/migration'
4
+
5
+ module Evil
6
+ module Setup
7
+ class Generator
8
+ include FileUtils
9
+
10
+ ASSET_PATH = File.join(File.dirname(__FILE__), '..', '..', '..', 'assets')
11
+
12
+ DIR_LAYOUT = %w{
13
+ tmp
14
+ public/images
15
+ public/stylesheets
16
+ public/javascripts
17
+ }
18
+
19
+ ASSETS = [
20
+ ['evil.css', 'public/stylesheets/evil.css'],
21
+ ['evil.js', 'public/javascripts/evil.js'],
22
+ ['config.ru', 'config.ru']
23
+ ]
24
+
25
+ def initialize(path)
26
+ @path = path
27
+ end
28
+
29
+ def generate!
30
+ puts "Generating Evil application..."
31
+ create_dir_tree!
32
+ copy_assets!
33
+ puts "Initializing database..."
34
+ create_database!
35
+ end
36
+
37
+ def create_dir_tree!
38
+ DIR_LAYOUT.each do |dir|
39
+ mkdir_p "#{@path}/#{dir}"
40
+ end
41
+ end
42
+
43
+ def create_database!
44
+ ActiveRecord::Base.establish_connection :adapter => 'sqlite3',
45
+ :database => File.join(@path, 'evil.db')
46
+
47
+ ActiveRecord::Migration.extend Evil::Setup::Migration
48
+
49
+ ActiveRecord::Migration.create_evil_tables
50
+ end
51
+
52
+ def copy_assets!
53
+ ASSETS.each do |file, dest|
54
+ cp File.join(ASSET_PATH, file), File.join(@path, dest)
55
+ end
56
+ end
57
+
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,54 @@
1
+ require 'ar_openid_store'
2
+ require 'ar_openid_store/migration'
3
+
4
+ module Evil
5
+ module Setup
6
+ module Migration
7
+
8
+ def create_evil_tables
9
+ create_table :evil_templates do |t|
10
+ t.integer :ttl, :position
11
+ t.string :title, :route
12
+ t.text :source
13
+ t.timestamps
14
+ end unless Evil::Models::Template.table_exists?
15
+
16
+ create_table :evil_plugins do |t|
17
+ t.string :name, :description, :author
18
+ t.text :source, :url
19
+ t.boolean :enabled
20
+ t.timestamps
21
+ end unless Evil::Models::Plugin.table_exists?
22
+
23
+ unless Evil::Models::ConfigPair.table_exists?
24
+ create_table :evil_config_pairs do |t|
25
+ t.integer :plugin_id
26
+ t.string :key
27
+ t.text :value
28
+ t.timestamps
29
+ end
30
+
31
+ add_index :evil_config_pairs, :plugin_id
32
+ end
33
+
34
+ create_table :evil_whitelists do |t|
35
+ t.string :pattern
36
+ end unless Evil::Models::Whitelist.table_exists?
37
+
38
+ unless ArOpenidStore::Association.table_exists?
39
+ create_openid_tables
40
+ end
41
+ end
42
+
43
+ def destroy_evil_tables
44
+ drop_table :evil_templates
45
+ drop_table :evil_plugins
46
+ drop_table :evil_config_pairs
47
+ drop_openid_tables
48
+ end
49
+
50
+ end
51
+ end
52
+ end
53
+
54
+
data/lib/evil.rb ADDED
@@ -0,0 +1,15 @@
1
+ module Evil
2
+ module Setup
3
+ autoload :DbTool, 'evil/setup/db_tool'
4
+ autoload :Generator, 'evil/setup/generator'
5
+ autoload :Migration, 'evil/setup/migration'
6
+ end
7
+
8
+ autoload :Application, 'evil/application'
9
+
10
+ class << self
11
+ attr_accessor :gem_root, :app_root
12
+ end
13
+ end
14
+
15
+ Evil.gem_root = File.join(File.dirname(__FILE__), '..')
@@ -0,0 +1,9 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), '../../lib'))
2
+ require 'rubygems'
3
+ require 'evil'
4
+
5
+ Evil.app_root = File.expand_path(File.dirname(__FILE__))
6
+
7
+ require 'evil/application'
8
+
9
+ run Sinatra::Application
Binary file
File without changes
@@ -0,0 +1,24 @@
1
+ body {
2
+ background: black;
3
+ color: white;
4
+ font-family: Monaco, Courier, fixed-width;
5
+ text-align: center;
6
+ }
7
+
8
+ #page {
9
+ width: 60%;
10
+ margin: 3em auto;
11
+ text-align: left;
12
+ background: #333;
13
+ }
14
+
15
+ #banner {
16
+ padding: 0.2em 1em;
17
+ }
18
+
19
+ #content {
20
+ margin: 0.5em;
21
+ padding: 0.5em;
22
+ background: #111;
23
+ }
24
+
File without changes
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danwrong-evil
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Dan Webb
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-18 00:00:00 -07:00
13
+ default_executable: evil
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sinatra
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: activerecord
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: sqlite3-ruby
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: clip
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: haml
57
+ type: :runtime
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ description: A simple framework for creating sites from 3rd party data and services
66
+ email: dan@danwebb.net
67
+ executables:
68
+ - evil
69
+ extensions: []
70
+
71
+ extra_rdoc_files:
72
+ - bin/evil
73
+ - CHANGELOG
74
+ - lib/evil/application.rb
75
+ - lib/evil/models/config_pair.rb
76
+ - lib/evil/models/plugin.rb
77
+ - lib/evil/models/template.rb
78
+ - lib/evil/models/whitelist.rb
79
+ - lib/evil/models.rb
80
+ - lib/evil/setup/db_tool.rb
81
+ - lib/evil/setup/generator.rb
82
+ - lib/evil/setup/migration.rb
83
+ - lib/evil.rb
84
+ files:
85
+ - assets/config.ru
86
+ - assets/evil.css
87
+ - assets/evil.js
88
+ - bin/evil
89
+ - CHANGELOG
90
+ - lib/evil/application.rb
91
+ - lib/evil/models/config_pair.rb
92
+ - lib/evil/models/plugin.rb
93
+ - lib/evil/models/template.rb
94
+ - lib/evil/models/whitelist.rb
95
+ - lib/evil/models.rb
96
+ - lib/evil/setup/db_tool.rb
97
+ - lib/evil/setup/generator.rb
98
+ - lib/evil/setup/migration.rb
99
+ - lib/evil.rb
100
+ - Rakefile
101
+ - test/harness/config.ru
102
+ - test/harness/evil.db
103
+ - test/harness/public/javascripts/evil.js
104
+ - test/harness/public/stylesheets/evil.css
105
+ - test/harness/tmp/restart.txt
106
+ - Manifest
107
+ - evil.gemspec
108
+ has_rdoc: true
109
+ homepage: http://www.evilmashups.com
110
+ post_install_message:
111
+ rdoc_options:
112
+ - --line-numbers
113
+ - --inline-source
114
+ - --title
115
+ - Evil
116
+ - --main
117
+ - README.textile
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: "0"
125
+ version:
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: "1.2"
131
+ version:
132
+ requirements: []
133
+
134
+ rubyforge_project: evil
135
+ rubygems_version: 1.2.0
136
+ signing_key:
137
+ specification_version: 2
138
+ summary: A simple framework for creating sites from 3rd party data and services
139
+ test_files: []
140
+