simple_ace_input 0.0.1.rc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. data/.gitignore +7 -0
  2. data/.rvmrc +31 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +95 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.rdoc +71 -0
  7. data/Rakefile +1 -0
  8. data/app/assets/javascripts/simple_ace_input.js +51 -0
  9. data/app/assets/javascripts/simple_ace_input/.gitkeep +0 -0
  10. data/app/assets/javascripts/simple_ace_input/controller.js.coffee +35 -0
  11. data/app/inputs/ace_input.rb +18 -0
  12. data/lib/generators/simple_ace_input/config_generator.rb +11 -0
  13. data/lib/generators/simple_ace_input/templates/simple_ace_input.rb +5 -0
  14. data/lib/simple_ace_input.rb +5 -0
  15. data/lib/simple_ace_input/config.rb +35 -0
  16. data/lib/simple_ace_input/engine.rb +4 -0
  17. data/lib/simple_ace_input/version.rb +3 -0
  18. data/simple_ace_input.gemspec +23 -0
  19. data/vendor/assets/javascripts/ace/ace.js +14406 -0
  20. data/vendor/assets/javascripts/ace/keybinding-emacs.js +1 -0
  21. data/vendor/assets/javascripts/ace/keybinding-vim.js +1 -0
  22. data/vendor/assets/javascripts/ace/mode-c_cpp.js +1 -0
  23. data/vendor/assets/javascripts/ace/mode-clojure.js +1 -0
  24. data/vendor/assets/javascripts/ace/mode-coffee.js +1 -0
  25. data/vendor/assets/javascripts/ace/mode-csharp.js +1 -0
  26. data/vendor/assets/javascripts/ace/mode-css.js +1 -0
  27. data/vendor/assets/javascripts/ace/mode-groovy.js +1 -0
  28. data/vendor/assets/javascripts/ace/mode-html.js +1 -0
  29. data/vendor/assets/javascripts/ace/mode-java.js +1 -0
  30. data/vendor/assets/javascripts/ace/mode-javascript.js +1 -0
  31. data/vendor/assets/javascripts/ace/mode-json.js +1 -0
  32. data/vendor/assets/javascripts/ace/mode-latex.js +1 -0
  33. data/vendor/assets/javascripts/ace/mode-lua.js +1 -0
  34. data/vendor/assets/javascripts/ace/mode-markdown.js +1 -0
  35. data/vendor/assets/javascripts/ace/mode-ocaml.js +1 -0
  36. data/vendor/assets/javascripts/ace/mode-perl.js +1 -0
  37. data/vendor/assets/javascripts/ace/mode-php.js +1 -0
  38. data/vendor/assets/javascripts/ace/mode-python.js +1 -0
  39. data/vendor/assets/javascripts/ace/mode-ruby.js +1 -0
  40. data/vendor/assets/javascripts/ace/mode-scad.js +1 -0
  41. data/vendor/assets/javascripts/ace/mode-scala.js +1 -0
  42. data/vendor/assets/javascripts/ace/mode-scss.js +1 -0
  43. data/vendor/assets/javascripts/ace/mode-svg.js +1 -0
  44. data/vendor/assets/javascripts/ace/mode-textile.js +1 -0
  45. data/vendor/assets/javascripts/ace/mode-xml.js +1 -0
  46. data/vendor/assets/javascripts/ace/theme-carto_light.js +29 -0
  47. data/vendor/assets/javascripts/ace/theme-clouds.js +1 -0
  48. data/vendor/assets/javascripts/ace/theme-clouds_midnight.js +1 -0
  49. data/vendor/assets/javascripts/ace/theme-cobalt.js +1 -0
  50. data/vendor/assets/javascripts/ace/theme-crimson_editor.js +1 -0
  51. data/vendor/assets/javascripts/ace/theme-dawn.js +1 -0
  52. data/vendor/assets/javascripts/ace/theme-eclipse.js +1 -0
  53. data/vendor/assets/javascripts/ace/theme-idle_fingers.js +1 -0
  54. data/vendor/assets/javascripts/ace/theme-kr_theme.js +1 -0
  55. data/vendor/assets/javascripts/ace/theme-merbivore.js +1 -0
  56. data/vendor/assets/javascripts/ace/theme-merbivore_soft.js +1 -0
  57. data/vendor/assets/javascripts/ace/theme-mono_industrial.js +1 -0
  58. data/vendor/assets/javascripts/ace/theme-monokai.js +1 -0
  59. data/vendor/assets/javascripts/ace/theme-pastel_on_dark.js +1 -0
  60. data/vendor/assets/javascripts/ace/theme-solarized_dark.js +1 -0
  61. data/vendor/assets/javascripts/ace/theme-solarized_light.js +1 -0
  62. data/vendor/assets/javascripts/ace/theme-tomorrow.js +1 -0
  63. data/vendor/assets/javascripts/ace/theme-tomorrow_night.js +1 -0
  64. data/vendor/assets/javascripts/ace/theme-tomorrow_night_blue.js +1 -0
  65. data/vendor/assets/javascripts/ace/theme-tomorrow_night_bright.js +1 -0
  66. data/vendor/assets/javascripts/ace/theme-tomorrow_night_eighties.js +1 -0
  67. data/vendor/assets/javascripts/ace/theme-twilight.js +1 -0
  68. data/vendor/assets/javascripts/ace/theme-vibrant_ink.js +1 -0
  69. metadata +148 -0
@@ -0,0 +1,7 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/*.sqlite3
5
+ spec/dummy/log/*.log
6
+ spec/dummy/tmp/
7
+ spec/dummy/.sass-cache
data/.rvmrc ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+
8
+ environment_id="ruby-1.9.2-p290@simple_ace_input"
9
+
10
+
11
+ # First we attempt to load the desired environment directly from the environment
12
+ # file. This is very fast and efficient compared to running through the entire
13
+ # CLI and selector. If you want feedback on which environment was used then
14
+ # insert the word 'use' after --create as this triggers verbose mode.
15
+
16
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
17
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
18
+ then
19
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
20
+
21
+ if [[ -s ".rvm/hooks/after_use" ]]
22
+ then
23
+ . ".rvm/hooks/after_use"
24
+ fi
25
+ else
26
+ # If the environment file has not yet been created, use the RVM CLI to select.
27
+ if ! rvm --create "$environment_id"
28
+ then
29
+ echo "Failed to create RVM environment '$environment_id'."
30
+ fi
31
+ fi
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,95 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ simple_ace_input (0.0.1.rc)
5
+ rails (~> 3.1)
6
+ simple_form (~> 2.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ actionmailer (3.2.3)
12
+ actionpack (= 3.2.3)
13
+ mail (~> 2.4.4)
14
+ actionpack (3.2.3)
15
+ activemodel (= 3.2.3)
16
+ activesupport (= 3.2.3)
17
+ builder (~> 3.0.0)
18
+ erubis (~> 2.7.0)
19
+ journey (~> 1.0.1)
20
+ rack (~> 1.4.0)
21
+ rack-cache (~> 1.2)
22
+ rack-test (~> 0.6.1)
23
+ sprockets (~> 2.1.2)
24
+ activemodel (3.2.3)
25
+ activesupport (= 3.2.3)
26
+ builder (~> 3.0.0)
27
+ activerecord (3.2.3)
28
+ activemodel (= 3.2.3)
29
+ activesupport (= 3.2.3)
30
+ arel (~> 3.0.2)
31
+ tzinfo (~> 0.3.29)
32
+ activeresource (3.2.3)
33
+ activemodel (= 3.2.3)
34
+ activesupport (= 3.2.3)
35
+ activesupport (3.2.3)
36
+ i18n (~> 0.6)
37
+ multi_json (~> 1.0)
38
+ arel (3.0.2)
39
+ builder (3.0.0)
40
+ erubis (2.7.0)
41
+ hike (1.2.1)
42
+ i18n (0.6.0)
43
+ journey (1.0.3)
44
+ json (1.6.6)
45
+ mail (2.4.4)
46
+ i18n (>= 0.4.0)
47
+ mime-types (~> 1.16)
48
+ treetop (~> 1.4.8)
49
+ mime-types (1.18)
50
+ multi_json (1.3.1)
51
+ polyglot (0.3.3)
52
+ rack (1.4.1)
53
+ rack-cache (1.2)
54
+ rack (>= 0.4)
55
+ rack-ssl (1.3.2)
56
+ rack
57
+ rack-test (0.6.1)
58
+ rack (>= 1.0)
59
+ rails (3.2.3)
60
+ actionmailer (= 3.2.3)
61
+ actionpack (= 3.2.3)
62
+ activerecord (= 3.2.3)
63
+ activeresource (= 3.2.3)
64
+ activesupport (= 3.2.3)
65
+ bundler (~> 1.0)
66
+ railties (= 3.2.3)
67
+ railties (3.2.3)
68
+ actionpack (= 3.2.3)
69
+ activesupport (= 3.2.3)
70
+ rack-ssl (~> 1.3.2)
71
+ rake (>= 0.8.7)
72
+ rdoc (~> 3.4)
73
+ thor (~> 0.14.6)
74
+ rake (0.9.2.2)
75
+ rdoc (3.12)
76
+ json (~> 1.4)
77
+ simple_form (2.0.1)
78
+ actionpack (~> 3.0)
79
+ activemodel (~> 3.0)
80
+ sprockets (2.1.2)
81
+ hike (~> 1.2)
82
+ rack (~> 1.0)
83
+ tilt (~> 1.1, != 1.3.0)
84
+ thor (0.14.6)
85
+ tilt (1.3.3)
86
+ treetop (1.4.10)
87
+ polyglot
88
+ polyglot (>= 0.3.1)
89
+ tzinfo (0.3.33)
90
+
91
+ PLATFORMS
92
+ ruby
93
+
94
+ DEPENDENCIES
95
+ simple_ace_input!
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Brian McNabb
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.
@@ -0,0 +1,71 @@
1
+ = SimpleAceInput
2
+
3
+ A drop in solution for turning any +textarea+ into an ACE editor via simple_form.
4
+
5
+ == Install
6
+
7
+ Put this line in your Gemfile:
8
+ gem 'simple_ace_input'
9
+
10
+ Then bundle:
11
+ % bundle
12
+
13
+
14
+ == Configuration
15
+
16
+ The primary configuration consideration relates to how you want to handle loading the javascript files, as it relates to the Asset Pipeline.
17
+
18
+ For the whole kit and kaboodle add the following to your application.js:
19
+ //= require simple_ace_input
20
+
21
+ For a minimally viable setup (no modes or themes) add the following to your application.js:
22
+ //= ace/ace
23
+ //= simple_ace_input/controller
24
+
25
+ Then add only the modes and themes you want:
26
+ //= ace/mode-css
27
+ //= ace/mode-solarized-dark
28
+
29
+
30
+ Another option and one worth considering (b/c ACE is quite large) is only loading the scripts on pages where ACE is actually needed.
31
+
32
+ If you take this route make sure the scripts you use get precompiled by adding something like the following to your <tt>production.rb</tt> file:
33
+ config.assets.precompile += ['ace/*.js', 'simple_ace_input']
34
+
35
+ If you only want to precompile the mode, theme and keybinding files you can use a proc like this:
36
+ config.assets.precompile += [Proc.new{ |path| File.basename(path, '.js' ) =~ /^(keybinding-|mode-|theme-)\w+$/ }]
37
+
38
+ Lastly, if you're implementing this in an engine, you can designate the assets to be precompiled via an initializer placed in the <tt>engine.rb</tt> file:
39
+ initializer :assets, group: :all do |app|
40
+ app.config.assets.precompile += [...]
41
+ end
42
+
43
+
44
+ == Usage
45
+
46
+ Just designate a textarea input <tt>as: :ace</tt>.
47
+
48
+ <%= simple_form_for @user do |f| %>
49
+ <%= f.input :code, as::ace %>
50
+ <% end %>
51
+
52
+ === Options
53
+
54
+ Set the <tt>mode</tt>, <tt>theme</tt>, and <tt>height</tt> by passing them as <tt>data-</tt> attributes.
55
+ data: { ace_mode: 'html', ace_theme: 'carto_light', ace_height: '600' }
56
+
57
+ If you would like to change the defaults, run the following to generate an initializer where you can set your own defaults.
58
+ % rails g simple_ace_input:config
59
+
60
+ === Notes
61
+
62
+ I have not included any of the worker functionality in this gem because I have found it to be a bit finicky and more trouble than it's worth.
63
+
64
+ == TODOs
65
+
66
+ * This gem has zero testing coverage. {SAD TROMBONE}[http://www.sadtrombone.com/]
67
+ * Make more configuration options available via the <tt>data-</tt> convention.
68
+
69
+ == Copyright
70
+
71
+ Copyright (c) 2012 Brian McNabb. See MIT_LICENSE for further details.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,51 @@
1
+ //= require ace/ace
2
+ //= require ace/keybinding-emacs
3
+ //= require ace/keybinding-vim
4
+ //= require ace/mode-c_cpp
5
+ //= require ace/mode-clojure
6
+ //= require ace/mode-coffee
7
+ //= require ace/mode-csharp
8
+ //= require ace/mode-css
9
+ //= require ace/mode-groovy
10
+ //= require ace/mode-html
11
+ //= require ace/mode-java
12
+ //= require ace/mode-javascript
13
+ //= require ace/mode-json
14
+ //= require ace/mode-latex
15
+ //= require ace/mode-lua
16
+ //= require ace/mode-markdown
17
+ //= require ace/mode-ocaml
18
+ //= require ace/mode-perl
19
+ //= require ace/mode-php
20
+ //= require ace/mode-python
21
+ //= require ace/mode-ruby
22
+ //= require ace/mode-scad
23
+ //= require ace/mode-scala
24
+ //= require ace/mode-scss
25
+ //= require ace/mode-svg
26
+ //= require ace/mode-textile
27
+ //= require ace/mode-xml
28
+ //= require ace/theme-carto_light
29
+ //= require ace/theme-clouds
30
+ //= require ace/theme-clouds_midnight
31
+ //= require ace/theme-cobalt
32
+ //= require ace/theme-crimson_editor
33
+ //= require ace/theme-dawn
34
+ //= require ace/theme-eclipse
35
+ //= require ace/theme-idle_fingers
36
+ //= require ace/theme-kr_theme
37
+ //= require ace/theme-merbivore
38
+ //= require ace/theme-merbivore_soft
39
+ //= require ace/theme-mono_industrial
40
+ //= require ace/theme-monokai
41
+ //= require ace/theme-pastel_on_dark
42
+ //= require ace/theme-solarized_dark
43
+ //= require ace/theme-solarized_light
44
+ //= require ace/theme-tomorrow
45
+ //= require ace/theme-tomorrow_night
46
+ //= require ace/theme-tomorrow_night_blue
47
+ //= require ace/theme-tomorrow_night_bright
48
+ //= require ace/theme-tomorrow_night_eighties
49
+ //= require ace/theme-twilight
50
+ //= require ace/theme-vibrant_ink
51
+ //= require simple_ace_input/controller
@@ -0,0 +1,35 @@
1
+ class AceInput
2
+ constructor: ->
3
+ @editor = ace.edit("input")
4
+ @session = @editor.getSession()
5
+ @renderer = @editor.renderer
6
+ @textarea = $('textarea.ace')
7
+ @setOptions()
8
+ @updateMode()
9
+ @updateTheme()
10
+ @bindTextarea()
11
+
12
+ setOptions: =>
13
+ @renderer.setShowPrintMargin false
14
+ @renderer.setHScrollBarAlwaysVisible false
15
+ @session.setUseWorker false
16
+ @session.setTabSize 2
17
+ @session.setUseSoftTabs true
18
+ @session.setFoldStyle "markbeginend"
19
+
20
+ updateMode: (mode = @textarea.data('ace-mode'))=>
21
+ if mode
22
+ mode = require("ace/mode/#{mode}").Mode
23
+ @session.setMode new mode()
24
+
25
+ updateTheme: (theme = @textarea.data('ace-theme'))=>
26
+ if theme
27
+ @editor.setTheme "ace/theme/#{theme}"
28
+
29
+ bindTextarea: =>
30
+ ace = @
31
+ ace.session.setValue ace.textarea.val()
32
+ ace.session.on "change", ->
33
+ ace.textarea.val ace.session.getValue()
34
+
35
+ window.AceInput = AceInput
@@ -0,0 +1,18 @@
1
+ class AceInput < SimpleForm::Inputs::Base
2
+
3
+ def input
4
+ ace = options.delete :ace
5
+ mode = ace[:mode] || SimpleAceInput.config.mode
6
+ theme = ace[:theme] || SimpleAceInput.config.theme
7
+ height = ace[:height] || SimpleAceInput.config.height
8
+
9
+ input_html_options.merge!({ data: { ace_mode: mode, ace_theme: theme }, hidden: true})
10
+ base_styles = "position: relative; height: #{height}px;"
11
+ target = [object_name, attribute_name].join('_')
12
+
13
+ out = ''
14
+ out << @builder.text_area(attribute_name, input_html_options)
15
+ out << template.content_tag(:div, '', id: 'input', style: base_styles, data: { target: target })
16
+ out.html_safe
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ module SimpleAceInput
2
+ module Generators
3
+ class ConfigGenerator < Rails::Generators::Base
4
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
5
+
6
+ def copy_config_file
7
+ template 'simple_ace_input.rb', 'config/initializers/simple_ace_input.rb'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ SimpleAceInput.setup do |config|
2
+ #config.theme = 'blank'
3
+ #config.mode = 'html'
4
+ #config.height = 600
5
+ end
@@ -0,0 +1,5 @@
1
+ require "simple_ace_input/config"
2
+ require "simple_ace_input/engine"
3
+
4
+ module SimpleAceInput
5
+ end
@@ -0,0 +1,35 @@
1
+ require 'active_support/configurable'
2
+
3
+ module SimpleAceInput
4
+
5
+ def self.setup(&block)
6
+ yield @config ||= SimpleAceInput::Configuration.new
7
+ end
8
+
9
+ def self.config
10
+ @config
11
+ end
12
+
13
+
14
+ class Configuration
15
+ include ActiveSupport::Configurable
16
+ config_accessor :mode
17
+ config_accessor :theme
18
+ config_accessor :height
19
+ config_accessor :precompile
20
+
21
+ def param_name
22
+ config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name
23
+ end
24
+
25
+ writer, line = 'def param_name=(value); config.param_name = value; end', __LINE__
26
+ singleton_class.class_eval writer, __FILE__, line
27
+ class_eval writer, __FILE__, line
28
+ end
29
+
30
+ setup do |config|
31
+ config.mode = 'html'
32
+ config.theme = 'carto_light'
33
+ config.height = '600'
34
+ end
35
+ end
@@ -0,0 +1,4 @@
1
+ module SimpleAceInput
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleAceInput
2
+ VERSION = "0.0.1.rc"
3
+ end
@@ -0,0 +1,23 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "simple_ace_input/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "simple_ace_input"
9
+ s.version = SimpleAceInput::VERSION
10
+ s.authors = ["Brian McNabb"]
11
+ s.email = ["brian@new-cartographers.com"]
12
+ s.homepage = "http://github.com/briandmcnabb/simple_ace_input"
13
+ s.summary = "Turns a simple_form textarea into an ACE editor."
14
+ s.description = "Turns a simple_form textarea into an ACE editor."
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "rails", "~> 3.1"
22
+ s.add_dependency "simple_form", "~> 2.0"
23
+ end