acts_as_translatebox 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg/
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 [name of plugin creator]
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.md ADDED
@@ -0,0 +1,44 @@
1
+ ## ActsAsTranslatebox
2
+
3
+ Add a translate box at the page bottom for your rails project.
4
+
5
+ Author: [Qichunren](http://cqror.com/qichunren)
6
+
7
+ ### How to use it?
8
+
9
+ gem install acts_as_translatebox
10
+
11
+ In Gemfile
12
+
13
+ gem "acts_as_translatebox"
14
+
15
+ Then just use
16
+
17
+ acts_as_translatebox
18
+
19
+ in your controller.
20
+
21
+ #### Example
22
+
23
+ class PostsController < ApplicationController
24
+
25
+ acts_as_translatebox :only => ["index","show"]
26
+
27
+ def index
28
+ @posts = Post.latest(5)
29
+ end
30
+
31
+ def new
32
+ @post = Post.new
33
+ end
34
+
35
+ def show
36
+ @post = Post.find(params[:id])
37
+ end
38
+
39
+ end
40
+
41
+ ![Demo](https://github.com/qichunren/acts_as_translatebox/raw/master/translate_demo.png)
42
+
43
+
44
+ Copyright (c) 2009 [name of plugin creator], released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ require "rubygems"
3
+ require 'rake'
4
+
5
+ begin
6
+ require 'jeweler'
7
+
8
+ Jeweler::Tasks.new do |gemspec|
9
+ gemspec.name = "acts_as_translatebox"
10
+ gemspec.summary = "add a translate box at the bottom of page."
11
+ gemspec.description = "add a translate box at the bottom of page."
12
+ gemspec.email = "whyruby@gmail.com"
13
+ gemspec.homepage = "https://github.com/qichunren/acts_as_translatebox"
14
+ gemspec.authors = ["qichunren"]
15
+
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+
19
+ rescue LoadError
20
+ puts "Jeweler not available. Install it with: gem install jeweler"
21
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,53 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{acts_as_translatebox}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["qichunren"]
12
+ s.date = %q{2011-02-20}
13
+ s.description = %q{add a translate box at the bottom of page.}
14
+ s.email = %q{whyruby@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "README.md",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "acts_as_translatebox.gemspec",
25
+ "init.rb",
26
+ "install.rb",
27
+ "lib/acts_as_translatebox.rb",
28
+ "test/acts_as_translatebox_test.rb",
29
+ "test/test_helper.rb",
30
+ "translate_demo.png",
31
+ "uninstall.rb"
32
+ ]
33
+ s.homepage = %q{https://github.com/qichunren/acts_as_translatebox}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.7}
37
+ s.summary = %q{add a translate box at the bottom of page.}
38
+ s.test_files = [
39
+ "test/acts_as_translatebox_test.rb",
40
+ "test/test_helper.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ else
49
+ end
50
+ else
51
+ end
52
+ end
53
+
data/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ # encoding: utf-8
2
+ # Include hook code here
3
+ require File.dirname(__FILE__) + '/lib/acts_as_translatebox'
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,101 @@
1
+ # encoding: utf-8
2
+ # ActsAsTranslatebox
3
+ module ActsAsTranslatebox
4
+
5
+ module Rails
6
+ class Railtie < ::Rails::Railtie
7
+
8
+ end
9
+ end
10
+
11
+ def self.included(base)
12
+ base.send :include, InstanceMethods
13
+ base.send :extend, ClassMethods
14
+ end
15
+
16
+ module ClassMethods
17
+ def acts_as_translatebox(*args)
18
+ after_filter :insert_translatebox_html, (args.first||{})
19
+ end
20
+ end
21
+
22
+ module InstanceMethods
23
+ def insert_translatebox_html
24
+ translatebox_html = <<-HTML
25
+ <script type="text/javascript" src="http://www.google.com/jsapi"></script>
26
+ <script type="text/javascript">
27
+ google.load("language", "1");
28
+
29
+ function translate_it(){
30
+ var the_words = document.getElementById("words").value;
31
+ google.language.detect(the_words, function(result) {
32
+ if (!result.error && result.language) {
33
+ google.language.translate(the_words, result.language, "en",
34
+ function(result) {
35
+ var translated = document.getElementById("target");
36
+ if (result.translation) {
37
+ translated.innerHTML = result.translation;
38
+ }
39
+ });
40
+ }
41
+ });
42
+
43
+ }
44
+ </script>
45
+ <style type="text/css">
46
+ div#translate_button {
47
+ text-align: right;
48
+ position: fixed;
49
+ bottom: 0px;
50
+ right: 10px;
51
+ width: 80px;
52
+ border: 1px solid #ccc;
53
+ padding: 2px;
54
+ vertical-align: middle;
55
+ background-color: #eee;
56
+ }
57
+ div#translate_input {
58
+ position: fixed;
59
+ bottom: 25px;
60
+ padding:5px;
61
+ right: 10px;
62
+ border:1px solid #BDBDBD;
63
+ background:#E0E0E0;
64
+ }
65
+ div#translate_input span{
66
+ display:block;float:left;margin-right:4px;
67
+ border:1px solid #FF9900;color:#FF9900;
68
+ cursor:pointer;
69
+ }
70
+ * html div#translate_input {
71
+ position: absolute;
72
+ right: auto; bottom: auto;
73
+ left: expression( ( 0 - translate_input.offsetWidth + ( document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth ) + ( ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + 'px' );
74
+ top: expression( ( -25 - translate_input.offsetHeight + ( document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + 'px' );
75
+ }
76
+
77
+ * html div#translate_button {
78
+ position: absolute;
79
+ right: auto; bottom: auto;
80
+ left: expression( ( 0 - translate_button.offsetWidth + ( document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth ) + ( ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + 'px' );
81
+ top: expression( ( 0 - translate_button.offsetHeight + ( document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + 'px' );
82
+ }
83
+
84
+ </style>
85
+ <div id="translate_input" style="display:none;">
86
+ <span onclick="document.getElementById('translate_input').style.display='none'">X</span>
87
+ <input id='words' type="text" style="width:280px;vertical-align:middle;" value="输入中文 ..." />
88
+ <input type='button' value='翻译' style="vertical-align:middle;" onclick="translate_it()"/>
89
+ <div id="target" style="margin-top:4px;width:330px;height:120px;border:1px solid #FF9900;background:#FFF;overflow:scroll" ></div>
90
+ </div>
91
+ <div id="translate_button">
92
+ <a href="#" style="text-decoration:none;color:black" onclick="e = document.getElementById('translate_input');if(e.style.display==''){e.style.display='none';}else{e.style.display='';}return false;">翻译助手</a>
93
+ </div>
94
+ HTML
95
+ response.body = response.body.to_s + translatebox_html
96
+ end
97
+ end
98
+
99
+ end
100
+
101
+ ActionController::Base.send :include, ActsAsTranslatebox
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ class ActsAsTranslateboxTest < ActiveSupport::TestCase
5
+ # Replace this with your real tests.
6
+ test "the truth" do
7
+ assert true
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'active_support'
4
+ require 'active_support/test_case'
Binary file
data/uninstall.rb ADDED
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_translatebox
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
+ - qichunren
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-02-20 00:00:00 +08:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: add a translate box at the bottom of page.
22
+ email: whyruby@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.md
29
+ files:
30
+ - .gitignore
31
+ - MIT-LICENSE
32
+ - README.md
33
+ - Rakefile
34
+ - VERSION
35
+ - acts_as_translatebox.gemspec
36
+ - init.rb
37
+ - install.rb
38
+ - lib/acts_as_translatebox.rb
39
+ - test/acts_as_translatebox_test.rb
40
+ - test/test_helper.rb
41
+ - translate_demo.png
42
+ - uninstall.rb
43
+ has_rdoc: true
44
+ homepage: https://github.com/qichunren/acts_as_translatebox
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.7
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: add a translate box at the bottom of page.
75
+ test_files:
76
+ - test/acts_as_translatebox_test.rb
77
+ - test/test_helper.rb