dryink 0.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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 Jason Coene
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = DryInk
2
+
3
+ A simple DRY template engine assuming the conventions built on CanCan, Haml, Kaminari and SimpleForm.
4
+
5
+ Please see MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ require 'rake/rdoctask'
9
+
10
+ Rake::RDocTask.new(:rdoc) do |rdoc|
11
+ rdoc.rdoc_dir = 'rdoc'
12
+ rdoc.title = 'Dryink'
13
+ rdoc.options << '--line-numbers' << '--inline-source'
14
+ rdoc.rdoc_files.include('README.rdoc')
15
+ rdoc.rdoc_files.include('lib/**/*.rb')
16
+ end
17
+
18
+
@@ -0,0 +1,138 @@
1
+ module DryInk
2
+
3
+ class Base < ::ApplicationController
4
+
5
+ before_filter :discover_model
6
+ before_filter :instantiate_object, :only => [:show, :new, :create, :edit, :update, :destroy]
7
+
8
+ def discover_model
9
+ @model_class ||= Kernel.const_get(params[:controller].to_s.singularize.camelcase)
10
+ @model_singular ||= @model_class.to_s.humanize
11
+ @model_plural ||= @model_class.to_s.pluralize.humanize
12
+ @model_symbol_singular ||= @model_class.to_s.underscore.to_sym
13
+ @model_symbol_plural ||= @model_class.to_s.pluralize.underscore.to_sym
14
+ end
15
+
16
+ def child_of(classname)
17
+ @parent_class = Kernel.const_get(classname.to_s.camelcase)
18
+ @parent_key = "#{classname}_id".to_sym
19
+ @parent_object = @parent_class.find(params[@parent_key])
20
+ end
21
+
22
+ def field(name, options={})
23
+ @fields ||= Hash.new
24
+ @fields[name.to_sym] = options
25
+ @fields[name.to_sym][:label] ||= name.to_s.humanize
26
+ end
27
+
28
+ def index_path
29
+ @parent_object ? [@parent_object, @model_symbol_plural] : [@model_symbol_plural]
30
+ end
31
+
32
+ def page
33
+ params[:page] || 1
34
+ end
35
+
36
+ def per_page
37
+ 25
38
+ end
39
+
40
+ def new_object
41
+ if @parent_object
42
+ @parent_object.send(@model_symbol_plural).build
43
+ else
44
+ @model_class.new
45
+ end
46
+ end
47
+
48
+ def find_object
49
+ if @parent_object
50
+ @parent_object.send(@model_symbol_plural).find(params[:id])
51
+ else
52
+ @model_class.find(params[:id])
53
+ end
54
+ end
55
+
56
+ def find_objects
57
+ if @parent_object
58
+ @skip_pagination = true
59
+ @objects = @parent_object.send(@model_symbol_plural).all
60
+ else
61
+ @objects = @model_class.all.page(page).per(per_page)
62
+ end
63
+ end
64
+
65
+ def instantiate_object
66
+ current_model = params[:controller].to_s.singularize.camelize
67
+ current_action = params[:action].to_sym
68
+
69
+ case current_action
70
+ when :new, :create
71
+ authorize! current_action, @model_class
72
+ @object = new_object
73
+ @page_title = "New #{@model_singular}"
74
+ when :show, :edit, :update, :destroy
75
+ @object = find_object
76
+ @object_name = @object.respond_to?(:title) ? @object.title : @object.id
77
+ authorize! current_action, @object
78
+ @page_title = "#{@object_name} | #{@model_plural}"
79
+ else
80
+ @object = nil
81
+ end
82
+
83
+ end
84
+
85
+ # GET /model
86
+ def index
87
+ @objects = find_objects
88
+ @page_title = @model_plural
89
+ render 'dryink/template/index'
90
+ end
91
+
92
+ # GET /model/:id
93
+ def show
94
+ render 'dryink/template/show'
95
+ end
96
+
97
+ # GET /model/new
98
+ def new
99
+ render 'dryink/template/new'
100
+ end
101
+
102
+ # POST /model
103
+ def create
104
+ @object.attributes = params[@model_class.to_s.underscore.to_sym]
105
+ if @object.save
106
+ redirect_to index_path, :notice => "#{@model_singular} Created!"
107
+ else
108
+ render 'dryink/template/new'
109
+ end
110
+ end
111
+
112
+ # GET /model/:id/edit
113
+ def edit
114
+ render 'dryink/template/edit'
115
+ end
116
+
117
+ # PUT /model/:id
118
+ def update
119
+ if @object.update_attributes(params[@model_class.to_s.underscore.to_sym])
120
+ redirect_to index_path, :notice => "#{@model_singular} Updated!"
121
+ else
122
+ render 'dryink/template/edit'
123
+ end
124
+ end
125
+
126
+ # DELETE /model/:id
127
+ def destroy
128
+ if @object.destroy
129
+ flash[:notice] = "#{@model_singular} Deleted!"
130
+ else
131
+ flash[:alert] = "Unable to delete #{@model_singular}!"
132
+ end
133
+ redirect_to index_path
134
+ end
135
+
136
+ end
137
+
138
+ end
@@ -0,0 +1,8 @@
1
+ require 'dryink'
2
+ require 'rails'
3
+
4
+ module DryInk
5
+ class Engine < Rails::Engine
6
+ engine_name :dryink
7
+ end
8
+ end
data/lib/dryink.rb ADDED
@@ -0,0 +1,4 @@
1
+ module DryInk
2
+ require 'dryink/engine'
3
+ autoload :Base, 'dryink/base'
4
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dryink
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Jason Coene
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-05-16 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rails
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 3
30
+ - 1
31
+ - 0
32
+ - beta1
33
+ version: 3.1.0.beta1
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: cancan
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ segments:
45
+ - 1
46
+ - 6
47
+ - 4
48
+ version: 1.6.4
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: haml
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ segments:
60
+ - 3
61
+ - 0
62
+ - 25
63
+ version: 3.0.25
64
+ type: :runtime
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: kaminari
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
76
+ - 11
77
+ - 0
78
+ version: 0.11.0
79
+ type: :runtime
80
+ version_requirements: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ name: simple_form
83
+ prerelease: false
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ segments:
90
+ - 1
91
+ - 3
92
+ - 1
93
+ version: 1.3.1
94
+ type: :runtime
95
+ version_requirements: *id005
96
+ description: DRY controller and views for your simple models.
97
+ email:
98
+ - jcoene@gmail.com
99
+ executables: []
100
+
101
+ extensions: []
102
+
103
+ extra_rdoc_files: []
104
+
105
+ files:
106
+ - lib/dryink/base.rb
107
+ - lib/dryink/engine.rb
108
+ - lib/dryink.rb
109
+ - MIT-LICENSE
110
+ - Rakefile
111
+ - README.rdoc
112
+ has_rdoc: true
113
+ homepage: http://github.com/jcoene/dryink
114
+ licenses: []
115
+
116
+ post_install_message:
117
+ rdoc_options: []
118
+
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ segments:
135
+ - 0
136
+ version: "0"
137
+ requirements: []
138
+
139
+ rubyforge_project:
140
+ rubygems_version: 1.3.7
141
+ signing_key:
142
+ specification_version: 3
143
+ summary: DRY controller and views for your simple models.
144
+ test_files: []
145
+