c2 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ %script{ :'data-template' => 'entryIndex', :type => 'text/js-template' }
2
+ .header
3
+ %h1
4
+ %span.type <%= entries.parent.index_label() %>
5
+ %strong <%= entries.locus().escape('label') %>
6
+ .toolbar
7
+ .body
8
+ #items
9
+ %ul.block-list.entries
10
+ <% entries.each(function(entry) { %>
11
+ %li.entry.item
12
+ %h3
13
+ :plain
14
+ <a href="<%= entry.hash_path() %>/edit" class="title" title="edit “<%= entry.label() %>”"><%= entry.label() %></a>
15
+ <% if (entry.get('updated_at')) { %>
16
+ %dl.meta
17
+ %dt.date Updated
18
+ %dd.date
19
+ :plain
20
+ <abbr class="timeago" title="<%= entry.get('updated_at') %>"><%= entry.get('updated_at') %></abbr>
21
+ <% } %>
22
+ <% }); %>
@@ -0,0 +1,7 @@
1
+ %script{ :'data-template' => 'entryIndexAside', :type => 'text/js-template' }
2
+ %aside.call-to-action.new-entry
3
+ .body
4
+ :plain
5
+ <a class="button" href="<%= entries.newPath() %>">
6
+ <strong>Add a new entry</strong>
7
+ </a>
@@ -0,0 +1,30 @@
1
+ %script{ :'data-template' => 'sidebar', :type => 'text/js-template' }
2
+ %nav#sitemap.sitemap
3
+ .header
4
+ %h3= link_to('Locus of Control', '#/')
5
+ .body.tree
6
+ <% collection.each(function(locus) { %>
7
+ %ul
8
+ %li.item.section
9
+ .label{ :'data-depth' => 1 }
10
+ %a.section{ :href => '#' }
11
+ %span <%= locus.escape('label') %>
12
+ %ul
13
+ %li.item.entries
14
+ .label{ :'data-depth' => 2 }
15
+ :plain
16
+ <a href="<%= locus.entries_path() %>" class="entries">
17
+ <em class="count"><%= locus.escape('count') %></em>
18
+ <span>Entries</span>
19
+ </a>
20
+
21
+ <% locus.buckets.each(function(bucket) { %>
22
+ %li.item.bucket
23
+ .label{ :'data-depth' => 2 }
24
+ :plain
25
+ <a href="<%= bucket.entries_path() %>" class="bucket">
26
+ <em class="count"><%= bucket.escape('count') %></em>
27
+ <span><%= bucket.escape('label') %></span>
28
+ </a>
29
+ <% }); %>
30
+ <% }); %>
@@ -0,0 +1,30 @@
1
+ .content
2
+ .header
3
+ %h1
4
+ %span.type Home
5
+ %strong Overview
6
+ .body
7
+
8
+ = content_for :back do
9
+ .content
10
+ .header
11
+ %h1
12
+ %span.type Editing
13
+ %strong Overview
14
+ .body
15
+ %form#entry
16
+
17
+ = content_for :sidebar do
18
+ %nav#sitemap.sitemap
19
+ .header
20
+ %h3.current= link_to('Loading ...', '#')
21
+
22
+
23
+ = content_for :head do
24
+ :javascript
25
+ Sexy.script('/javascripts/c2/informant/init.js');
26
+
27
+ = content_for :templates do
28
+ = render 'entry_index'
29
+ = render 'entry_index_aside'
30
+ = render 'sidebar'
@@ -0,0 +1,56 @@
1
+ !!!
2
+ %head
3
+ %title= params[:controller].split('/').map(&:titleize).join(' ')
4
+ = csrf_meta_tag
5
+
6
+ %link{ :rel => 'stylesheet', :href => '/stylesheets/compiled/c2.css', :type => 'text/css', :media => 'screen', :charset => 'utf-8' }
7
+ %script{:src => '/javascripts/c2/lib/Sexy.min.js', :type => 'text/javascript'}
8
+
9
+ = yield :head
10
+
11
+ %body.pictos-icons
12
+ #templates
13
+ = yield :templates
14
+ #wrapper
15
+ #header-wrapper
16
+ %header#header
17
+ %h1= link_to('Command & Control', '#')
18
+ %h2=# link_to('Version 0.0.1', '#', :class => 'preview')
19
+ .url= link_to('Control Yourself!', '#', :class => 'external-link')
20
+ %ul.links
21
+ %li
22
+ %strong#user-name.dropdown-trigger= current_c2_agent_title
23
+ %ul.dropdown.menu
24
+ %li= link_to('My profile', '#')
25
+ %li= link_to('My account', '#')
26
+ %li= link_to('Log out', '#')
27
+ %li= link_to('Help & Feedback', '#', :id => 'support-link')
28
+ %li= link_to('Flip', '#', :class => 'back flip-trigger')
29
+
30
+ %nav
31
+ %ul
32
+ %li.informant.current.tab= link_to('Informant', c2_informant_app_path)
33
+ %li.reports.tab= link_to('Reporter', '#')
34
+
35
+ #main-wrapper
36
+ #sidebar-wrapper
37
+ #sidebar
38
+ = yield :sidebar
39
+ #main-content
40
+ #notices
41
+ = yield :notices
42
+ #app-wrapper
43
+ #app
44
+ #app-front.sheet
45
+ = yield
46
+ #app-back.sheet
47
+ = yield :back
48
+ #aside-wrapper
49
+ #aside
50
+ = yield :aside
51
+ #footer-wrapper
52
+ #footer
53
+ = yield :footer
54
+
55
+
56
+
@@ -0,0 +1,3 @@
1
+ ActiveSupport::Inflector.inflections do |inflect|
2
+ inflect.irregular 'locus', 'locus'
3
+ end
@@ -0,0 +1,21 @@
1
+ defaults: &defaults
2
+ host: localhost
3
+ autocreate_indexes: false
4
+ allow_dynamic_fields: true
5
+ include_root_in_json: false
6
+ parameterize_keys: true
7
+ persist_in_safe_mode: false
8
+ raise_not_found_error: true
9
+ reconnect_time: 3
10
+
11
+ development:
12
+ <<: *defaults
13
+ database: develop_control
14
+
15
+ test:
16
+ <<: *defaults
17
+ database: test_control
18
+
19
+ production:
20
+ <<: *defaults
21
+ database: command_control
@@ -0,0 +1,13 @@
1
+ Rails.application.routes.draw do |map|
2
+ namespace :c2 do
3
+ namespace :informant do
4
+ get '/', :to => 'app#show', :as => :app
5
+ resources :locus, :only => [:index, :create, :update] do
6
+ resources :entries
7
+ resources :buckets do
8
+ resources :entries
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ if defined?(Rails) && Rails::VERSION::MAJOR == 3
2
+ require 'c2/engine'
3
+ require 'c2/exceptions'
4
+ require 'c2/controller_additions'
5
+ end
@@ -0,0 +1,42 @@
1
+ module C2
2
+ module ControllerAdditions
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ base.helper_method :current_c2_agent, :current_c2_agent_title, :c2_login_path, :c2_profile_path, :c2_logout_path
6
+ end
7
+
8
+ def current_c2_agent
9
+ @current_c2_agent ||= current_user
10
+ end
11
+
12
+ def current_c2_agent_title
13
+ @current_c2_agent_title ||= current_c2_agent.send(([:c2_title, :title, :name, :email].map(&:to_s) & current_c2_agent.methods).first)
14
+ end
15
+
16
+ def c2_clearance?
17
+ current_c2_agent && current_c2_agent.admin?
18
+ end
19
+
20
+ def authorize_c2_agent
21
+ raise C2::AccessDenied unless c2_clearance?
22
+ end
23
+
24
+ def c2_login_path
25
+ '/'
26
+ end
27
+
28
+ def c2_profile_path
29
+ '/'
30
+ end
31
+
32
+ def c2_logout_path
33
+ '/'
34
+ end
35
+ end
36
+ end
37
+
38
+ if defined? ActionController
39
+ ActionController::Base.class_eval do
40
+ include C2::ControllerAdditions
41
+ end
42
+ end
@@ -0,0 +1,12 @@
1
+ module C2
2
+ class Engine < Rails::Engine
3
+
4
+ rake_tasks do
5
+ load 'c2/tasks.rake'
6
+ end
7
+
8
+ initializer "static assets" do |app|
9
+ app.middleware.use ::ActionDispatch::Static, "#{root}/public"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ module C2
2
+ class AccessDenied < StandardError
3
+ attr_reader :action, :subject
4
+ attr_writer :default_message
5
+
6
+ def initialize(message = nil, subject = nil)
7
+ @message = message
8
+ @subject = subject
9
+ @default_message = "You are not authorized to access this page."
10
+ end
11
+
12
+ def to_s
13
+ @message || @default_message
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,79 @@
1
+ namespace :c2 do
2
+ def get_mongoid_models
3
+ documents = []
4
+ Dir.glob("app/models/**/*.rb").sort.each do |file|
5
+ model_path = file[0..-4].split('/')[2..-1]
6
+ begin
7
+ klass = model_path.map(&:classify).join('::').constantize
8
+ if klass.ancestors.include?(Mongoid::Document) && !klass.embedded
9
+ documents << klass
10
+ end
11
+ rescue => e
12
+ # Just for non-mongoid objects that dont have the embedded
13
+ # attribute at the class level.
14
+ end
15
+ end
16
+ documents
17
+ end
18
+
19
+ def valid_scopes_for(document)
20
+ valid_scopes = document.scopes.select do |method, scope|
21
+ valid = case conditions = scope.conditions
22
+ when Hash
23
+ true
24
+ when Proc
25
+ true if conditions.arity == 0
26
+ else
27
+ false
28
+ end
29
+ valid || false
30
+ end
31
+ Hash[*valid_scopes.flatten]
32
+ end
33
+
34
+ def categorized_fields_for(document)
35
+ valid_fields = document.fields.map do |name, field|
36
+ tag = case field.type.name
37
+ when 'String', 'Object'
38
+ if field.options[:metadata]
39
+ nil
40
+ elsif name.to_s.ends_with?('_password')
41
+ [name.to_s, 'password']
42
+ else
43
+ [name.to_s, 'text']
44
+ end
45
+ when 'Boolean'
46
+ [name.to_s, 'checkbox']
47
+ else
48
+ nil
49
+ end
50
+ end
51
+ Hash[*valid_fields.compact.flatten]
52
+ end
53
+
54
+ desc 'List all mongoid models'
55
+ task :discover => :environment do
56
+ locus_list = get_mongoid_models.map do |document|
57
+ C2::Informant::Locus.find_or_create_by({ :class_name => document.name })
58
+ end
59
+ locus_list.each do |document|
60
+ puts document.label
61
+
62
+ puts ' > Scopes'
63
+ valid_scopes_for(document.klass).each do |method, scope|
64
+ puts " - #{method}"
65
+ document.buckets.find_or_create_by({ :method_name => method.to_s })
66
+ end
67
+
68
+ puts ' > Fields'
69
+ categorized_fields_for(document.klass).each do |name, tag|
70
+ puts " - #{name} as #{tag}"
71
+ unless document.elements.where({ :name => name }).first
72
+ document.elements.create({ :name => name, :tag => tag })
73
+ end
74
+ end
75
+ end
76
+
77
+ end
78
+
79
+ end
@@ -0,0 +1,16 @@
1
+ class C2::InstallGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../../../../', __FILE__)
3
+ desc "Configure your app to work with C2."
4
+
5
+ def cache_js
6
+ directory "public/javascripts/c2", "public/javascripts/c2"
7
+ end
8
+
9
+ def cache_css
10
+ copy_file "public/stylesheets/c2.css", "public/stylesheets/c2.css"
11
+ end
12
+
13
+ def cache_images
14
+ directory "public/images/c2", "public/images/c2"
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "C2" do
4
+ end
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'bundler'
5
+ require 'c2'
6
+
7
+ Bundler.require(:default, :test) if defined?(Bundler)
8
+
9
+ mongoid_file = File.join(File.dirname(__FILE__), "..", "config", "mongoid.yml")
10
+ @settings = YAML.load(ERB.new(File.new(mongoid_file).read).result)
11
+
12
+ Mongoid.configure do |config|
13
+ config.from_hash(@settings['test'])
14
+ end
15
+
16
+ RSpec.configure do |config|
17
+ config.include Devise::TestHelpers, :type => :controller
18
+ config.mock_with :rspec
19
+
20
+ config.after :suite do
21
+ Mongoid.master.collections.select do |collection|
22
+ collection.name !~ /system/
23
+ end.each(&:drop)
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: c2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - hexorx
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-15 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ type: :runtime
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ version: 3.0.0
35
+ name: rails
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ prerelease: false
39
+ type: :runtime
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - "="
44
+ - !ruby/object:Gem::Version
45
+ hash: 15424091
46
+ segments:
47
+ - 2
48
+ - 0
49
+ - 0
50
+ - rc
51
+ - 7
52
+ version: 2.0.0.rc.7
53
+ name: mongoid
54
+ version_requirements: *id002
55
+ - !ruby/object:Gem::Dependency
56
+ prerelease: false
57
+ type: :runtime
58
+ requirement: &id003 !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - "="
62
+ - !ruby/object:Gem::Version
63
+ hash: 23
64
+ segments:
65
+ - 1
66
+ - 2
67
+ - 4
68
+ version: 1.2.4
69
+ name: bson_ext
70
+ version_requirements: *id003
71
+ - !ruby/object:Gem::Dependency
72
+ prerelease: false
73
+ type: :runtime
74
+ requirement: &id004 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ hash: 3
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ name: haml
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ prerelease: false
87
+ type: :development
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ name: jeweler
98
+ version_requirements: *id005
99
+ - !ruby/object:Gem::Dependency
100
+ prerelease: false
101
+ type: :development
102
+ requirement: &id006 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ name: rspec
112
+ version_requirements: *id006
113
+ description: " C2 aspires to be a simple, drop in, Admin Portal + CMS for apps based on Rails 3 + Mongoid. "
114
+ email: hexorx@gmail.com
115
+ executables: []
116
+
117
+ extensions: []
118
+
119
+ extra_rdoc_files:
120
+ - LICENSE
121
+ - README.md
122
+ files:
123
+ - app/controllers/c2/base_controller.rb
124
+ - app/controllers/c2/informant/app_controller.rb
125
+ - app/controllers/c2/informant/buckets_controller.rb
126
+ - app/controllers/c2/informant/entries_controller.rb
127
+ - app/controllers/c2/informant/locus_controller.rb
128
+ - app/models/c2/informant/bucket.rb
129
+ - app/models/c2/informant/form_element.rb
130
+ - app/models/c2/informant/locus.rb
131
+ - app/stylesheets/c2.scss
132
+ - app/views/c2/informant/app/_entry_index.html.haml
133
+ - app/views/c2/informant/app/_entry_index_aside.html.haml
134
+ - app/views/c2/informant/app/_sidebar.html.haml
135
+ - app/views/c2/informant/app/show.html.haml
136
+ - app/views/layouts/c2.html.haml
137
+ - config/initializers/c2_inflections.rb
138
+ - config/mongoid.yml
139
+ - config/routes.rb
140
+ - lib/c2.rb
141
+ - lib/c2/controller_additions.rb
142
+ - lib/c2/engine.rb
143
+ - lib/c2/exceptions.rb
144
+ - lib/c2/tasks.rake
145
+ - lib/generators/c2/install_generator.rb
146
+ - LICENSE
147
+ - README.md
148
+ - spec/c2_spec.rb
149
+ - spec/spec_helper.rb
150
+ has_rdoc: true
151
+ homepage: http://github.com/hexorx/c2
152
+ licenses: []
153
+
154
+ post_install_message:
155
+ rdoc_options: []
156
+
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ hash: 3
165
+ segments:
166
+ - 0
167
+ version: "0"
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ hash: 3
174
+ segments:
175
+ - 0
176
+ version: "0"
177
+ requirements: []
178
+
179
+ rubyforge_project:
180
+ rubygems_version: 1.6.2
181
+ signing_key:
182
+ specification_version: 3
183
+ summary: Take control of your Rails 3 and Mongoid based site with the Comand & Control Admin Portal + CMS.
184
+ test_files:
185
+ - spec/c2_spec.rb
186
+ - spec/spec_helper.rb