summaryrefslogtreecommitdiff
path: root/public/vendor/codemirror/mode/puppet
diff options
context:
space:
mode:
authorWu Cheng-Han2015-05-04 15:53:29 +0800
committerWu Cheng-Han2015-05-04 15:53:29 +0800
commit4b0ca55eb79e963523eb6c8197825e9e8ae904e2 (patch)
tree574f3923af77b37b41dbf1b00bcd7827ef724a28 /public/vendor/codemirror/mode/puppet
parent61eb11d23c65c9e5c493c67d055f785cbec139e2 (diff)
First commit, version 0.2.7
Diffstat (limited to 'public/vendor/codemirror/mode/puppet')
-rwxr-xr-xpublic/vendor/codemirror/mode/puppet/index.html121
-rwxr-xr-xpublic/vendor/codemirror/mode/puppet/puppet.js220
2 files changed, 341 insertions, 0 deletions
diff --git a/public/vendor/codemirror/mode/puppet/index.html b/public/vendor/codemirror/mode/puppet/index.html
new file mode 100755
index 00000000..5614c369
--- /dev/null
+++ b/public/vendor/codemirror/mode/puppet/index.html
@@ -0,0 +1,121 @@
+<!doctype html>
+
+<title>CodeMirror: Puppet mode</title>
+<meta charset="utf-8"/>
+<link rel=stylesheet href="../../doc/docs.css">
+
+<link rel="stylesheet" href="../../lib/codemirror.css">
+<script src="../../lib/codemirror.js"></script>
+<script src="../../addon/edit/matchbrackets.js"></script>
+<script src="puppet.js"></script>
+<style>
+ .CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
+ .cm-s-default span.cm-arrow { color: red; }
+ </style>
+<div id=nav>
+ <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
+
+ <ul>
+ <li><a href="../../index.html">Home</a>
+ <li><a href="../../doc/manual.html">Manual</a>
+ <li><a href="https://github.com/codemirror/codemirror">Code</a>
+ </ul>
+ <ul>
+ <li><a href="../index.html">Language modes</a>
+ <li><a class=active href="#">Puppet</a>
+ </ul>
+</div>
+
+<article>
+<h2>Puppet mode</h2>
+<form><textarea id="code" name="code">
+# == Class: automysqlbackup
+#
+# Puppet module to install AutoMySQLBackup for periodic MySQL backups.
+#
+# class { 'automysqlbackup':
+# backup_dir => '/mnt/backups',
+# }
+#
+
+class automysqlbackup (
+ $bin_dir = $automysqlbackup::params::bin_dir,
+ $etc_dir = $automysqlbackup::params::etc_dir,
+ $backup_dir = $automysqlbackup::params::backup_dir,
+ $install_multicore = undef,
+ $config = {},
+ $config_defaults = {},
+) inherits automysqlbackup::params {
+
+# Ensure valid paths are assigned
+ validate_absolute_path($bin_dir)
+ validate_absolute_path($etc_dir)
+ validate_absolute_path($backup_dir)
+
+# Create a subdirectory in /etc for config files
+ file { $etc_dir:
+ ensure => directory,
+ owner => 'root',
+ group => 'root',
+ mode => '0750',
+ }
+
+# Create an example backup file, useful for reference
+ file { "${etc_dir}/automysqlbackup.conf.example":
+ ensure => file,
+ owner => 'root',
+ group => 'root',
+ mode => '0660',
+ source => 'puppet:///modules/automysqlbackup/automysqlbackup.conf',
+ }
+
+# Add files from the developer
+ file { "${etc_dir}/AMB_README":
+ ensure => file,
+ source => 'puppet:///modules/automysqlbackup/AMB_README',
+ }
+ file { "${etc_dir}/AMB_LICENSE":
+ ensure => file,
+ source => 'puppet:///modules/automysqlbackup/AMB_LICENSE',
+ }
+
+# Install the actual binary file
+ file { "${bin_dir}/automysqlbackup":
+ ensure => file,
+ owner => 'root',
+ group => 'root',
+ mode => '0755',
+ source => 'puppet:///modules/automysqlbackup/automysqlbackup',
+ }
+
+# Create the base backup directory
+ file { $backup_dir:
+ ensure => directory,
+ owner => 'root',
+ group => 'root',
+ mode => '0755',
+ }
+
+# If you'd like to keep your config in hiera and pass it to this class
+ if !empty($config) {
+ create_resources('automysqlbackup::backup', $config, $config_defaults)
+ }
+
+# If using RedHat family, must have the RPMforge repo's enabled
+ if $install_multicore {
+ package { ['pigz', 'pbzip2']: ensure => installed }
+ }
+
+}
+</textarea></form>
+ <script>
+ var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
+ mode: "text/x-puppet",
+ matchBrackets: true,
+ indentUnit: 4
+ });
+ </script>
+
+ <p><strong>MIME types defined:</strong> <code>text/x-puppet</code>.</p>
+
+ </article>
diff --git a/public/vendor/codemirror/mode/puppet/puppet.js b/public/vendor/codemirror/mode/puppet/puppet.js
new file mode 100755
index 00000000..e7f799f7
--- /dev/null
+++ b/public/vendor/codemirror/mode/puppet/puppet.js
@@ -0,0 +1,220 @@
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+(function(mod) {
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
+ mod(require("../../lib/codemirror"));
+ else if (typeof define == "function" && define.amd) // AMD
+ define(["../../lib/codemirror"], mod);
+ else // Plain browser env
+ mod(CodeMirror);
+})(function(CodeMirror) {
+"use strict";
+
+CodeMirror.defineMode("puppet", function () {
+ // Stores the words from the define method
+ var words = {};
+ // Taken, mostly, from the Puppet official variable standards regex
+ var variable_regex = /({)?([a-z][a-z0-9_]*)?((::[a-z][a-z0-9_]*)*::)?[a-zA-Z0-9_]+(})?/;
+
+ // Takes a string of words separated by spaces and adds them as
+ // keys with the value of the first argument 'style'
+ function define(style, string) {
+ var split = string.split(' ');
+ for (var i = 0; i < split.length; i++) {
+ words[split[i]] = style;
+ }
+ }
+
+ // Takes commonly known puppet types/words and classifies them to a style
+ define('keyword', 'class define site node include import inherits');
+ define('keyword', 'case if else in and elsif default or');
+ define('atom', 'false true running present absent file directory undef');
+ define('builtin', 'action augeas burst chain computer cron destination dport exec ' +
+ 'file filebucket group host icmp iniface interface jump k5login limit log_level ' +
+ 'log_prefix macauthorization mailalias maillist mcx mount nagios_command ' +
+ 'nagios_contact nagios_contactgroup nagios_host nagios_hostdependency ' +
+ 'nagios_hostescalation nagios_hostextinfo nagios_hostgroup nagios_service ' +
+ 'nagios_servicedependency nagios_serviceescalation nagios_serviceextinfo ' +
+ 'nagios_servicegroup nagios_timeperiod name notify outiface package proto reject ' +
+ 'resources router schedule scheduled_task selboolean selmodule service source ' +
+ 'sport ssh_authorized_key sshkey stage state table tidy todest toports tosource ' +
+ 'user vlan yumrepo zfs zone zpool');
+
+ // After finding a start of a string ('|") this function attempts to find the end;
+ // If a variable is encountered along the way, we display it differently when it
+ // is encapsulated in a double-quoted string.
+ function tokenString(stream, state) {
+ var current, prev, found_var = false;
+ while (!stream.eol() && (current = stream.next()) != state.pending) {
+ if (current === '$' && prev != '\\' && state.pending == '"') {
+ found_var = true;
+ break;
+ }
+ prev = current;
+ }
+ if (found_var) {
+ stream.backUp(1);
+ }
+ if (current == state.pending) {
+ state.continueString = false;
+ } else {
+ state.continueString = true;
+ }
+ return "string";
+ }
+
+ // Main function
+ function tokenize(stream, state) {
+ // Matches one whole word
+ var word = stream.match(/[\w]+/, false);
+ // Matches attributes (i.e. ensure => present ; 'ensure' would be matched)
+ var attribute = stream.match(/(\s+)?\w+\s+=>.*/, false);
+ // Matches non-builtin resource declarations
+ // (i.e. "apache::vhost {" or "mycustomclasss {" would be matched)
+ var resource = stream.match(/(\s+)?[\w:_]+(\s+)?{/, false);
+ // Matches virtual and exported resources (i.e. @@user { ; and the like)
+ var special_resource = stream.match(/(\s+)?[@]{1,2}[\w:_]+(\s+)?{/, false);
+
+ // Finally advance the stream
+ var ch = stream.next();
+
+ // Have we found a variable?
+ if (ch === '$') {
+ if (stream.match(variable_regex)) {
+ // If so, and its in a string, assign it a different color
+ return state.continueString ? 'variable-2' : 'variable';
+ }
+ // Otherwise return an invalid variable
+ return "error";
+ }
+ // Should we still be looking for the end of a string?
+ if (state.continueString) {
+ // If so, go through the loop again
+ stream.backUp(1);
+ return tokenString(stream, state);
+ }
+ // Are we in a definition (class, node, define)?
+ if (state.inDefinition) {
+ // If so, return def (i.e. for 'class myclass {' ; 'myclass' would be matched)
+ if (stream.match(/(\s+)?[\w:_]+(\s+)?/)) {
+ return 'def';
+ }
+ // Match the rest it the next time around
+ stream.match(/\s+{/);
+ state.inDefinition = false;
+ }
+ // Are we in an 'include' statement?
+ if (state.inInclude) {
+ // Match and return the included class
+ stream.match(/(\s+)?\S+(\s+)?/);
+ state.inInclude = false;
+ return 'def';
+ }
+ // Do we just have a function on our hands?
+ // In 'ensure_resource("myclass")', 'ensure_resource' is matched
+ if (stream.match(/(\s+)?\w+\(/)) {
+ stream.backUp(1);
+ return 'def';
+ }
+ // Have we matched the prior attribute regex?
+ if (attribute) {
+ stream.match(/(\s+)?\w+/);
+ return 'tag';
+ }
+ // Do we have Puppet specific words?
+ if (word && words.hasOwnProperty(word)) {
+ // Negates the initial next()
+ stream.backUp(1);
+ // Acutally move the stream
+ stream.match(/[\w]+/);
+ // We want to process these words differently
+ // do to the importance they have in Puppet
+ if (stream.match(/\s+\S+\s+{/, false)) {
+ state.inDefinition = true;
+ }
+ if (word == 'include') {
+ state.inInclude = true;
+ }
+ // Returns their value as state in the prior define methods
+ return words[word];
+ }
+ // Is there a match on a reference?
+ if (/(^|\s+)[A-Z][\w:_]+/.test(word)) {
+ // Negate the next()
+ stream.backUp(1);
+ // Match the full reference
+ stream.match(/(^|\s+)[A-Z][\w:_]+/);
+ return 'def';
+ }
+ // Have we matched the prior resource regex?
+ if (resource) {
+ stream.match(/(\s+)?[\w:_]+/);
+ return 'def';
+ }
+ // Have we matched the prior special_resource regex?
+ if (special_resource) {
+ stream.match(/(\s+)?[@]{1,2}/);
+ return 'special';
+ }
+ // Match all the comments. All of them.
+ if (ch == "#") {
+ stream.skipToEnd();
+ return "comment";
+ }
+ // Have we found a string?
+ if (ch == "'" || ch == '"') {
+ // Store the type (single or double)
+ state.pending = ch;
+ // Perform the looping function to find the end
+ return tokenString(stream, state);
+ }
+ // Match all the brackets
+ if (ch == '{' || ch == '}') {
+ return 'bracket';
+ }
+ // Match characters that we are going to assume
+ // are trying to be regex
+ if (ch == '/') {
+ stream.match(/.*?\//);
+ return 'variable-3';
+ }
+ // Match all the numbers
+ if (ch.match(/[0-9]/)) {
+ stream.eatWhile(/[0-9]+/);
+ return 'number';
+ }
+ // Match the '=' and '=>' operators
+ if (ch == '=') {
+ if (stream.peek() == '>') {
+ stream.next();
+ }
+ return "operator";
+ }
+ // Keep advancing through all the rest
+ stream.eatWhile(/[\w-]/);
+ // Return a blank line for everything else
+ return null;
+ }
+ // Start it all
+ return {
+ startState: function () {
+ var state = {};
+ state.inDefinition = false;
+ state.inInclude = false;
+ state.continueString = false;
+ state.pending = false;
+ return state;
+ },
+ token: function (stream, state) {
+ // Strip the spaces, but regex will account for them eitherway
+ if (stream.eatSpace()) return null;
+ // Go through the main process
+ return tokenize(stream, state);
+ }
+ };
+});
+
+CodeMirror.defineMIME("text/x-puppet", "puppet");
+
+});