ace-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/README.md +27 -0
- data/Rakefile +2 -0
- data/ace-rails.gemspec +21 -0
- data/lib/ace-rails.rb +8 -0
- data/lib/ace-rails/railtie.rb +13 -0
- data/lib/ace-rails/version.rb +6 -0
- data/lib/ace-rails/view_helpers.rb +38 -0
- data/lib/generators/ace/install/USAGE +0 -0
- data/lib/generators/ace/install/install_generator.rb +51 -0
- data/lib/generators/ace/install/templates/ace-rails.css +23 -0
- metadata +68 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# ace-rails
|
2
|
+
|
3
|
+
This gem provides a generator to download and install [ace (Ajax.org Cloud9 Editor)](https://github.com/ajaxorg/ace) into your Rails 3 project. It also provides some view helper to setup an editor.
|
4
|
+
|
5
|
+
## Setup
|
6
|
+
|
7
|
+
Add the gem to your Gemfile and run *bundle*.
|
8
|
+
|
9
|
+
gem 'ace-rails'
|
10
|
+
|
11
|
+
Run the generator to download and install the current version of [ace](https://github.com/ajaxorg/ace) into *public/javascripts/ace*
|
12
|
+
|
13
|
+
rails g ace:install
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Use the helper function to create an editor within your view
|
18
|
+
|
19
|
+
<%= ace_editor :mode => :css, :content => "body {\n\tfont-size: 12px;\n}" %>
|
20
|
+
|
21
|
+
the *:mode* option could be one of
|
22
|
+
|
23
|
+
[:c_cpp, :coffee, :css, :html, :java, :javascript, :php, :python, :ruby, :xml]
|
24
|
+
|
25
|
+
you can also specify a *:theme* option to change the look and feel of the ace editor. By default ace loads the *textmate* theme. Currentyl available themes are:
|
26
|
+
|
27
|
+
[:clouds, :clouds_midnight, :cobalt, :dawn, :eclipse, :idle_fingers, :kr_theme, :mongo_industrial, :monokai, :pastel_on_dark, :twilight]
|
data/Rakefile
ADDED
data/ace-rails.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ace-rails/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "ace-rails"
|
7
|
+
s.version = Ace::Rails::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Florian Günther"]
|
10
|
+
s.email = ["mail@gee-f.de"]
|
11
|
+
s.homepage = "https://github.com/florianguenther/ace-rails"
|
12
|
+
s.summary = "Use ace (Ajax.org Cloud9 Editor) within your Rails 3 projects"
|
13
|
+
s.description = "This gem provides a generator to download and install ace (Ajax.org Cloud9 Editor) into your Rails 3 project. It also provides some view helper to setup an editor."
|
14
|
+
|
15
|
+
# s.rubyforge_project = "ace-rails"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
data/lib/ace-rails.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Ace
|
2
|
+
module Rails
|
3
|
+
module ViewHelpers
|
4
|
+
|
5
|
+
def ace_editor(options = {})
|
6
|
+
id = options[:id] || 'editor'
|
7
|
+
mode = options[:mode] || 'css'
|
8
|
+
theme = options[:theme] # nil => default theme
|
9
|
+
|
10
|
+
mode_class = "#{mode}_mode".camelize
|
11
|
+
|
12
|
+
theme_script_tag = theme ? "<script type='text/javascript' src='/javascripts/ace/theme-#{theme}.js' charset='utf-8' ></script>" : ""
|
13
|
+
theme_setter = theme ? "editor.setTheme('ace/theme/#{theme}');" : ""
|
14
|
+
|
15
|
+
output = <<HTML
|
16
|
+
<div class='editor_container'>
|
17
|
+
<pre id='#{id}'>#{options[:content]}</pre>
|
18
|
+
<div class='editor_footer'></div>
|
19
|
+
</div>
|
20
|
+
<script type='text/javascript' src='/javascripts/ace/ace.js' charset='utf-8' ></script>
|
21
|
+
<script type='text/javascript' src='/javascripts/ace/mode-#{mode}.js' charset='utf-8' ></script>
|
22
|
+
#{theme_script_tag}
|
23
|
+
<script type='text/javascript'>
|
24
|
+
$(document).ready(function(){
|
25
|
+
var editor = ace.edit('#{id}');
|
26
|
+
#{theme_setter}
|
27
|
+
var #{mode_class} = require("ace/mode/#{mode}").Mode;
|
28
|
+
editor.getSession().setMode(new #{mode_class}());
|
29
|
+
});
|
30
|
+
</script>
|
31
|
+
HTML
|
32
|
+
|
33
|
+
output.html_safe
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
File without changes
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Ace
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
@@ace_version = "0.1.6"
|
7
|
+
@@ace_version_file = "ace-#{@@ace_version}.tgz"
|
8
|
+
# @@ace_url = "https://github.com/downloads/ajaxorg/ace/#{@@ace_version_file}"
|
9
|
+
@@ace_url = "http://cloud.github.com/downloads/ajaxorg/ace/#{@@ace_version_file}"
|
10
|
+
|
11
|
+
@@tmp_base = "tmp/ace-install"
|
12
|
+
@@tmp_file = File.join @@tmp_base, @@ace_version_file
|
13
|
+
@@tmp_src_base = File.join @@tmp_base, "ace-#{@@ace_version}", "src"
|
14
|
+
|
15
|
+
@@target_src = "public/javascripts/ace"
|
16
|
+
|
17
|
+
class_option :download, :type => :boolean, :default => true, :desc => "Download and install ACE (#{@@ace_version}) to #{@@target_src}."
|
18
|
+
class_option :stylesheet, :type => :boolean, :default => true, :desc => "Creates a default stylesheet and includes it to the application layout"
|
19
|
+
def self.source_root
|
20
|
+
File.dirname(__FILE__) + "/templates"
|
21
|
+
end
|
22
|
+
|
23
|
+
def download_and_install_ace
|
24
|
+
return unless options.download?
|
25
|
+
|
26
|
+
remove_dir @@tmp_base
|
27
|
+
remove_dir @@target_src
|
28
|
+
get @@ace_url, @@tmp_file
|
29
|
+
inside @@tmp_base do
|
30
|
+
run("tar xzf #{@@ace_version_file}")
|
31
|
+
end
|
32
|
+
|
33
|
+
say_status("copying", "ace (#{@@ace_version})", :green)
|
34
|
+
FileUtils.cp_r("#{File.expand_path @@tmp_src_base}", @@target_src)
|
35
|
+
|
36
|
+
remove_dir @@tmp_base
|
37
|
+
end
|
38
|
+
|
39
|
+
def copy_stylesheet
|
40
|
+
return unless options.stylesheet?
|
41
|
+
|
42
|
+
copy_file "ace-rails.css", "public/stylesheets/ace-rails.css"
|
43
|
+
|
44
|
+
application_layout = File.expand_path('app/views/layouts/application.html.erb')
|
45
|
+
stylesheet_tag = "\n <%= stylesheet_link_tag '/stylesheets/ace-rails.css' %>"
|
46
|
+
inject_into_file application_layout, stylesheet_tag, :after => "</title>"
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/* Style for ace-rails */
|
2
|
+
|
3
|
+
#editor_container {
|
4
|
+
clear: both;
|
5
|
+
width: 100%;
|
6
|
+
height: 300px;
|
7
|
+
position: relative;
|
8
|
+
}
|
9
|
+
|
10
|
+
#editor {
|
11
|
+
position: absolute;
|
12
|
+
background-color: #fff;
|
13
|
+
margin: 0;
|
14
|
+
top: 0;
|
15
|
+
bottom: 0;
|
16
|
+
left: 0;
|
17
|
+
right: 0;
|
18
|
+
border: 1px solid #333;
|
19
|
+
}
|
20
|
+
|
21
|
+
#editor_footer {
|
22
|
+
clear: both;
|
23
|
+
}
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ace-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- "Florian G\xC3\xBCnther"
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-11 00:00:00 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: This gem provides a generator to download and install ace (Ajax.org Cloud9 Editor) into your Rails 3 project. It also provides some view helper to setup an editor.
|
18
|
+
email:
|
19
|
+
- mail@gee-f.de
|
20
|
+
executables: []
|
21
|
+
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
26
|
+
files:
|
27
|
+
- .gitignore
|
28
|
+
- Gemfile
|
29
|
+
- README.md
|
30
|
+
- Rakefile
|
31
|
+
- ace-rails.gemspec
|
32
|
+
- lib/ace-rails.rb
|
33
|
+
- lib/ace-rails/railtie.rb
|
34
|
+
- lib/ace-rails/version.rb
|
35
|
+
- lib/ace-rails/view_helpers.rb
|
36
|
+
- lib/generators/ace/install/USAGE
|
37
|
+
- lib/generators/ace/install/install_generator.rb
|
38
|
+
- lib/generators/ace/install/templates/ace-rails.css
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: https://github.com/florianguenther/ace-rails
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.6.2
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: Use ace (Ajax.org Cloud9 Editor) within your Rails 3 projects
|
67
|
+
test_files: []
|
68
|
+
|