olala 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/olala.iml +1 -0
- data/Gemfile.lock +17 -0
- data/README.md +31 -5
- data/app/controllers/olala/labels_controller.rb +23 -0
- data/app/models/olala/label.rb +19 -0
- data/config/routes.rb +5 -0
- data/lib/generators/olala/install/install_generator.rb +29 -1
- data/lib/generators/olala/install/templates/create_labels.rb +10 -0
- data/lib/olala.rb +42 -1
- data/lib/olala/version.rb +1 -1
- data/olala-0.0.1.gem +0 -0
- data/olala.gemspec +2 -0
- data/vendor/assets/javascripts/olala.js +55 -3
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 612f570db9fee7224fce81d26b27191083732280
|
4
|
+
data.tar.gz: 583e4c38c91cf96147e675909c1088ced5d188ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9ffcdbb0168a532e57bf7c67741edeebe1949580bcd5b77545ba3160d251f1034f38146cc2a4e0cfdcf3f83d56c6dfd5944ab1c9c3c17bbf865ea62961c5956
|
7
|
+
data.tar.gz: b734235bb2ed809bf3a6f9f9ce16ff5f569ea2b67bfa2eb4771b96078e9ce9fcd6704e9e7fb44c7e59a37342fbfdb75753d9619c16d38e3751b8a2dfc4d4a2c6
|
data/.idea/olala.iml
CHANGED
@@ -13,6 +13,7 @@
|
|
13
13
|
<content url="file://$MODULE_DIR$" />
|
14
14
|
<orderEntry type="inheritedJdk" />
|
15
15
|
<orderEntry type="sourceFolder" forTests="false" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="olala (v0.0.1, /Users/pinouchon/code/olala) [path][gem]" level="application" />
|
16
17
|
</component>
|
17
18
|
</module>
|
18
19
|
|
data/Gemfile.lock
ADDED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Olala
|
2
2
|
|
3
|
-
|
3
|
+
Dynamic content edition for rails
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -11,14 +11,40 @@ Add this line to your application's Gemfile:
|
|
11
11
|
And then execute:
|
12
12
|
|
13
13
|
$ bundle
|
14
|
+
$ rails g olala:install
|
15
|
+
$ rake db:migrate
|
14
16
|
|
15
|
-
|
17
|
+
Add `require olala` at the end of `app/assets/javascripts/application.js`
|
16
18
|
|
17
|
-
|
19
|
+
Add this in `application.html.erb` before `</head>` tag
|
18
20
|
|
19
|
-
|
21
|
+
<% if session[:admin] %>
|
22
|
+
<link rel="stylesheet" href="/aloha/css/aloha.css" type="text/css">
|
23
|
+
<script src="/aloha/lib/require.js"></script>
|
24
|
+
<script src="/aloha/lib/vendor/jquery-1.7.2.js"></script>
|
25
|
+
<script src="/aloha/lib/aloha.js" data-aloha-plugins="common/ui,common/format,common/table,common/list,common/highlighteditables,common/link,common/image,common/block,common/undo"></script>
|
26
|
+
<% end %>
|
27
|
+
<%= javascript_include_tag 'application' %>
|
20
28
|
|
21
|
-
|
29
|
+
Change your body tag to: `<body class='<%= 'admin' if session[:admin] %>'>`
|
30
|
+
|
31
|
+
Load the temporary auth mechanism (in application_controller.rb) :
|
32
|
+
|
33
|
+
include Olala::CustomAuth
|
34
|
+
|
35
|
+
|
36
|
+
Make sure that you have:
|
37
|
+
|
38
|
+
- jquery in your javascript dependencies'
|
39
|
+
- a database with activeRecord (pg, mysql, sqlite), jquery
|
40
|
+
|
41
|
+
## Usage:
|
42
|
+
|
43
|
+
Replace each block that you want to make dynamic:
|
44
|
+
|
45
|
+
<p>Static text</p>
|
46
|
+
to
|
47
|
+
<p>Olala::editable('my_title', 'Static text')</p>
|
22
48
|
|
23
49
|
## Contributing
|
24
50
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Olala
|
2
|
+
class LabelsController < ApplicationController
|
3
|
+
include ApplicationHelper
|
4
|
+
|
5
|
+
before_filter :check_admin_right
|
6
|
+
protect_from_forgery :except => :create
|
7
|
+
|
8
|
+
def check_admin_right
|
9
|
+
if !session[:admin]
|
10
|
+
raise 'Access denied'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
params.permit(:label, :content)
|
16
|
+
|
17
|
+
label = Label.find_or_create_by_label params[:label]
|
18
|
+
label.content = params[:content] if params[:content]
|
19
|
+
label.save
|
20
|
+
render text: 'ok'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Olala
|
2
|
+
class Label < ActiveRecord::Base
|
3
|
+
#attr_accessible :content_fr, :content_en, :label
|
4
|
+
|
5
|
+
def self.retrieve(label, default = nil)
|
6
|
+
if default.nil?
|
7
|
+
label = Digest::MD5.hexdigest(label)
|
8
|
+
default = 'undefined'
|
9
|
+
end
|
10
|
+
|
11
|
+
entry = self.where(label: label).first
|
12
|
+
if !entry
|
13
|
+
entry = Label.create! label: label, content: default
|
14
|
+
end
|
15
|
+
[label, entry.content.to_s.html_safe]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/config/routes.rb
ADDED
@@ -7,13 +7,41 @@ module Olala
|
|
7
7
|
module Generators
|
8
8
|
class InstallGenerator < ::Rails::Generators::Base
|
9
9
|
|
10
|
+
include Rails::Generators::Migration
|
11
|
+
|
12
|
+
def self.next_migration_number(path)
|
13
|
+
unless @prev_migration_nr
|
14
|
+
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
15
|
+
else
|
16
|
+
@prev_migration_nr += 1
|
17
|
+
end
|
18
|
+
@prev_migration_nr.to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
def copy_migrations
|
22
|
+
migration_template "../../lib/generators/olala/install/templates/create_labels.rb", "db/migrate/create_labels.rb"
|
23
|
+
#migration_template "create_something_else.rb", "db/migrate/create_something_else.rb"
|
24
|
+
end
|
25
|
+
|
10
26
|
desc "This generator installs olala + aloha"
|
11
27
|
source_root File.expand_path('../../../../../vendor/assets/', __FILE__)
|
12
28
|
|
13
29
|
def add_assets
|
14
30
|
puts 'copying aloha into public/ ...'
|
15
31
|
directory 'aloha', 'public/aloha/'
|
16
|
-
puts '
|
32
|
+
puts 'Aloha jquery plugin is now installed in public/aloha'
|
33
|
+
end
|
34
|
+
|
35
|
+
def copy_olala
|
36
|
+
say_status("copying", "olala", :green)
|
37
|
+
copy_file "javascripts/olala.js", "app/assets/javascripts/olala.js"
|
38
|
+
|
39
|
+
puts ''
|
40
|
+
puts 'To use olala, you need to:'
|
41
|
+
puts ' - add jquery in your javascript dependencies'
|
42
|
+
puts ' - add "require olala" in app/assets/javascripts/application.js'
|
43
|
+
puts ''
|
44
|
+
puts 'More info at https://github.com/pinouchon/olala'
|
17
45
|
end
|
18
46
|
|
19
47
|
end
|
data/lib/olala.rb
CHANGED
@@ -1,5 +1,46 @@
|
|
1
1
|
require "olala/version"
|
2
2
|
|
3
3
|
module Olala
|
4
|
-
|
4
|
+
module Controllers
|
5
|
+
#autoload :Rememberable, 'devise/controllers/rememberable'
|
6
|
+
autoload :Labels, 'olala/controllers'
|
7
|
+
end
|
8
|
+
|
9
|
+
class Engine < Rails::Engine
|
10
|
+
#config.autoload_paths << File.expand_path("../app", __FILE__)
|
11
|
+
|
12
|
+
config.to_prepare do
|
13
|
+
ApplicationController.helper(Olala::Helpers)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module CustomAuth
|
18
|
+
def self.included(base)
|
19
|
+
base.send(:before_filter, :custom_auth)
|
20
|
+
end
|
21
|
+
|
22
|
+
def custom_auth
|
23
|
+
if params[:admin] == (ENV['OLALA_PASSWORD'] || 'secretpass42')
|
24
|
+
session[:admin] = true
|
25
|
+
end
|
26
|
+
if params[:admin] == ''
|
27
|
+
session[:admin] = false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
module Helpers
|
34
|
+
def editable(label, default = nil, &block)
|
35
|
+
if block_given?
|
36
|
+
label, content = Olala::Label.retrieve(label, capture(&block))
|
37
|
+
return raw "<div class='editable' data-label='#{label.to_s}'>" +
|
38
|
+
content.to_s +
|
39
|
+
'</div>'.html_safe
|
40
|
+
else
|
41
|
+
label, content = Olala::Label.retrieve(label, default)
|
42
|
+
return raw "<div class='editable' data-label='#{label.to_s}'>#{content.to_s}</div>".html_safe
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
5
46
|
end
|
data/lib/olala/version.rb
CHANGED
data/olala-0.0.1.gem
ADDED
Binary file
|
data/olala.gemspec
CHANGED
@@ -1,3 +1,55 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
var Olala = {
|
2
|
+
init: function () {
|
3
|
+
if (this.isAdmin()) {
|
4
|
+
this.initAloha();
|
5
|
+
}
|
6
|
+
},
|
7
|
+
|
8
|
+
isAdmin: function () {
|
9
|
+
return $('body').hasClass('admin');
|
10
|
+
},
|
11
|
+
|
12
|
+
initAloha: function () {
|
13
|
+
Aloha.ready(function () {
|
14
|
+
Aloha.jQuery('.editable').aloha();
|
15
|
+
Aloha.require(['aloha', 'aloha/jquery'], function (Aloha, jQuery) {
|
16
|
+
|
17
|
+
// save all changes after leaving an editable
|
18
|
+
Aloha.bind('aloha-editable-deactivated', function () {
|
19
|
+
var content = Aloha.activeEditable.getContents();
|
20
|
+
var contentId = Aloha.activeEditable.obj[0].id;
|
21
|
+
var pageId = window.location.pathname;
|
22
|
+
|
23
|
+
// textarea handling -- html id is "xy" and will be "xy-aloha" for the aloha editable
|
24
|
+
if (contentId.match(/-aloha$/gi)) {
|
25
|
+
contentId = contentId.replace(/-aloha/gi, '');
|
26
|
+
}
|
27
|
+
|
28
|
+
console.log({content: content, id: contentId, pageId: pageId});
|
29
|
+
|
30
|
+
var data = {label: Aloha.activeEditable.obj.data('label')};
|
31
|
+
data['content'] = content;
|
32
|
+
$.ajax({
|
33
|
+
type: "POST",
|
34
|
+
url: '/olala/labels',
|
35
|
+
data: data,
|
36
|
+
success: function () {
|
37
|
+
console.log('success', 'Modifications enregistrées');
|
38
|
+
},
|
39
|
+
failure: function () {
|
40
|
+
console.log('error', "Impossible d'enregistrer les modifications (1)");
|
41
|
+
},
|
42
|
+
error: function () {
|
43
|
+
console.log('error', "Impossible d'enregistrer les modifications (2)");
|
44
|
+
}
|
45
|
+
});
|
46
|
+
});
|
47
|
+
|
48
|
+
});
|
49
|
+
});
|
50
|
+
}
|
51
|
+
};
|
52
|
+
|
53
|
+
$(function () {
|
54
|
+
Olala.init();
|
55
|
+
});
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: olala
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Crouzier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -54,12 +54,18 @@ files:
|
|
54
54
|
- .idea/vcs.xml
|
55
55
|
- .idea/workspace.xml
|
56
56
|
- Gemfile
|
57
|
+
- Gemfile.lock
|
57
58
|
- LICENSE.txt
|
58
59
|
- README.md
|
59
60
|
- Rakefile
|
61
|
+
- app/controllers/olala/labels_controller.rb
|
62
|
+
- app/models/olala/label.rb
|
63
|
+
- config/routes.rb
|
60
64
|
- lib/generators/olala/install/install_generator.rb
|
65
|
+
- lib/generators/olala/install/templates/create_labels.rb
|
61
66
|
- lib/olala.rb
|
62
67
|
- lib/olala/version.rb
|
68
|
+
- olala-0.0.1.gem
|
63
69
|
- olala.gemspec
|
64
70
|
- olala/.idea/olala.iml
|
65
71
|
- vendor/assets/aloha/css/aloha-common-extra.css
|