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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 625da9256f6b09c349b3011c4a15ccfc46599a8f
4
- data.tar.gz: be33f3076a87623a6cf9a9c391582929f6c1d676
3
+ metadata.gz: 612f570db9fee7224fce81d26b27191083732280
4
+ data.tar.gz: 583e4c38c91cf96147e675909c1088ced5d188ab
5
5
  SHA512:
6
- metadata.gz: 9f8e5de2cc5901c886742076067dfa4633e497d4c02eba34af5be026546e89833720c0e59165ff0cf1df4c099bf2b8852b390c52d6d6c5daf6aa7f5988b3aec2
7
- data.tar.gz: f198d279534f46302f0ca3eefa35e16e7d85bf838dd8944deb09d95e80c529f767c3861292156bc2e0cfb7d9f565c896f2a64af1faf506d5a024bbdc03d254ea
6
+ metadata.gz: d9ffcdbb0168a532e57bf7c67741edeebe1949580bcd5b77545ba3160d251f1034f38146cc2a4e0cfdcf3f83d56c6dfd5944ab1c9c3c17bbf865ea62961c5956
7
+ data.tar.gz: b734235bb2ed809bf3a6f9f9ce16ff5f569ea2b67bfa2eb4771b96078e9ce9fcd6704e9e7fb44c7e59a37342fbfdb75753d9619c16d38e3751b8a2dfc4d4a2c6
@@ -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
 
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ olala (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.3.2)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ bundler (~> 1.3)
16
+ olala!
17
+ rake
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Olala
2
2
 
3
- TODO: Write a gem description
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
- Or install it yourself as:
17
+ Add `require olala` at the end of `app/assets/javascripts/application.js`
16
18
 
17
- $ gem install olala
19
+ Add this in `application.html.erb` before `</head>` tag
18
20
 
19
- ## Usage
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
- TODO: Write usage instructions here
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
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ namespace :olala do
3
+ resources :labels
4
+ end
5
+ end
@@ -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 'done copying aloha into public'
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
@@ -0,0 +1,10 @@
1
+ class CreateLabels < ActiveRecord::Migration
2
+ def change
3
+ create_table :labels do |t|
4
+ t.string :label
5
+ t.string :content
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -1,5 +1,46 @@
1
1
  require "olala/version"
2
2
 
3
3
  module Olala
4
- # Your code goes here...
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
@@ -1,3 +1,3 @@
1
1
  module Olala
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
Binary file
@@ -2,6 +2,8 @@
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'olala/version'
5
+ #require 'olala/engine'
6
+ #require 'app/controllers/olala/labels_controller'
5
7
 
6
8
  Gem::Specification.new do |spec|
7
9
  spec.name = "olala"
@@ -1,3 +1,55 @@
1
- function olala() {
2
- console.log('olala');
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.1
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-01 00:00:00.000000000 Z
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