Merge Variables
Text Replacement Package for Sublime Text 2 and 3
Details
Installs
- Total 2K
- Win 1K
- Mac 574
- Linux 238
Apr 2 | Apr 1 | Mar 31 | Mar 30 | Mar 29 | Mar 28 | Mar 27 | Mar 26 | Mar 25 | Mar 24 | Mar 23 | Mar 22 | Mar 21 | Mar 20 | Mar 19 | Mar 18 | Mar 17 | Mar 16 | Mar 15 | Mar 14 | Mar 13 | Mar 12 | Mar 11 | Mar 10 | Mar 9 | Mar 8 | Mar 7 | Mar 6 | Mar 5 | Mar 4 | Mar 3 | Mar 2 | Mar 1 | Feb 28 | Feb 27 | Feb 26 | Feb 25 | Feb 24 | Feb 23 | Feb 22 | Feb 21 | Feb 20 | Feb 19 | Feb 18 | Feb 17 | Feb 16 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Windows | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 3 |
Mac | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
Linux | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Readme
- Source
- raw.githubusercontent.com
Merge Variables
Text Replacement Package for Sublime Text 2 and 3
Merge Variables allows you define sets of replaceable strings. When you run the Merge Variables
command, the package expands each of the strings with a replacement. For example, you can turn this:
<a href="http://{{HOSTNAME}}/page">{{TITLE}}</a>
into:
<a href="http://www.myexamplesite.com/page">My Example Site</a>
How to Use
Creating Sets
To define the your variables and their values, open the user settings for the package. Create a "sets"
member. This member will be an object, and each of its members will be the name of a “set”. Each of the sets will also be an object containin key-value pairs for the variables and their values. Here's an example:
{
"sets": {
"mysite": {
"{{HOSTNAME}}": "www.myexamplesite.com",
"{{TITLE}}": "My Example Site"
}
}
}
Note: There's no need to use double curly braces around your variables names. This is my convention, but it isn't required. You may want to use some symbols on either side to safeguard against unwanted replacements. %PERCENTS%, [brackets], =Equals=, etc. could all be good choices.
Next you'll need to make this an active set. Add an "active_sets"
member to the user settings file. This member is a list of all of the names of sets you would like to use.
{
"active_sets": ["mysite"],
"sets": {
"mysite": {
"{{HOSTNAME}}": "www.myexamplesite.com",
"{{TITLE}}": "My Example Site"
}
}
}
Merging Variables
Once you have your variables defined, open the Command Palette (Shift + Command + P) and enter Merge Variables
.
Cascading Sets
But wait! There's more! You can define multiple sets, and merge them together. In this example, there are three sets: "mysite"
, "mysite-development"
, and "some other set we're not going to use yet"
.
{
"active_sets": ["mysite", "mysite-development"],
"sets": {
"mysite": {
"{{HOSTNAME}}": "www.myexamplesite.com",
"{{TITLE}}": "My Example Site"
},
"mysite-development": {
"{{HOSTNAME}}": "dev.myexamplesite.com"
},
"some other set we're not going to use yet": {
"{{HOSTNAME}}": "www.not-this-site.com",
"{{TITLE}}": "Won't See This Title"
}
}
}
I've specified the list of active sets as ["mysite", "mysite-development"]
. This tells the package to start wth the key-value pairs from "mysite"
first, then override those values with the ones in "mysite-development"
. Here's what happens:
{{HOSTNAME}}
is defined in both sets. The value from the last set takes precedence.{{TITLE}}
is defined in the first set, but not the second. That's okay. The value from the first carries through.- The set
"some other set we're not going to use yet"
is not in the list of active sets, so its values are ignored.
The result:
<a href="http://dev.myexamplesite.com/page">My Example Site</a>
Programatically
If you're super cool, and you write Sublime packages too, you may want to call Merge Variables
in code. When you do, you can pass the list of active sets at call time. Here's an example:
view.run_command("merge_variables", active_sets=["this_set", "that_set"])
Installation
Sublime Package Control
You can install Merge Variables using the excellent Package Control package manager for Sublime Text:
- Open “Package Control: Install Package” from the Command Palette (
Shift
+Command
+P
). - Select the “Merge Variables” option to install Merge Variables.
Git Installation
To install manually using Git, clone to your “Packages” directory.
git clone git@github.com:pjdietz/sublime-merge-variables.git "Merge Variables"
Note: Some features such as the menu command to open the default settings will not work if the package is not installed to a directory called “Merge Variables”.
Author
PJ Dietz
Copyright and license
Copyright 2013 PJ Dietz