[#369] add codemirror editor
This commit is contained in:
parent
fe96da0eea
commit
dd41f41867
2
Gemfile
2
Gemfile
|
@ -86,6 +86,8 @@ gem 'therubyracer', '~> 0.12.1', platforms: [:mri, :rbx]
|
||||||
gem 'therubyrhino', '~> 1.73.1', platforms: :jruby
|
gem 'therubyrhino', '~> 1.73.1', platforms: :jruby
|
||||||
gem 'sitemap_generator'
|
gem 'sitemap_generator'
|
||||||
|
|
||||||
|
gem 'codemirror-rails', '~> 4.0'
|
||||||
|
|
||||||
group :production do
|
group :production do
|
||||||
gem "airbrake", '~> 3.1.2'
|
gem "airbrake", '~> 3.1.2'
|
||||||
gem 'bluepill', '~> 0.0.60', require: false
|
gem 'bluepill', '~> 0.0.60', require: false
|
||||||
|
|
|
@ -122,6 +122,8 @@ GEM
|
||||||
activesupport (>= 3.0)
|
activesupport (>= 3.0)
|
||||||
cocaine (0.5.3)
|
cocaine (0.5.3)
|
||||||
climate_control (>= 0.0.3, < 1.0)
|
climate_control (>= 0.0.3, < 1.0)
|
||||||
|
codemirror-rails (4.0)
|
||||||
|
railties (>= 3.0, < 5)
|
||||||
coderay (1.1.0)
|
coderay (1.1.0)
|
||||||
coffee-rails (4.0.1)
|
coffee-rails (4.0.1)
|
||||||
coffee-script (>= 2.2.0)
|
coffee-script (>= 2.2.0)
|
||||||
|
@ -523,6 +525,7 @@ DEPENDENCIES
|
||||||
capistrano
|
capistrano
|
||||||
capistrano_colors
|
capistrano_colors
|
||||||
charlock_holmes (~> 0.6.9)
|
charlock_holmes (~> 0.6.9)
|
||||||
|
codemirror-rails (~> 4.0)
|
||||||
coffee-rails (~> 4.0.1)
|
coffee-rails (~> 4.0.1)
|
||||||
compass-rails (~> 1.1.6)
|
compass-rails (~> 1.1.6)
|
||||||
creole
|
creole
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
= javascript_include_tag 'codemirror_editor'
|
||||||
|
= stylesheet_link_tag 'codemirror_editor'
|
||||||
|
|
||||||
%h3= t("layout.projects.files_in_project")
|
%h3= t("layout.projects.files_in_project")
|
||||||
.files
|
.files
|
||||||
.l= render 'whereami'
|
.l= render 'whereami'
|
||||||
|
@ -16,3 +19,19 @@
|
||||||
= submit_tag t('layout.save'), title: t('layout.save'), data: {'disable-with' => t('layout.saving')}
|
= submit_tag t('layout.save'), title: t('layout.save'), data: {'disable-with' => t('layout.saving')}
|
||||||
= t("layout.or")
|
= t("layout.or")
|
||||||
= link_to t("layout.cancel"), blob_path(@project, @treeish, @path), class: 'button'
|
= link_to t("layout.cancel"), blob_path(@project, @treeish, @path), class: 'button'
|
||||||
|
|
||||||
|
:javascript
|
||||||
|
$(function() {
|
||||||
|
var editor = CodeMirror.fromTextArea(document.getElementById('code'), {
|
||||||
|
lineNumbers: true,
|
||||||
|
mode: '#{@blob.raw_mime_type}'
|
||||||
|
});
|
||||||
|
$(".CodeMirror").resizable({
|
||||||
|
stop: function() { editor.refresh(); },
|
||||||
|
resize: function() {
|
||||||
|
$(".CodeMirror-scroll").height($(this).height());
|
||||||
|
$(".CodeMirror-scroll").width($(this).width());
|
||||||
|
editor.refresh();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -63,7 +63,9 @@ Rosa::Application.configure do
|
||||||
config.assets.digest = true
|
config.assets.digest = true
|
||||||
|
|
||||||
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
||||||
config.assets.precompile += %w(login.css login.js reg_session.css tour.css tour.js gollum/editor/langs/*.js moment/ru.js)
|
config.assets.precompile +=
|
||||||
|
%w(login.css login.js reg_session.css tour.css tour.js gollum/editor/langs/*.js moment/ru.js
|
||||||
|
codemirror_editor.js codemirror_editor.css)
|
||||||
|
|
||||||
# Compress JavaScripts and CSS.
|
# Compress JavaScripts and CSS.
|
||||||
config.assets.js_compressor = :uglifier
|
config.assets.js_compressor = :uglifier
|
||||||
|
|
|
@ -62,7 +62,9 @@ Rosa::Application.configure do
|
||||||
config.assets.digest = true
|
config.assets.digest = true
|
||||||
|
|
||||||
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
||||||
config.assets.precompile += %w(login.css login.js reg_session.css tour.css tour.js gollum/editor/langs/*.js moment/ru.js)
|
config.assets.precompile +=
|
||||||
|
%w(login.css login.js reg_session.css tour.css tour.js gollum/editor/langs/*.js moment/ru.js
|
||||||
|
codemirror_editor.js codemirror_editor.css)
|
||||||
|
|
||||||
# Compress JavaScripts and CSS.
|
# Compress JavaScripts and CSS.
|
||||||
config.assets.js_compressor = :uglifier
|
config.assets.js_compressor = :uglifier
|
||||||
|
|
|
@ -43,61 +43,17 @@ module Grit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# def file_mime_type
|
|
||||||
# @file_mime_type ||= data.file_type(:mime_type)
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# def text?
|
|
||||||
# file_mime_type =~ /^text\// # not binary?
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# def binary?
|
|
||||||
# not text? # file_mime_type !~ /^text\//
|
|
||||||
# # s = data.split(//); ((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30 # works only for latin chars
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# def image?
|
|
||||||
# mime_type.match(/image/)
|
|
||||||
# end
|
|
||||||
|
|
||||||
DEFAULT_RAW_MIME_TYPE = MIME::Types[DEFAULT_MIME_TYPE].first
|
|
||||||
|
|
||||||
def mime_type_with_class_store
|
|
||||||
set_associated_mimes
|
|
||||||
@associated_mimes.first.simplified
|
|
||||||
end
|
|
||||||
alias_method_chain :mime_type, :class_store
|
|
||||||
|
|
||||||
attr_accessor :raw_mime_type
|
attr_accessor :raw_mime_type
|
||||||
def raw_mime_type
|
def raw_mime_type
|
||||||
set_associated_mimes
|
return @raw_mime_type if @raw_mime_type.present?
|
||||||
@raw_mime_type = @associated_mimes.first || DEFAULT_RAW_MIME_TYPE
|
if mime_type == 'text/rpm-spec'
|
||||||
|
@raw_mime_type = 'text/x-rpm-spec'
|
||||||
|
else
|
||||||
|
@raw_mime_type = Linguist::Language.detect(name, data).try(:lexer).try(:mimetypes).try(:first)
|
||||||
|
@raw_mime_type ||= DEFAULT_MIME_TYPE
|
||||||
|
@raw_mime_type.gsub!('application', 'text')
|
||||||
@raw_mime_type
|
@raw_mime_type
|
||||||
end
|
end
|
||||||
|
|
||||||
def raw_mime_types
|
|
||||||
set_associated_mimes
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
# store all associated MIME::Types inside class
|
|
||||||
def set_associated_mimes
|
|
||||||
@associated_mimes ||= []
|
|
||||||
if @associated_mimes.empty?
|
|
||||||
guesses = MIME::Types.type_for(self.name) rescue [DEFAULT_RAW_MIME_TYPE]
|
|
||||||
guesses = [DEFAULT_RAW_MIME_TYPE] if guesses.empty?
|
|
||||||
|
|
||||||
@associated_mimes = guesses.sort{|a,b| mime_sort(a, b)}
|
|
||||||
end
|
|
||||||
@associated_mimes
|
|
||||||
end
|
|
||||||
|
|
||||||
# TODO make more clever function
|
|
||||||
def mime_sort(a,b)
|
|
||||||
return 0 if a.media_type == b.media_type and a.registered? == b.registered?
|
|
||||||
return -1 if a.media_type == 'text' and !a.registered?
|
|
||||||
return 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
//= require codemirror
|
||||||
|
|
||||||
|
//= require codemirror/modes/apl
|
||||||
|
//= require codemirror/modes/asterisk
|
||||||
|
//= require codemirror/modes/clike
|
||||||
|
//= require codemirror/modes/clojure
|
||||||
|
//= require codemirror/modes/cobol
|
||||||
|
//= require codemirror/modes/coffeescript
|
||||||
|
//= require codemirror/modes/commonlisp
|
||||||
|
//= require codemirror/modes/css
|
||||||
|
//= require codemirror/modes/d
|
||||||
|
//= require codemirror/modes/diff
|
||||||
|
//= require codemirror/modes/dtd
|
||||||
|
//= require codemirror/modes/ecl
|
||||||
|
//= require codemirror/modes/eiffel
|
||||||
|
//= require codemirror/modes/erlang
|
||||||
|
//= require codemirror/modes/fortran
|
||||||
|
//= require codemirror/modes/gas
|
||||||
|
//= require codemirror/modes/gfm
|
||||||
|
//= require codemirror/modes/gherkin
|
||||||
|
//= require codemirror/modes/go
|
||||||
|
//= require codemirror/modes/groovy
|
||||||
|
//= require codemirror/modes/haml
|
||||||
|
//= require codemirror/modes/haskell
|
||||||
|
//= require codemirror/modes/haxe
|
||||||
|
//= require codemirror/modes/htmlembedded
|
||||||
|
//= require codemirror/modes/htmlmixed
|
||||||
|
//= require codemirror/modes/http
|
||||||
|
//= require codemirror/modes/jade
|
||||||
|
//= require codemirror/modes/javascript
|
||||||
|
//= require codemirror/modes/jinja2
|
||||||
|
//= require codemirror/modes/julia
|
||||||
|
//= require codemirror/modes/livescript
|
||||||
|
//= require codemirror/modes/lua
|
||||||
|
//= require codemirror/modes/markdown
|
||||||
|
//= require codemirror/modes/mirc
|
||||||
|
//= require codemirror/modes/mllike
|
||||||
|
//= require codemirror/modes/nginx
|
||||||
|
//= require codemirror/modes/ntriples
|
||||||
|
//= require codemirror/modes/octave
|
||||||
|
//= require codemirror/modes/pascal
|
||||||
|
//= require codemirror/modes/pegjs
|
||||||
|
//= require codemirror/modes/perl
|
||||||
|
//= require codemirror/modes/php
|
||||||
|
//= require codemirror/modes/pig
|
||||||
|
//= require codemirror/modes/properties
|
||||||
|
//= require codemirror/modes/puppet
|
||||||
|
//= require codemirror/modes/python
|
||||||
|
//= require codemirror/modes/q
|
||||||
|
//= require codemirror/modes/r
|
||||||
|
//= require codemirror/modes/rpm
|
||||||
|
//= require codemirror/modes/rst
|
||||||
|
//= require codemirror/modes/ruby
|
||||||
|
//= require codemirror/modes/rust
|
||||||
|
//= require codemirror/modes/sass
|
||||||
|
//= require codemirror/modes/scheme
|
||||||
|
//= require codemirror/modes/shell
|
||||||
|
//= require codemirror/modes/sieve
|
||||||
|
//= require codemirror/modes/smalltalk
|
||||||
|
//= require codemirror/modes/smarty
|
||||||
|
//= require codemirror/modes/smartymixed
|
||||||
|
//= require codemirror/modes/solr
|
||||||
|
//= require codemirror/modes/sparql
|
||||||
|
//= require codemirror/modes/sql
|
||||||
|
//= require codemirror/modes/stex
|
||||||
|
//= require codemirror/modes/tcl
|
||||||
|
//= require codemirror/modes/tiddlywiki
|
||||||
|
//= require codemirror/modes/tiki
|
||||||
|
//= require codemirror/modes/toml
|
||||||
|
//= require codemirror/modes/turtle
|
||||||
|
//= require codemirror/modes/vb
|
||||||
|
//= require codemirror/modes/vbscript
|
||||||
|
//= require codemirror/modes/velocity
|
||||||
|
//= require codemirror/modes/verilog
|
||||||
|
//= require codemirror/modes/xml
|
||||||
|
//= require codemirror/modes/xquery
|
||||||
|
//= require codemirror/modes/yaml
|
||||||
|
//= require codemirror/modes/z80
|
|
@ -0,0 +1,2 @@
|
||||||
|
@import "codemirror";
|
||||||
|
//@import "codemirror/themes/rubyblue";
|
Loading…
Reference in New Issue