Merge pull request #772 from warpc/762-ui_and_refactoring
[refs #762] ui and refactoring for mass build; fix syntax highlight
This commit is contained in:
commit
59c1d75a36
|
@ -0,0 +1,29 @@
|
|||
$(document).ready(function() {
|
||||
var projects_list = $('.form.mass_build #projects_list');
|
||||
var repositories = $(".form.mass_build input:checkbox");
|
||||
repositories.click(function(){
|
||||
if (this.checked){
|
||||
$(this).attr('disabled',true);
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: $(this).attr('href'),
|
||||
success: function(data){
|
||||
var text = projects_list.val();
|
||||
if(text.length > 0 && text.slice(-1) != '\n') {text = text + "\n"}
|
||||
projects_list.val(text+data);
|
||||
},
|
||||
error: function(data){
|
||||
alert('Error :(') // TODO remove
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
projects_list.keyup(function(){
|
||||
if($(this).val().length == 0) {
|
||||
repositories.attr('disabled',false)
|
||||
.attr('checked', false);
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1101,13 +1101,22 @@ div#advisory_search_block div.continue_input {
|
|||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
form.mass_build section.left {
|
||||
margin-left: 50px;
|
||||
form.mass_build {
|
||||
section.left {
|
||||
margin-left: 10px;
|
||||
width: 350px;
|
||||
}
|
||||
|
||||
form.mass_build section.right {
|
||||
section.right {
|
||||
margin-right: 50px;
|
||||
}
|
||||
input[type="submit"] {
|
||||
margin: 10px 0 10px 0;
|
||||
}
|
||||
#projects_list {
|
||||
min-width:315px;
|
||||
}
|
||||
}
|
||||
|
||||
.toggle {
|
||||
overflow: hidden;
|
||||
|
|
|
@ -10,8 +10,7 @@ class Platforms::MassBuildsController < Platforms::BaseController
|
|||
skip_authorize_resource :platform, :only => [:create, :index]
|
||||
|
||||
def create
|
||||
mass_build = @platform.mass_builds.new(:repositories => params[:repositories],
|
||||
:arches => params[:arches],
|
||||
mass_build = @platform.mass_builds.new(:arches => params[:arches],
|
||||
:auto_publish => params[:auto_publish] || false,
|
||||
:projects_list => params[:projects_list])
|
||||
mass_build.user = current_user
|
||||
|
|
|
@ -97,6 +97,7 @@ class Platforms::RepositoriesController < Platforms::BaseController
|
|||
end
|
||||
|
||||
def projects_list
|
||||
render(:text => @repository.projects.map(&:name).join("\n")) && return if params[:text] == 'true'
|
||||
|
||||
owner_subquery = "
|
||||
INNER JOIN (
|
||||
|
|
|
@ -6,11 +6,10 @@ class MassBuild < ActiveRecord::Base
|
|||
scope :by_platform, lambda { |platform| where(:platform_id => platform.id) }
|
||||
scope :outdated, where('created_at < ?', Time.now + 1.day - BuildList::MAX_LIVE_TIME)
|
||||
|
||||
attr_accessor :repositories, :arches
|
||||
attr_accessible :repositories, :arches, :auto_publish, :projects_list
|
||||
attr_accessor :arches
|
||||
attr_accessible :arches, :auto_publish, :projects_list
|
||||
|
||||
validates :platform_id, :arch_names, :name, :user_id, :presence => true
|
||||
validate :rep_names, :repositories, :presence => true, :if => Proc.new {|mb| mb.projects_list.blank?}
|
||||
validates :platform_id, :arch_names, :name, :user_id, :projects_list, :presence => true
|
||||
validates_inclusion_of :auto_publish, :in => [true, false]
|
||||
|
||||
after_create :build_all
|
||||
|
@ -25,26 +24,33 @@ class MassBuild < ActiveRecord::Base
|
|||
:build_error
|
||||
]
|
||||
|
||||
# ATTENTION: repositories and arches must be set before calling this method!
|
||||
def build_all
|
||||
# later with resque
|
||||
if projects_list.present?
|
||||
platform.build_from_list(
|
||||
:mass_build_id => self.id,
|
||||
:user => self.user,
|
||||
:arches => self.arches,
|
||||
:auto_publish => self.auto_publish
|
||||
)
|
||||
arches_list = arches ? Arch.where(:id => arches) : Arch.all
|
||||
auto_publish ||= false
|
||||
|
||||
projects_list.lines.each do |name|
|
||||
next if name.blank?
|
||||
name.chomp!; name.strip!
|
||||
|
||||
if project = Project.joins(:repositories).where('repositories.id in (?)', platform.repository_ids).find_by_name(name)
|
||||
begin
|
||||
return if self.reload.stop_build
|
||||
arches_list.each do |arch|
|
||||
rep = (project.repositories & platform.repositories).first
|
||||
project.build_for(platform, rep.id, user, arch, auto_publish, self.id)
|
||||
end
|
||||
rescue RuntimeError, Exception
|
||||
end
|
||||
else
|
||||
platform.build_all(
|
||||
:mass_build_id => self.id,
|
||||
:user => self.user,
|
||||
:repositories => self.repositories,
|
||||
:arches => self.arches,
|
||||
:auto_publish => self.auto_publish
|
||||
)
|
||||
MassBuild.increment_counter :missed_projects_count, id
|
||||
list = (missed_projects_list || '') << "#{name}\n"
|
||||
update_column :missed_projects_list, list
|
||||
end
|
||||
sleep 1
|
||||
end
|
||||
end
|
||||
later :build_all, :loner => true, :queue => :clone_build
|
||||
|
||||
def generate_failed_builds_list
|
||||
report = ""
|
||||
|
@ -67,10 +73,8 @@ class MassBuild < ActiveRecord::Base
|
|||
|
||||
def set_data
|
||||
if new_record?
|
||||
self.rep_names = Repository.where(:id => self.repositories).map(&:name).join(", ")
|
||||
self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{platform.name}"
|
||||
self.arch_names = Arch.where(:id => self.arches).map(&:name).join(", ")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -178,66 +178,6 @@ class Platform < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def build_all(opts={})
|
||||
# Set options to build all need
|
||||
repositories = opts[:repositories] ? self.repositories.where(:id => opts[:repositories]) : self.repositories
|
||||
arches = opts[:arches] ? Arch.where(:id => opts[:arches]) : Arch.all
|
||||
auto_publish = opts[:auto_publish] || false
|
||||
user = opts[:user]
|
||||
mass_build_id = opts[:mass_build_id]
|
||||
mass_build = MassBuild.find mass_build_id
|
||||
|
||||
repositories.each do |rep|
|
||||
rep.projects.find_in_batches(:batch_size => 2) do |group|
|
||||
sleep 1
|
||||
group.each do |p|
|
||||
arches.map(&:name).each do |arch|
|
||||
begin
|
||||
return if mass_build.reload.stop_build
|
||||
p.build_for(self, rep.id, user, arch, auto_publish, mass_build_id)
|
||||
rescue RuntimeError, Exception
|
||||
# p.async(:build_for, self, user, arch, auto_publish, mass_build_id) # TODO need this?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
later :build_all, :loner => true, :queue => :clone_build
|
||||
|
||||
def build_from_list(opts={})
|
||||
mass_build = MassBuild.find opts[:mass_build_id]
|
||||
arches = opts[:arches] ? Arch.where(:id => opts[:arches]) : Arch.all
|
||||
auto_publish = opts[:auto_publish] || false
|
||||
user = opts[:user]
|
||||
|
||||
mass_build.projects_list.lines.each do |name|
|
||||
name.chomp!; name.strip!
|
||||
|
||||
project = ""
|
||||
Project.where(:name => name).each do |pr|
|
||||
project = pr if (pr.repository_ids & self.repository_ids).present?
|
||||
end
|
||||
|
||||
if project
|
||||
begin
|
||||
return if mass_build.reload.stop_build
|
||||
arches.map(&:name).each do |arch|
|
||||
rep = (project.repositories & self.repositories).first
|
||||
project.build_for(self, rep.id, user, arch, auto_publish, mass_build.id)
|
||||
end
|
||||
rescue RuntimeError, Exception
|
||||
end
|
||||
else
|
||||
MassBuild.increment_counter :missed_projects_count, mass_build.id
|
||||
list = (mass_build.missed_projects_list || '') << "#{name}\n"
|
||||
mass_build.update_column :missed_projects_list, list
|
||||
end
|
||||
sleep 1
|
||||
end
|
||||
end
|
||||
later :build_from_list, :loner => true, :queue => :clone_build
|
||||
|
||||
def destroy
|
||||
with_skip {super} # avoid cascade XML RPC requests
|
||||
end
|
||||
|
|
|
@ -124,14 +124,13 @@ class Project < ActiveRecord::Base
|
|||
#path #share by NFS
|
||||
end
|
||||
|
||||
def build_for(platform, repository_id, user, arch = 'i586', auto_publish = false, mass_build_id = nil, priority = 0)
|
||||
def build_for(platform, repository_id, user, arch = Arch.find_by_name('i586'), auto_publish = false, mass_build_id = nil, priority = 0)
|
||||
# Select main and project platform repository(contrib, non-free and etc)
|
||||
# If main does not exist, will connect only project platform repository
|
||||
# If project platform repository is main, only main will be connect
|
||||
main_rep_id = platform.repositories.find_by_name('main').try(:id)
|
||||
build_reps_ids = [main_rep_id, repository_id].compact.uniq
|
||||
|
||||
arch = Arch.find_by_name(arch) if arch.acts_like?(:string)
|
||||
build_lists.create do |bl|
|
||||
bl.save_to_platform = platform
|
||||
bl.build_for_platform = platform
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
%h3=t("layout.mass_builds.repositories")
|
||||
-@platform.repositories.each do |rep|
|
||||
.both
|
||||
=check_box_tag "repositories[]", rep.id, (params[:repositories]||[]).include?(rep.id.to_s), :id => "repositories_#{rep.id}", :href => "#{projects_list_platform_repository_path(@platform, rep)}?text=true"
|
||||
=label_tag "repositories_#{rep.id}", rep.name
|
||||
%h3=t("layout.mass_builds.projects_list")
|
||||
=text_area_tag :projects_list, nil
|
||||
|
|
@ -3,13 +3,7 @@
|
|||
|
||||
= form_for :build, :url => platform_mass_builds_path(@platform), :html => { :class => 'form mass_build', :method => :post } do |f|
|
||||
%section.left
|
||||
%h3= t("layout.mass_builds.repositories")
|
||||
- @platform.repositories.each do |rep|
|
||||
.both
|
||||
= check_box_tag "repositories[]", rep.id, (params[:repositories]||[]).include?(rep.id.to_s), :id => "repositories_#{rep.id}"
|
||||
= label_tag "repositories_#{rep.id}", rep.name
|
||||
%h3= t("layout.mass_builds.projects_list")
|
||||
= text_area_tag :projects_list, nil
|
||||
=render 'repos_or_list_choice'
|
||||
%br
|
||||
= f.submit t("layout.projects.build_button")
|
||||
%section.right
|
||||
|
|
|
@ -13,7 +13,8 @@ Mime::Type.register "text/plain", 'patch'
|
|||
["text/x-rpm-spec", ['spec'], '8bit'],
|
||||
["text/x-csrc", ['h', 'c'], '8bit'],
|
||||
["text/x-c++src", ['cpp'], '8bit'],
|
||||
["text/x-diff", ['diff'], '8bit']
|
||||
["text/x-diff", ['diff'], '8bit'],
|
||||
["text/x-markdown", ['md'], '8bit']
|
||||
].each do |type|
|
||||
MIME::Types.add MIME::Type.from_array(type)
|
||||
end
|
||||
|
|
|
@ -22,4 +22,3 @@ en:
|
|||
user: User
|
||||
auto_publish: Auto Publish
|
||||
repositories: Repositories
|
||||
rep_names: Repositories
|
||||
|
|
|
@ -22,4 +22,3 @@ ru:
|
|||
user: Пользователь
|
||||
auto_publish: Авто Публикация
|
||||
repositories: Репозитории
|
||||
rep_names: Репозитории
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class RemoveRepNamesFromMassBuild < ActiveRecord::Migration
|
||||
def change
|
||||
remove_column :mass_builds, :rep_names
|
||||
end
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
class AddIndexes < ActiveRecord::Migration
|
||||
def change
|
||||
add_index :project_to_repositories, [:repository_id, :project_id], :unique => true
|
||||
add_index :repositories, :platform_id
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20121206143724) do
|
||||
ActiveRecord::Schema.define(:version => 20121211132948) do
|
||||
|
||||
create_table "activity_feeds", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
|
@ -250,7 +250,6 @@ ActiveRecord::Schema.define(:version => 20121206143724) do
|
|||
t.integer "build_started_count", :default => 0, :null => false
|
||||
t.integer "build_publish_count", :default => 0, :null => false
|
||||
t.integer "build_error_count", :default => 0, :null => false
|
||||
t.string "rep_names"
|
||||
t.boolean "stop_build", :default => false, :null => false
|
||||
t.text "projects_list"
|
||||
t.integer "missed_projects_count", :default => 0, :null => false
|
||||
|
@ -330,6 +329,8 @@ ActiveRecord::Schema.define(:version => 20121206143724) do
|
|||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "project_to_repositories", ["repository_id", "project_id"], :name => "index_project_to_repositories_on_repository_id_and_project_id", :unique => true
|
||||
|
||||
create_table "projects", :force => true do |t|
|
||||
t.string "name"
|
||||
t.datetime "created_at", :null => false
|
||||
|
@ -403,6 +404,8 @@ ActiveRecord::Schema.define(:version => 20121206143724) do
|
|||
t.boolean "publish_without_qa", :default => true
|
||||
end
|
||||
|
||||
add_index "repositories", ["platform_id"], :name => "index_repositories_on_platform_id"
|
||||
|
||||
create_table "settings_notifiers", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
t.boolean "can_notify", :default => true
|
||||
|
|
|
@ -37,7 +37,7 @@ shared_examples_for 'mass_build platform owner' do
|
|||
Platform.update_all("platform_type = 'personal'")
|
||||
end
|
||||
|
||||
[:cancel, :failed_builds_list, :create].each do |action|
|
||||
[:cancel, :get_list, :create].each do |action|
|
||||
it "should not be able to perform #{ action } action" do
|
||||
get action, :platform_id => @platform, :id => @mass_build.id
|
||||
response.should redirect_to(forbidden_path)
|
||||
|
@ -54,7 +54,7 @@ shared_examples_for 'mass_build platform reader' do
|
|||
end
|
||||
end
|
||||
|
||||
[:cancel, :failed_builds_list].each do |action|
|
||||
[:cancel, :get_list].each do |action|
|
||||
it "should not be able to perform #{ action } action" do
|
||||
get action, :platform_id => @platform, :id => @mass_build.id
|
||||
response.should redirect_to(forbidden_path)
|
||||
|
@ -81,14 +81,17 @@ describe Platforms::MassBuildsController do
|
|||
@repository = FactoryGirl.create(:repository, :platform => @platform)
|
||||
@personal_platform = FactoryGirl.create(:platform, :platform_type => 'personal')
|
||||
@user = FactoryGirl.create(:user)
|
||||
project = FactoryGirl.create(:project, :owner => @user)
|
||||
@repository.projects << project
|
||||
|
||||
@create_params = {
|
||||
:platform_id => @platform,
|
||||
:repositories => [@platform.repositories.first.id],
|
||||
:projects_list => @repository.projects.map(&:name).join("\n"),
|
||||
:arches => [Arch.first.id],
|
||||
:auto_publish => true
|
||||
}
|
||||
|
||||
@mass_build = FactoryGirl.create(:mass_build, :platform => @platform, :user => @user)
|
||||
@mass_build = FactoryGirl.create(:mass_build, :platform => @platform, :user => @user, :projects_list => project.name)
|
||||
end
|
||||
|
||||
context 'for guest' do
|
||||
|
@ -99,8 +102,8 @@ describe Platforms::MassBuildsController do
|
|||
end
|
||||
end
|
||||
|
||||
it "should not be able to perform failed_builds_list action" do
|
||||
get :failed_builds_list, :platform_id => @platform, :id => @mass_build
|
||||
it "should not be able to get failed builds list" do
|
||||
get :get_list, :platform_id => @platform, :id => @mass_build, :kind => 'failed_builds_list'
|
||||
response.should redirect_to(new_user_session_path)
|
||||
end
|
||||
|
||||
|
@ -161,4 +164,3 @@ describe Platforms::MassBuildsController do
|
|||
it_should_behave_like 'mass_build platform reader'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ FactoryGirl.define do
|
|||
association :platform
|
||||
#name FactoryGirl.generate(:name)
|
||||
association :user
|
||||
repositories { |mb| [ mb.platform.repositories.first.id ] }
|
||||
projects_list "first"
|
||||
arches { [ Arch.first.id ] }
|
||||
auto_publish true
|
||||
stop_build false
|
||||
|
|
|
@ -176,14 +176,14 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
|
|||
return "string";
|
||||
}
|
||||
|
||||
CodeMirror.defineMIME("text/x-csrc", {
|
||||
CodeMirror.defineMIME("application/x-csrc", {
|
||||
name: "clike",
|
||||
keywords: words(cKeywords),
|
||||
blockKeywords: words("case do else for if switch while struct"),
|
||||
atoms: words("null"),
|
||||
hooks: {"#": cppHook}
|
||||
});
|
||||
CodeMirror.defineMIME("text/x-c++src", {
|
||||
CodeMirror.defineMIME("application/x-c++src", {
|
||||
name: "clike",
|
||||
keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " +
|
||||
"static_cast typeid catch operator template typename class friend private " +
|
||||
|
@ -193,7 +193,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
|
|||
atoms: words("true false null"),
|
||||
hooks: {"#": cppHook}
|
||||
});
|
||||
CodeMirror.defineMIME("text/x-java", {
|
||||
CodeMirror.defineMIME("application/x-java", {
|
||||
name: "clike",
|
||||
keywords: words("abstract assert boolean break byte case catch char class const continue default " +
|
||||
"do double else enum extends final finally float for goto if implements import " +
|
||||
|
@ -209,7 +209,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
|
|||
}
|
||||
}
|
||||
});
|
||||
CodeMirror.defineMIME("text/x-csharp", {
|
||||
CodeMirror.defineMIME("application/x-csharp", {
|
||||
name: "clike",
|
||||
keywords: words("abstract as base bool break byte case catch char checked class const continue decimal" +
|
||||
" default delegate do double else enum event explicit extern finally fixed float for" +
|
||||
|
|
|
@ -205,3 +205,4 @@ CodeMirror.defineMode("clojure", function (config, mode) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-clojure", "clojure");
|
||||
CodeMirror.defineMIME("application/x-clojure", "clojure");
|
||||
|
|
|
@ -339,3 +339,4 @@ CodeMirror.defineMode('coffeescript', function(conf) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME('text/x-coffeescript', 'coffeescript');
|
||||
CodeMirror.defineMIME('application/x-coffeescript', 'coffeescript');
|
||||
|
|
|
@ -122,3 +122,4 @@ CodeMirror.defineMode("css", function(config) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/css", "css");
|
||||
CodeMirror.defineMIME('application/x-coffeescript', 'css');
|
|
@ -11,3 +11,4 @@ CodeMirror.defineMode("diff", function() {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-diff", "diff");
|
||||
CodeMirror.defineMIME("application/x-diff", "diff");
|
||||
|
|
|
@ -170,3 +170,4 @@ CodeMirror.defineMode("go", function(config, parserConfig) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-go", "go");
|
||||
CodeMirror.defineMIME("application/x-go", "go");
|
||||
|
|
|
@ -208,3 +208,4 @@ CodeMirror.defineMode("groovy", function(config, parserConfig) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-groovy", "groovy");
|
||||
CodeMirror.defineMIME("application/x-groovy", "groovy");
|
||||
|
|
|
@ -240,3 +240,4 @@ CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-haskell", "haskell");
|
||||
CodeMirror.defineMIME("application/x-haskell", "haskell");
|
||||
|
|
|
@ -81,3 +81,4 @@ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/html", "htmlmixed");
|
||||
CodeMirror.defineMIME("application/html", "htmlmixed");
|
||||
|
|
|
@ -357,4 +357,5 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/javascript", "javascript");
|
||||
CodeMirror.defineMIME("application/javascript", "javascript");
|
||||
CodeMirror.defineMIME("application/json", {name: "javascript", json: true});
|
||||
|
|
|
@ -138,3 +138,4 @@ CodeMirror.defineMode("lua", function(config, parserConfig) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-lua", "lua");
|
||||
CodeMirror.defineMIME("application/x-lua", "lua");
|
||||
|
|
|
@ -240,3 +240,4 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-markdown", "markdown");
|
||||
CodeMirror.defineMIME("application/x-markdown", "markdown");
|
||||
|
|
|
@ -186,3 +186,4 @@ CodeMirror.defineMode("mysql", function(config) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-mysql", "mysql");
|
||||
CodeMirror.defineMIME("application/x-mysql", "mysql");
|
||||
|
|
|
@ -136,3 +136,4 @@ CodeMirror.defineMode("pascal", function(config) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-pascal", "pascal");
|
||||
CodeMirror.defineMIME("application/x-pascal", "pascal");
|
||||
|
|
|
@ -778,6 +778,7 @@ CodeMirror.defineMode("perl",function(config,parserConfig){
|
|||
electricChars:"{}"}});
|
||||
|
||||
CodeMirror.defineMIME("text/x-perl", "perl");
|
||||
CodeMirror.defineMIME("application/x-perl", "perl");
|
||||
|
||||
// it's like "peek", but need for look-ahead or look-behind if index < 0
|
||||
CodeMirror.StringStream.prototype.look=function(c){
|
||||
|
|
|
@ -118,4 +118,5 @@
|
|||
CodeMirror.defineMIME("application/x-httpd-php", "php");
|
||||
CodeMirror.defineMIME("application/x-httpd-php-open", {name: "php", startOpen: true});
|
||||
CodeMirror.defineMIME("text/x-php", phpConfig);
|
||||
CodeMirror.defineMIME("application/x-php", phpConfig);
|
||||
})();
|
||||
|
|
|
@ -207,7 +207,7 @@ CodeMirror.defineMode("plsql", function(config, parserConfig) {
|
|||
"verify version " +
|
||||
"wrap";
|
||||
|
||||
CodeMirror.defineMIME("text/x-plsql", {
|
||||
CodeMirror.defineMIME("application/x-plsql", {
|
||||
name: "plsql",
|
||||
keywords: keywords(cKeywords),
|
||||
functions: keywords(cFunctions),
|
||||
|
|
|
@ -338,3 +338,4 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-python", "python");
|
||||
CodeMirror.defineMIME("application/x-python", "python");
|
||||
|
|
|
@ -139,3 +139,4 @@ CodeMirror.defineMode("r", function(config) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-rsrc", "r");
|
||||
CodeMirror.defineMIME("application/x-rsrc", "r");
|
||||
|
|
|
@ -17,3 +17,4 @@ CodeMirror.defineMode("changes", function(config, modeConfig) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-rpm-changes", "changes");
|
||||
CodeMirror.defineMIME("application/x-rpm-changes", "changes");
|
||||
|
|
|
@ -64,3 +64,4 @@ CodeMirror.defineMode("spec", function(config, modeConfig) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-rpm-spec", "spec");
|
||||
CodeMirror.defineMIME("application/x-rpm-spec", "spec");
|
||||
|
|
|
@ -324,3 +324,4 @@ CodeMirror.defineMode('rst', function(config, options) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-rst", "rst");
|
||||
CodeMirror.defineMIME("application/x-rst", "rst");
|
||||
|
|
|
@ -197,4 +197,5 @@ CodeMirror.defineMode("ruby", function(config, parserConfig) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-ruby", "ruby");
|
||||
CodeMirror.defineMIME("application/x-ruby", "ruby");
|
||||
|
||||
|
|
|
@ -430,3 +430,4 @@ CodeMirror.defineMode("rust", function() {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-rustsrc", "rust");
|
||||
CodeMirror.defineMIME("application/x-rustsrc", "rust");
|
||||
|
|
|
@ -200,3 +200,4 @@ CodeMirror.defineMode("scheme", function (config, mode) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-scheme", "scheme");
|
||||
CodeMirror.defineMIME("application/x-scheme", "scheme");
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
CodeMirror.defineMode('shell', function(config) {
|
||||
|
||||
var words = {};
|
||||
function define(style, string) {
|
||||
var split = string.split(' ');
|
||||
for(var i = 0; i < split.length; i++) {
|
||||
words[split[i]] = style;
|
||||
}
|
||||
};
|
||||
|
||||
// Atoms
|
||||
define('atom', 'true false');
|
||||
|
||||
// Keywords
|
||||
define('keyword', 'if then do else elif while until for in esac fi fin ' +
|
||||
'fil done exit set unset export function');
|
||||
|
||||
// Commands
|
||||
define('builtin', 'ab awk bash beep cat cc cd chown chmod chroot clear cp ' +
|
||||
'curl cut diff echo find gawk gcc get git grep kill killall ln ls make ' +
|
||||
'mkdir openssl mv nc node npm ping ps restart rm rmdir sed service sh ' +
|
||||
'shopt shred source sort sleep ssh start stop su sudo tee telnet top ' +
|
||||
'touch vi vim wall wc wget who write yes zsh');
|
||||
|
||||
function tokenBase(stream, state) {
|
||||
|
||||
var sol = stream.sol();
|
||||
var ch = stream.next();
|
||||
|
||||
if (ch === '\'' || ch === '"' || ch === '`') {
|
||||
state.tokens.unshift(tokenString(ch));
|
||||
return tokenize(stream, state);
|
||||
}
|
||||
if (ch === '#') {
|
||||
if (sol && stream.eat('!')) {
|
||||
stream.skipToEnd();
|
||||
return 'meta'; // 'comment'?
|
||||
}
|
||||
stream.skipToEnd();
|
||||
return 'comment';
|
||||
}
|
||||
if (ch === '$') {
|
||||
state.tokens.unshift(tokenDollar);
|
||||
return tokenize(stream, state);
|
||||
}
|
||||
if (ch === '+' || ch === '=') {
|
||||
return 'operator';
|
||||
}
|
||||
if (ch === '-') {
|
||||
stream.eat('-');
|
||||
stream.eatWhile(/\w/);
|
||||
return 'attribute';
|
||||
}
|
||||
if (/\d/.test(ch)) {
|
||||
stream.eatWhile(/\d/);
|
||||
if(!/\w/.test(stream.peek())) {
|
||||
return 'number';
|
||||
}
|
||||
}
|
||||
stream.eatWhile(/\w/);
|
||||
var cur = stream.current();
|
||||
if (stream.peek() === '=' && /\w+/.test(cur)) return 'def';
|
||||
return words.hasOwnProperty(cur) ? words[cur] : null;
|
||||
}
|
||||
|
||||
function tokenString(quote) {
|
||||
return function(stream, state) {
|
||||
var next, end = false, escaped = false;
|
||||
while ((next = stream.next()) != null) {
|
||||
if (next === quote && !escaped) {
|
||||
end = true;
|
||||
break;
|
||||
}
|
||||
if (next === '$' && !escaped && quote !== '\'') {
|
||||
escaped = true;
|
||||
stream.backUp(1);
|
||||
state.tokens.unshift(tokenDollar);
|
||||
break;
|
||||
}
|
||||
escaped = !escaped && next === '\\';
|
||||
}
|
||||
if (end || !escaped) {
|
||||
state.tokens.shift();
|
||||
}
|
||||
return (quote === '`' || quote === ')' ? 'quote' : 'string');
|
||||
};
|
||||
};
|
||||
|
||||
var tokenDollar = function(stream, state) {
|
||||
if (state.tokens.length > 1) stream.eat('$');
|
||||
var ch = stream.next(), hungry = /\w/;
|
||||
if (ch === '{') hungry = /[^}]/;
|
||||
if (ch === '(') {
|
||||
state.tokens[0] = tokenString(')');
|
||||
return tokenize(stream, state);
|
||||
}
|
||||
if (!/\d/.test(ch)) {
|
||||
stream.eatWhile(hungry);
|
||||
stream.eat('}');
|
||||
}
|
||||
state.tokens.shift();
|
||||
return 'def';
|
||||
};
|
||||
|
||||
function tokenize(stream, state) {
|
||||
return (state.tokens[0] || tokenBase) (stream, state);
|
||||
};
|
||||
|
||||
return {
|
||||
startState: function() {return {tokens:[]};},
|
||||
token: function(stream, state) {
|
||||
if (stream.eatSpace()) return null;
|
||||
return tokenize(stream, state);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME('text/x-sh', 'shell');
|
||||
CodeMirror.defineMIME('application/x-sh', 'shell');
|
|
@ -137,3 +137,4 @@ CodeMirror.defineMode('smalltalk', function(config, modeConfig) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME('text/x-stsrc', {name: 'smalltalk'});
|
||||
CodeMirror.defineMIME('application/x-stsrc', {name: 'smalltalk'});
|
||||
|
|
|
@ -165,3 +165,4 @@ CodeMirror.defineMode("stex", function(cmCfg, modeCfg)
|
|||
|
||||
|
||||
CodeMirror.defineMIME("text/x-stex", "stex");
|
||||
CodeMirror.defineMIME("application/x-stex", "stex");
|
||||
|
|
|
@ -371,4 +371,5 @@ CodeMirror.defineMode("tiddlywiki", function (config, parserConfig) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-tiddlywiki", "tiddlywiki");
|
||||
CodeMirror.defineMIME("application/x-tiddlywiki", "tiddlywiki");
|
||||
//}}}
|
||||
|
|
|
@ -144,3 +144,4 @@ CodeMirror.defineMode("velocity", function(config) {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/velocity", "velocity");
|
||||
CodeMirror.defineMIME("application/velocity", "velocity");
|
||||
|
|
|
@ -184,7 +184,7 @@ CodeMirror.defineMode("verilog", function(config, parserConfig) {
|
|||
return "string";
|
||||
}
|
||||
|
||||
CodeMirror.defineMIME("text/x-verilog", {
|
||||
CodeMirror.defineMIME("application/x-verilog", {
|
||||
name: "verilog",
|
||||
keywords: words(verilogKeywords),
|
||||
blockKeywords: words(verilogBlockKeywords),
|
||||
|
|
|
@ -256,5 +256,6 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
|
|||
};
|
||||
});
|
||||
|
||||
CodeMirror.defineMIME("application/xml", "xml");
|
||||
//CodeMirror.defineMIME("application/xml", "xml");
|
||||
CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
|
||||
CodeMirror.defineMIME("application/html", {name: "xml", htmlMode: true});
|
||||
|
|
|
@ -93,3 +93,4 @@ CodeMirror.defineMode("yaml", function() {
|
|||
});
|
||||
|
||||
CodeMirror.defineMIME("text/x-yaml", "yaml");
|
||||
CodeMirror.defineMIME("application/x-yaml", "yaml");
|
||||
|
|
|
@ -815,4 +815,3 @@ a.badge:hover {
|
|||
.badge-inverse[href] {
|
||||
background-color: #1a1a1a;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue