ixtlan-core 0.6.0 → 0.6.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.
Files changed (47) hide show
  1. data/README.md +64 -0
  2. data/features/headers.feature +12 -0
  3. data/features/step_definitions/simple_steps.rb +1 -0
  4. data/lib/ixtlan/core/active_record.rb +22 -0
  5. data/lib/ixtlan/core/active_record.rb~ +24 -0
  6. data/lib/ixtlan/core/controllers/configuration_controller.rb~ +9 -0
  7. data/lib/ixtlan/core/data_mapper.rb +23 -0
  8. data/lib/ixtlan/core/data_mapper.rb~ +18 -0
  9. data/lib/ixtlan/core/optimistic_active_record.rb~ +21 -0
  10. data/lib/ixtlan/core/{optimistic_data_mapper.rb → optimistic_data_mapper.rb~} +1 -1
  11. data/lib/ixtlan/core/railtie.rb +6 -6
  12. data/lib/ixtlan/core/x_content_headers.rb~ +32 -0
  13. data/lib/ixtlan/core/x_content_type_headers.rb~ +30 -0
  14. data/lib/ixtlan/core/x_xss_protection_headers.rb~ +30 -0
  15. data/spec/cache_headers_spec.rb~ +52 -0
  16. data/spec/configuration_manager_spec.rb~ +40 -0
  17. data/spec/controller.rb~ +8 -0
  18. data/spec/x_headers_spec.rb~ +74 -0
  19. metadata +24 -37
  20. data/lib/generators/ixtlan/base.rb +0 -45
  21. data/lib/generators/ixtlan/configuration_model/configuration_model_generator.rb +0 -12
  22. data/lib/generators/ixtlan/configuration_scaffold/configuration_scaffold_generator.rb +0 -12
  23. data/lib/generators/ixtlan/setup/setup_generator.rb +0 -38
  24. data/lib/generators/ixtlan/setup/templates/application_layout.html.erb +0 -17
  25. data/lib/generators/ixtlan/setup/templates/database.yml.example +0 -48
  26. data/lib/generators/ixtlan/setup/templates/error.html.erb +0 -1
  27. data/lib/generators/ixtlan/setup/templates/error_with_session.html.erb +0 -1
  28. data/lib/generators/ixtlan/setup/templates/gitignore +0 -2
  29. data/lib/generators/ixtlan/setup/templates/initializer.rb +0 -64
  30. data/lib/generators/ixtlan/setup/templates/preinitializer.rb +0 -31
  31. data/lib/generators/ixtlan/setup/templates/production.yml.example +0 -8
  32. data/lib/generators/ixtlan/setup/templates/stale.html.erb +0 -2
  33. data/lib/generators/model/model_generator.rb +0 -12
  34. data/lib/generators/rails/active_record/active_record_generator.rb +0 -40
  35. data/lib/generators/rails/active_record/model/migration.rb +0 -19
  36. data/lib/generators/rails/active_record/model/model.rb +0 -16
  37. data/lib/generators/rails/erb/erb_generator.rb +0 -37
  38. data/lib/generators/rails/erb/scaffold/_form.html.erb +0 -28
  39. data/lib/generators/rails/erb/scaffold/edit.html.erb +0 -24
  40. data/lib/generators/rails/erb/scaffold/index.html.erb +0 -49
  41. data/lib/generators/rails/erb/scaffold/new.html.erb +0 -11
  42. data/lib/generators/rails/erb/scaffold/show.html.erb +0 -30
  43. data/lib/generators/rails/scaffold_controller/scaffold_controller/controller.rb +0 -129
  44. data/lib/generators/rails/scaffold_controller/scaffold_controller/singleton_controller.rb +0 -43
  45. data/lib/generators/scaffold/scaffold_generator.rb +0 -35
  46. data/lib/generators/scaffold_controller/scaffold_controller_generator.rb +0 -34
  47. data/lib/ixtlan/core/optimistic_active_record.rb +0 -18
@@ -1,31 +0,0 @@
1
- require 'yaml'
2
- require 'erb'
3
- module Ixtlan
4
- class Configurator
5
-
6
- def self.symbolize_keys(h)
7
- result = {}
8
-
9
- h.each do |k, v|
10
- v = ' ' if v.nil?
11
- if v.is_a?(Hash)
12
- result[k.to_sym] = symbolize_keys(v) unless v.size == 0
13
- else
14
- result[k.to_sym] = v unless k.to_sym == v.to_sym
15
- end
16
- end
17
-
18
- result
19
- end
20
-
21
- def self.load(file)
22
- if File.exists?(file)
23
- symbolize_keys(YAML::load(ERB.new(IO.read(file)).result))
24
- else
25
- warn "no file #{file} to load - maybe the is a #{file}.example"
26
- end
27
- end
28
- end
29
- end
30
-
31
- CONFIG = Ixtlan::Configurator.load(File.join(File.dirname(__FILE__), 'production.yml')) || {}
@@ -1,8 +0,0 @@
1
- db:
2
- database: production
3
- username: worker
4
- password: behappy
5
- smtp:
6
- host: mail.example.com
7
- username: mailworker
8
- password: secret
@@ -1,2 +0,0 @@
1
- <h1>stale resource</h1>
2
- <p>please reload resource and change it again</p>
@@ -1,12 +0,0 @@
1
- module Rails
2
- module Generators
3
- class ModelGenerator < NamedBase #metagenerator
4
- argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
5
- hook_for :orm, :required => true
6
-
7
- if defined? Resty
8
- hook_for :resty, :type => :boolean, :default => true
9
- end
10
- end
11
- end
12
- end
@@ -1,40 +0,0 @@
1
- require 'rails/generators/active_record'
2
-
3
- module ActiveRecord
4
- module Generators
5
- class ModelGenerator < Base
6
- include ::Ixtlan::Core::Singleton
7
-
8
- argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
9
-
10
- check_class_collision
11
-
12
- class_option :migration, :type => :boolean
13
- class_option :timestamps, :type => :boolean
14
- class_option :parent, :type => :string, :desc => "The parent class for the generated model"
15
-
16
- def create_migration_file
17
- return unless options[:migration] && options[:parent].nil?
18
- migration_template "migration.rb", "db/migrate/create_#{table_name}.rb"
19
- end
20
-
21
- def create_model_file
22
- template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
23
- end
24
-
25
- def create_module_file
26
- return if class_path.empty?
27
- template 'module.rb', File.join('app/models', "#{class_path.join('/')}.rb") if behavior == :invoke
28
- end
29
-
30
- hook_for :test_framework
31
-
32
- protected
33
-
34
- def parent_class_name
35
- options[:parent] || "ActiveRecord::Base"
36
- end
37
-
38
- end
39
- end
40
- end
@@ -1,19 +0,0 @@
1
- class <%= migration_class_name %> < ActiveRecord::Migration
2
- def self.up
3
- create_table :<%= table_name %> do |t|
4
- <% attributes.select {|attr| ![:has_one, :has_many].include?(attr.type) }.each do |attribute| -%>
5
- t.<%= attribute.type %> :<%= attribute.name %>
6
- <% end -%>
7
- <% if options[:timestamps] %>
8
- t.timestamps
9
- <% end -%>
10
- <% if options[:modified_by] %>
11
- t.references :modified_by
12
- <% end -%>
13
- end
14
- end
15
-
16
- def self.down
17
- drop_table :<%= table_name %>
18
- end
19
- end
@@ -1,16 +0,0 @@
1
- class <%= class_name %> < <%= parent_class_name.classify %>
2
- <% attributes.select {|attr| attr.reference? }.each do |attribute| -%>
3
- belongs_to :<%= attribute.name %>
4
- <% end -%>
5
- <% attributes.select {|attr| [:has_one, :has_many].include?(attr.type) }.each do |attribute| -%>
6
- <%= attribute.type %> :<%= attribute.name %>
7
- <% end -%>
8
- <% if options[:modified_by] -%>
9
- belongs_to :modified_by, :class_name => "<%= options[:user_model] %>"
10
- <% end -%>
11
- <% if options[:singleton] -%>
12
- def self.instance
13
- self.first || self.new
14
- end
15
- <% end -%>
16
- end
@@ -1,37 +0,0 @@
1
- require 'rails/generators/erb'
2
- require 'rails/generators/resource_helpers'
3
-
4
- module Erb
5
- module Generators
6
- class ScaffoldGenerator < Base
7
- include Rails::Generators::ResourceHelpers
8
-
9
- class_option :optimistic, :type => :boolean, :default => false
10
- class_option :singleton, :type => :boolean, :default => false
11
- class_option :timestamps, :type => :boolean, :default => true
12
-
13
- argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
14
-
15
- def create_root_folder
16
- empty_directory File.join("app/views", controller_file_path)
17
- end
18
-
19
- def copy_view_files
20
- available_views.each do |view|
21
- filename = filename_with_extensions(view)
22
- template filename, File.join("app/views", controller_file_path, filename)
23
- end
24
- end
25
-
26
- protected
27
-
28
- def available_views
29
- if options[:singleton]
30
- %w(edit show _form)
31
- else
32
- %w(index edit show new _form)
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,28 +0,0 @@
1
- <%%= form_for(@<%= singular_table_name %><% if options[:singleton] -%>
2
- , :url => <%= singular_table_name %>_path, :html => { :method => :put, :class => "edit_<%= singular_table_name %>", :id => "edit_<%= singular_table_name %>"}<% end -%>
3
- ) do |f| %>
4
- <%% if @<%= singular_table_name %>.errors.any? %>
5
- <div id="error_explanation">
6
- <h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
7
-
8
- <ul>
9
- <%% @<%= singular_table_name %>.errors.full_messages.each do |msg| %>
10
- <li><%%= msg %></li>
11
- <%% end %>
12
- </ul>
13
- </div>
14
- <%% end %>
15
-
16
- <% for attribute in attributes -%>
17
- <div class="field"><!-- begin - <%= attribute.name %> -->
18
- <%%= f.label :<%= attribute.name %> %><br />
19
- <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
20
- </div><!-- end - <%= attribute.name %> -->
21
- <% end -%>
22
- <div class="actions">
23
- <% if options[:optimistic] && options[:timestamps] -%>
24
- <%%= f.hidden_field :updated_at %>
25
- <% end -%>
26
- <%%= f.submit %>
27
- </div>
28
- <%% end %>
@@ -1,24 +0,0 @@
1
- <h1>Editing <%= singular_table_name %></h1>
2
-
3
- <%%= render 'form' %>
4
-
5
- <% if defined? ::Ixtlan::Guard -%>
6
- <%% if allowed?(:<%= table_name %>, :show) %>
7
- <% end -%>
8
- <% if options[:singleton] -%>
9
- <%%= link_to 'Show', <%= singular_table_name %>_path %>
10
- <% else -%>
11
- <%%= link_to 'Show', @<%= singular_table_name %> %>
12
- <% end -%>
13
- <% if defined? ::Ixtlan::Guard -%>
14
- <%% end %>
15
- <% end -%>
16
- <% unless options[:singleton] -%>
17
- <% if defined? ::Ixtlan::Guard -%>
18
- <%% if allowed?(:<%= table_name %>, :index) %>
19
- <% end -%>
20
- | <%%= link_to 'Back', <%= index_helper %>_path %>
21
- <% if defined? ::Ixtlan::Guard -%>
22
- <%% end %>
23
- <% end -%>
24
- <% end -%>
@@ -1,49 +0,0 @@
1
- <h1>Listing <%= plural_table_name %></h1>
2
-
3
- <table>
4
- <tr>
5
- <% for attribute in attributes -%>
6
- <th><%= attribute.human_name %></th>
7
- <% end -%>
8
- <th></th>
9
- <th></th>
10
- <th></th>
11
- </tr>
12
-
13
- <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
14
- <tr>
15
- <% for attribute in attributes -%>
16
- <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
17
- <% end -%>
18
- <% if defined? ::Ixtlan::Guard -%>
19
- <%% if allowed?(:<%= table_name %>, :show) %>
20
- <% end -%>
21
- <td><%%= link_to 'Show', <%= singular_table_name %> %></td>
22
- <% if defined? ::Ixtlan::Guard -%>
23
- <%% end %>
24
- <%% if allowed?(:<%= table_name %>, :update) %>
25
- <% end -%>
26
- <td><%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>) %></td>
27
- <% if defined? ::Ixtlan::Guard -%>
28
- <%% end %>
29
- <%% if allowed?(:<%= table_name %>, :destroy) %>
30
- <% end -%>
31
- <td><% if options[:optimistic] && options[:timestamps] -%>
32
- <%%= link_to 'Destroy', <%= singular_table_name %>_path(<%= singular_table_name %>) + "?<%= singular_table_name %>[updated_at]=#{<%= singular_table_name %>.updated_at.utc.strftime('%Y-%m-%d %H:%M:%S') + ("%06d" % <%= singular_table_name %>.updated_at.utc)}", :confirm => 'Are you sure?', :method => :delete %><% else -%><%%= link_to 'Destroy', <%= singular_table_name %>, :confirm => 'Are you sure?', :method => :delete %>
33
- <% end -%></td>
34
- <% if defined? ::Ixtlan::Guard -%>
35
- <%% end %>
36
- <% end -%>
37
- </tr>
38
- <%% end %>
39
- </table>
40
-
41
- <br />
42
-
43
- <% if defined? ::Ixtlan::Guard -%>
44
- <%% if allowed?(:<%= table_name %>, :create) %>
45
- <% end -%>
46
- <%%= link_to 'New <%= human_name %>', new_<%= singular_table_name %>_path %>
47
- <% if defined? ::Ixtlan::Guard -%>
48
- <%% end %>
49
- <% end -%>
@@ -1,11 +0,0 @@
1
- <h1>New <%= singular_table_name %></h1>
2
-
3
- <%%= render 'form' %>
4
-
5
- <% if defined? ::Ixtlan::Guard -%>
6
- <%% if allowed?(:<%= table_name %>, :index) %>
7
- <% end -%>
8
- <%%= link_to 'Back', <%= index_helper %>_path %>
9
- <% if defined? ::Ixtlan::Guard -%>
10
- <%% end %>
11
- <% end -%>
@@ -1,30 +0,0 @@
1
- <p id="notice"><%%= notice %></p>
2
-
3
- <% for attribute in attributes -%>
4
- <p>
5
- <b><%= attribute.human_name %>:</b>
6
- <%%= @<%= singular_table_name %>.<%= attribute.name %> %>
7
- </p>
8
-
9
- <% end -%>
10
-
11
- <% if defined? ::Ixtlan::Guard -%>
12
- <%% if allowed?(:<%= table_name %>, :update) %>
13
- <% end -%>
14
- <% if options[:singleton] -%>
15
- <%%= link_to 'Edit', edit_<%= singular_table_name %>_path %>
16
- <% else -%>
17
- <%%= link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>) %>
18
- <% end -%>
19
- <% if defined? ::Ixtlan::Guard -%>
20
- <%% end %>
21
- <% end -%>
22
- <% unless options[:singleton] -%>
23
- <% if defined? ::Ixtlan::Guard -%>
24
- <%% if allowed?(:<%= table_name %>, :index) %>
25
- <% end -%>
26
- | <%%= link_to 'Back', <%= index_helper %>_path %>
27
- <% if defined? ::Ixtlan::Guard -%>
28
- <%% end %>
29
- <% end -%>
30
- <% end -%>
@@ -1,129 +0,0 @@
1
- class <%= controller_class_name %>Controller < ApplicationController
2
- # GET <%= route_url %>
3
- # GET <%= route_url %>.xml
4
- # GET <%= route_url %>.json
5
- def index
6
- @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
7
-
8
- respond_to do |format|
9
- format.html # index.html.erb
10
- format.xml { render :xml => @<%= plural_table_name %> }
11
- format.json { render :json => @<%= plural_table_name %> }
12
- end
13
- end
14
-
15
- # GET <%= route_url %>/1
16
- # GET <%= route_url %>/1.xml
17
- # GET <%= route_url %>/1.json
18
- def show
19
- @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
20
-
21
- respond_to do |format|
22
- format.html # show.html.erb
23
- format.xml { render :xml => @<%= singular_table_name %> }
24
- format.json { render :json => @<%= singular_table_name %> }
25
- end
26
- end
27
-
28
- # GET <%= route_url %>/new
29
- def new
30
- @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
31
- end
32
-
33
- # GET <%= route_url %>/1/edit
34
- def edit
35
- @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
36
- end
37
-
38
- # POST <%= route_url %>
39
- # POST <%= route_url %>.xml
40
- # POST <%= route_url %>.json
41
- def create
42
- @<%= singular_table_name %> = <%= orm_class.build(class_name, "params[:#{singular_table_name}]") %>
43
- <% if options[:modified_by] -%>
44
- @<%= singular_table_name %>.current_user = current_user
45
- <% end -%>
46
-
47
- respond_to do |format|
48
- if @<%= orm_instance.save %>
49
- format.html { redirect_to(@<%= singular_table_name %>, :notice => '<%= human_name %> was successfully created.') }
50
- format.xml { render :xml => @<%= singular_table_name %>, :status => :created, :location => @<%= singular_table_name %> }
51
- format.json { render :json => @<%= singular_table_name %>, :status => :created, :location => @<%= singular_table_name %> }
52
- else
53
- format.html { render :action => "new" }
54
- format.xml { render :xml => @<%= orm_instance.errors %>, :status => :unprocessable_entity }
55
- format.json { render :json => @<%= orm_instance.errors %>, :status => :unprocessable_entity }
56
- end
57
- end
58
- end
59
-
60
- # PUT <%= route_url %>/1
61
- # PUT <%= route_url %>/1.xml
62
- # PUT <%= route_url %>/1.json
63
- def update
64
- <% if options[:optimistic] && options[:timestamps] -%>
65
- @<%= singular_table_name %> = <%= orm_class.find(class_name, "(params[:#{singular_table_name}]||[]).delete(:updated_at), params[:id]").sub(/\.(get|find)/, '.optimistic_\1') %>
66
-
67
- if @<%= singular_table_name %>.nil?
68
- @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
69
- respond_to do |format|
70
- format.html { render :action => "edit" }
71
- format.xml { render :xml => nil, :status => :conflict }
72
- format.json { render :json => nil, :status => :conflict }
73
- end
74
- return
75
- end
76
- <% else -%>
77
- @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
78
- (params[:<%= singular_table_name %>]||[]).delete(:updated_at)
79
- <% end -%>
80
- (params[:<%= singular_table_name %>]||[]).delete(:id)
81
- <% if options[:modified_by] -%>
82
- @<%= singular_table_name %>.current_user = current_user
83
- <% end -%>
84
-
85
- respond_to do |format|
86
- if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %>
87
- format.html { redirect_to(@<%= singular_table_name %>, :notice => '<%= human_name %> was successfully updated.') }
88
- format.xml { render :xml => @<%= singular_table_name %> }
89
- format.json { render :json => @<%= singular_table_name %> }
90
- else
91
- format.html { render :action => "edit" }
92
- format.xml { render :xml => @<%= orm_instance.errors %>, :status => :unprocessable_entity }
93
- format.json { render :json => @<%= orm_instance.errors %>, :status => :unprocessable_entity }
94
- end
95
- end
96
- end
97
-
98
- # DELETE <%= route_url %>/1
99
- # DELETE <%= route_url %>/1.xml
100
- # DELETE <%= route_url %>/1.json
101
- def destroy
102
- <% if options[:optimistic] && options[:timestamps] -%>
103
- @<%= singular_table_name %> = <%= orm_class.find(class_name, "(params[:#{singular_table_name}]||[]).delete(:updated_at), params[:id]").sub(/\.(get|find)/, '.optimistic_\1') %>
104
-
105
- if @<%= singular_table_name %>.nil?
106
- @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
107
- respond_to do |format|
108
- format.html { render :action => "edit" }
109
- format.xml { render :xml => nil, :status => :conflict }
110
- format.json { render :json => nil, :status => :conflict }
111
- end
112
- return
113
- end
114
- <% else -%>
115
- @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
116
- <% end -%>
117
- <% if options[:modified_by] -%>
118
- @<%= singular_table_name %>.current_user = current_user
119
- <% end -%>
120
-
121
- @<%= orm_instance.destroy %>
122
-
123
- respond_to do |format|
124
- format.html { redirect_to(<%= index_helper %>_url) }
125
- format.xml { head :ok }
126
- format.json { head :ok }
127
- end
128
- end
129
- end