optimizable 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
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,47 @@
1
+ = optimizable
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to optimizable
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Alex Mishyn.
18
+
19
+ === Usage:
20
+
21
+ <title><%= optimization(@page, :title)%></title>
22
+
23
+ <%=link_to 'Optimization', optimization_path_for(@page)%>
24
+
25
+ === Initialize:
26
+
27
+ Optimizable.options = [:title, :description]
28
+ Optimizable.parent_controller = AdminController
29
+
30
+ === Migration:
31
+
32
+ class CreateOptimizations < ActiveRecord::Migration
33
+ def change
34
+ create_table :optimizations do |t|
35
+ t.integer :optimizable_id
36
+ t.string :optimizable_type
37
+ t.string :name
38
+ t.text :data
39
+
40
+ t.timestamps
41
+ end
42
+ end
43
+ end
44
+
45
+ === TODO:
46
+
47
+ Cover with specs
data/Rakefile ADDED
@@ -0,0 +1,37 @@
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
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Optimizable'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task :default => :test
@@ -0,0 +1,85 @@
1
+ module Optimizable
2
+ class OptimizationsController < Optimizable.parent_controller
3
+ # GET /optimizations
4
+ # GET /optimizations.json
5
+ def index
6
+ @optimizations = Optimization.all
7
+
8
+ respond_to do |format|
9
+ format.html # index.html.erb
10
+ format.json { render json: @optimizations }
11
+ end
12
+ end
13
+
14
+ # GET /optimizations/1
15
+ # GET /optimizations/1.json
16
+ def show
17
+ @optimization = Optimization.find(params[:id])
18
+
19
+ respond_to do |format|
20
+ format.html # show.html.erb
21
+ format.json { render json: @optimization }
22
+ end
23
+ end
24
+
25
+ # GET /optimizations/new
26
+ # GET /optimizations/new.json
27
+ def new
28
+ @optimization = Optimization.new
29
+ @optimization.optimizable = params[:optimizable_type].camelize.constantize.find(params[:optimizable_id])
30
+ respond_to do |format|
31
+ format.html # new.html.erb
32
+ format.json { render json: @optimization }
33
+ end
34
+ end
35
+
36
+ # GET /optimizations/1/edit
37
+ def edit
38
+ @optimization = Optimization.find(params[:id])
39
+ end
40
+
41
+ # POST /optimizations
42
+ # POST /optimizations.json
43
+ def create
44
+ @optimization = Optimization.new(params[:optimizable_optimization])
45
+
46
+ respond_to do |format|
47
+ if @optimization.save
48
+ format.html { redirect_to optimization_path(@optimization), notice: 'Optimization was successfully created.' }
49
+ format.json { render json: @optimization, status: :created, location: @optimization }
50
+ else
51
+ format.html { render action: "new" }
52
+ format.json { render json: @optimization.errors, status: :unprocessable_entity }
53
+ end
54
+ end
55
+ end
56
+
57
+ # PUT /optimizations/1
58
+ # PUT /optimizations/1.json
59
+ def update
60
+ @optimization = Optimization.find(params[:id])
61
+
62
+ respond_to do |format|
63
+ if @optimization.update_attributes(params[:optimizable_optimization])
64
+ format.html { redirect_to optimization_path(@optimization), notice: 'Optimization was successfully updated.' }
65
+ format.json { head :ok }
66
+ else
67
+ format.html { render action: "edit" }
68
+ format.json { render json: @optimization.errors, status: :unprocessable_entity }
69
+ end
70
+ end
71
+ end
72
+
73
+ # DELETE /optimizations/1
74
+ # DELETE /optimizations/1.json
75
+ def destroy
76
+ @optimization = Optimization.find(params[:id])
77
+ @optimization.destroy
78
+
79
+ respond_to do |format|
80
+ format.html { redirect_to optimizations_url }
81
+ format.json { head :ok }
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,20 @@
1
+ module Optimizable
2
+ module OptimizationsHelper
3
+ def optimization_path_for(object)
4
+ o = Optimization.for(object)
5
+ if o
6
+ edit_optimization_path(o)
7
+ else
8
+ new_optimization_path(:optimizable_type => object.class.to_s.underscore, :optimizable_id => object.id)
9
+ end
10
+ end
11
+
12
+ def optimization(object, option)
13
+ return nil if object.blank? || option.blank?
14
+ o = Optimization.for(object)
15
+ return nil unless o
16
+ o.get(option)
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ module Optimizable
2
+ class Optimization < ActiveRecord::Base
3
+ validates_uniqueness_of :optimizable_id, :scope => [:optimizable_type]
4
+ belongs_to :optimizable, :polymorphic => true
5
+
6
+ serialize :data, Hash
7
+
8
+ def self.for(optimizable)
9
+ self.where(:optimizable_id => optimizable.id, :optimizable_type => optimizable.class.to_s).first
10
+ end
11
+
12
+ def after_initialize
13
+ self.data ||= {}
14
+ Optimizable.options.each do |option|
15
+ self.data[option] = nil
16
+ end
17
+ end
18
+
19
+ def get key
20
+ self.data[key]
21
+ end
22
+
23
+ def human_optimizable
24
+ [optimizable.try(:title) || optimizable.try(:name) || optimizable.try(:id), optimizable.class.to_s].join(' ').downcase
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,35 @@
1
+ <%= form_for(@optimization, :url => @optimization.new_record? ? optimizations_path : optimization_path(@optimization)) do |f| %>
2
+ <% if @optimization.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@optimization.errors.count, "error") %> prohibited this optimization from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @optimization.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <%=t(:optimization_for, :scope => :optimizable)%> "<%=@optimization.human_optimizable%>"
15
+ <div class="field">
16
+ <%= f.hidden_field :optimizable_id %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.hidden_field :optimizable_type %>
20
+ </div>
21
+ <div class="field">
22
+ <%= f.label :name %><br />
23
+ <%= f.text_field :name %>
24
+ </div>
25
+
26
+ <% Optimizable.options.each do |option|%>
27
+ <div class="field">
28
+ <%= label_tag "optimizable_optimization[data][#{option}]", option %><br />
29
+ <%= text_field_tag "optimizable_optimization[data][#{option}]", @optimization.get(option) %>
30
+ </div>
31
+ <% end %>
32
+ <div class="actions">
33
+ <%= f.submit %>
34
+ </div>
35
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1><%=t '.title'%></h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to t(:show, :scope => :optimizable), optimization_path(@optimization) %> |
6
+ <%= link_to t(:back, :scope => :optimizable), optimizations_path %>
@@ -0,0 +1,29 @@
1
+ <h1><%=t '.title'%></h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th><%=t(:optimizable_id, :scope => :optimizable)%></th>
6
+ <th><%=t(:optimizable_type, :scope => :optimizable)%></th>
7
+ <th><%=t(:name, :scope => :optimizable)%></th>
8
+ <th><%=t(:data, :scope => :optimizable)%></th>
9
+ <th></th>
10
+ <th></th>
11
+ <th></th>
12
+ </tr>
13
+
14
+ <% @optimizations.each do |optimization| %>
15
+ <tr>
16
+ <td><%= optimization.optimizable_id %></td>
17
+ <td><%= optimization.optimizable_type %></td>
18
+ <td><%= optimization.name %></td>
19
+ <td><%= optimization.data %></td>
20
+ <td><%= link_to t(:show, :scope => :optimizable), optimization_path(optimization) %></td>
21
+ <td><%= link_to t(:edit, :scope => :optimizable), edit_optimization_path(optimization) %></td>
22
+ <td><%= link_to t(:destroy, :scope => :optimizable), optimization_path(optimization), confirm: 'Are you sure?', method: :delete %></td>
23
+ </tr>
24
+ <% end %>
25
+ </table>
26
+
27
+ <br />
28
+
29
+ <%#= link_to t(:new, :scope => :optimizable), new_optimization_path %>
@@ -0,0 +1,5 @@
1
+ <h1><%=t '.title'%></h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to t(:back, :scope => :optimizable), optimizations_path %>
@@ -0,0 +1,25 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <b><%=t(:optimizable_id, :scope => :optimizable)%>:</b>
5
+ <%= @optimization.optimizable_id %>
6
+ </p>
7
+
8
+ <p>
9
+ <b><%=t(:optimizable_type, :scope => :optimizable)%>:</b>
10
+ <%= @optimization.optimizable_type %>
11
+ </p>
12
+
13
+ <p>
14
+ <b><%=t(:name, :scope => :optimizable)%>:</b>
15
+ <%= @optimization.name %>
16
+ </p>
17
+
18
+ <p>
19
+ <b><%=t(:data, :scope => :optimizable)%>:</b>
20
+ <%= @optimization.data %>
21
+ </p>
22
+
23
+
24
+ <%= link_to t(:edit, :scope => :optimizable), edit_optimization_path(@optimization) %> |
25
+ <%= link_to t(:back, :scope => :optimizable), optimizations_path %>
@@ -0,0 +1,31 @@
1
+ ru:
2
+ optimize_it: 'Оптимизировать'
3
+ optimizations: Оптимизации
4
+ optimizations:
5
+ index:
6
+ title: Оптимизации
7
+ show:
8
+ title: Оптимизация
9
+ edit:
10
+ title: Редактирование Оптимизации
11
+ new:
12
+ title: Новая Оптимизация
13
+ optimizable:
14
+ show: Просмотреть
15
+ edit: Редактировать
16
+ destroy: Удалить
17
+ back: Назад
18
+ new: Добавить
19
+ data: Данные
20
+ name: Название
21
+ optimizable_id: Id Оптимизируемого объекта
22
+ optimizable_type: Тип Оптимизируемого объекта
23
+ activerecord:
24
+ models:
25
+ optimization: Оптимизация
26
+ attributes:
27
+ optimization:
28
+ name: Название
29
+ data: Данные
30
+ optimizable_id: Идентификатор
31
+ optimizable_type: Тип
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ # Optimizable::Engine.routes.draw do
2
+ # resources :optimizations, :controller => 'optimizable/optimizations'
3
+ # end
4
+
5
+ Rails.application.routes.draw do
6
+ resources :optimizations, :controller => 'optimizable/optimizations'
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'rails'
2
+
3
+ module Optimizable
4
+ class Engine < Rails::Engine
5
+ engine_name :optimizable
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Optimizable
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ require 'optimizable/engine'
2
+
3
+ module Optimizable
4
+ class<<self
5
+ attr_writer :options, :parent_controller
6
+
7
+ def options
8
+ @options || default_options
9
+ end
10
+
11
+ def default_options
12
+ [:description, :title]
13
+ end
14
+
15
+ def parent_controller
16
+ @parent_controller || default_parent_controller
17
+ end
18
+
19
+ def default_parent_controller
20
+ ApplicationController
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :optimizable do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: optimizable
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
+ - Alex Mishyn
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-10-18 00:00:00 +03: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
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 3
29
+ - 1
30
+ - 0
31
+ version: 3.1.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ description: Store for seo params
47
+ email:
48
+ - mishyn@gmail.com
49
+ executables: []
50
+
51
+ extensions: []
52
+
53
+ extra_rdoc_files: []
54
+
55
+ files:
56
+ - app/controllers/optimizable/optimizations_controller.rb
57
+ - app/helpers/optimizable/optimizations_helper.rb
58
+ - app/models/optimizable/optimization.rb
59
+ - app/views/optimizable/optimizations/_form.html.erb
60
+ - app/views/optimizable/optimizations/edit.html.erb
61
+ - app/views/optimizable/optimizations/index.html.erb
62
+ - app/views/optimizable/optimizations/new.html.erb
63
+ - app/views/optimizable/optimizations/show.html.erb
64
+ - config/locales/ru.yml
65
+ - config/routes.rb
66
+ - lib/optimizable/engine.rb
67
+ - lib/optimizable/version.rb
68
+ - lib/optimizable.rb
69
+ - lib/tasks/optimizable_tasks.rake
70
+ - MIT-LICENSE
71
+ - Rakefile
72
+ - README.rdoc
73
+ has_rdoc: true
74
+ homepage:
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options: []
79
+
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ requirements: []
97
+
98
+ rubyforge_project:
99
+ rubygems_version: 1.3.6
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Store for seo params
103
+ test_files: []
104
+