turple 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +31 -14
- data/lib/turple.rb +22 -2
- data/lib/turple/interpolate.rb +1 -1
- data/lib/turple/source.rb +5 -4
- data/lib/turple/template.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MWEyNzIxNjY4MjFkZGMxNjNiMTgyZTc3YTIyNjliMzBlNjEwNjI0ZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
N2MwZTJlOGRlMTEyYzU3ZTVmNGM5MWMzMDVjZmZjMmU2YmVjZDYyOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWJkMDMwZTlkMmExZjU2YWZlZWJiMjMwMjBmNzI4NjI3NGRmZWI1ZjIyMWQ3
|
10
|
+
M2IxOGQyNjZkYjAzMTdjOTIwZTQ0NGQ3M2I3ZGIzMDE4MTdmM2UwNmE5ZTMx
|
11
|
+
OTRjOGFiMjRmZDI3NmIwYjlkNmUyMTYzYWYyNmFiN2I4Y2RhNTQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzQ2NDE1YTRjMDQ4NDRlYjU1ZTMyMWU1Njk0Y2Q2ZjkzNTE0NTJkOGMxMjIx
|
14
|
+
ZWI2ODE4NmI1NDQ2MzU4N2FjZDdjMjQwOTllMWRmZjk4Mjc2YmIzYjIyNWYx
|
15
|
+
ZTEzOTBlODRlMGRkNGE0YWMwMGMzNzYxYTk0NmVjNzc2MGY4Mjg=
|
data/README.md
CHANGED
@@ -3,11 +3,13 @@
|
|
3
3
|
[![Coverage Status](https://coveralls.io/repos/brewster1134/turple/badge.png)](https://coveralls.io/r/brewster1134/turple)
|
4
4
|
|
5
5
|
# Turple
|
6
|
+
|
6
7
|
Quick project templating, with optional cli wizard support
|
7
8
|
|
8
9
|
Turple can take a custom template and use it to bootstrap projects structures you commonly use instead of **copy/pasting** an old project and **find/replacing** to make it a new project.
|
9
10
|
|
10
11
|
### Install
|
12
|
+
|
11
13
|
```sh
|
12
14
|
gem install turple
|
13
15
|
```
|
@@ -35,14 +37,9 @@ Turple is best used from a command line, but it can be used directly in ruby as
|
|
35
37
|
|
36
38
|
Turple requires a path to a template, and an optional destination. If no destination is passed, it will put everything in a `turple` folder in your current working directory.
|
37
39
|
|
38
|
-
|
39
|
-
turple --template /path/to/template --destination my_new_project_name
|
40
|
-
|
41
|
-
# or with shorter aliases
|
42
|
-
turple -t /path/to/template -d my_new_project_name
|
43
|
-
```
|
40
|
+
Turple will scan the template, determine what data is needed to process it, and prompt you for any missing data. If you wanted to run turple without the wizard, you can put a `Turplefile` in your destination directory with the necessary data.
|
44
41
|
|
45
|
-
|
42
|
+
e.g. Assuming our template requires a single piece of information called `foo`, a Turplefile in your new project directory could look something like this.
|
46
43
|
|
47
44
|
```yaml
|
48
45
|
data:
|
@@ -65,20 +62,34 @@ data:
|
|
65
62
|
A turple template is simply a directory containing a Turplefile, and any amount of custom folders and files your project template needs. The Turplefile inside a template has different data than a destination file. It has instructions on how to prompt a user for data, and the configuration details on how the template is built. _This example uses the default turple configuration._
|
66
63
|
|
67
64
|
###### Remote Template
|
65
|
+
|
68
66
|
You can easily use remote templates directly, or share other user's templates by passing turple a remote source in addition to a template name. Simply separate the source name from the template name with 2 hashes (`##`).
|
69
67
|
|
70
68
|
Turple uses the [Sourcerer](https://github.com/brewster1134/sourcerer) gem to download remote sources to a tmp directory, so you can use any supported Sourcerer format *(including github shorthand!)*
|
71
69
|
|
72
|
-
```
|
70
|
+
```sh
|
71
|
+
# local template
|
72
|
+
turple --template /path/to/template --destination new_project_name
|
73
|
+
|
74
|
+
# local template with shorter aliases
|
75
|
+
turple -t /path/to/template -d new_project_name
|
76
|
+
|
77
|
+
# remote template (with source and template)
|
73
78
|
turple -t brewster1134/turple_templates##javascript
|
74
|
-
```
|
75
79
|
|
76
|
-
|
80
|
+
# remote template (with just template)
|
81
|
+
# this requires the source be loaded in your home Turplefile
|
82
|
+
turple -t javascript
|
83
|
+
|
84
|
+
# already turple'd project
|
85
|
+
turple -t my_old_project_name -d new_project_name
|
86
|
+
```
|
77
87
|
|
78
88
|
### Configuration
|
79
89
|
|
90
|
+
A Turple template requires a Turplefile the defines the template's configuration. It can also include a data map that describes all the data a template requires.
|
91
|
+
|
80
92
|
```yaml
|
81
|
-
name: Foo Project Template
|
82
93
|
configuration:
|
83
94
|
file_ext: turple
|
84
95
|
path_regex: '\[([A-Z_\.]+)\]'
|
@@ -87,19 +98,21 @@ configuration:
|
|
87
98
|
content_separator: .
|
88
99
|
data_map:
|
89
100
|
foo: What is the foo called?
|
101
|
+
bar: The name of the bar.
|
90
102
|
```
|
91
103
|
|
92
|
-
* `name` is just a friendly name for the template. its optional. we can use the template directory name for that.
|
93
104
|
* `configuration` has some very important details. (again, these are the defaults, so if your template does not have a custom configuration, it uses these values)
|
94
105
|
* `file_ext` is the file extension turple looks for to tell it there is content inside the file that needs processed
|
95
106
|
* `path_regex` this is a string representing a regex match to variable names
|
96
107
|
* `path_separator` this is a string representing a character(s) to seperate variables strung togehter
|
97
108
|
* `content_regex` & `content_separator` are the same as with a path, but to match file contents rather than a path.
|
98
109
|
* `data_map` is a hash that matches the same structure as the data required for a template, but instead provides the details to prompt a user in case a peice of required data is missing.
|
110
|
+
* data_map entries will be displayed with a prompt to enter missing data. you can pose a data map entry in the form of a question, or just a description of the data.
|
99
111
|
|
100
112
|
## Example Template
|
101
113
|
|
102
114
|
Say you design a template using the turple default configuration, and you create a file structure like so...
|
115
|
+
|
103
116
|
```
|
104
117
|
foo_template
|
105
118
|
|__ my_[FOO.BAR]_dir
|
@@ -110,13 +123,14 @@ foo_template
|
|
110
123
|
```
|
111
124
|
|
112
125
|
and say your `my_[FOO.BAZ]_file.txt.turple` file contains the following
|
126
|
+
|
113
127
|
```
|
114
128
|
This <>foo.baz<> file is in the <>foo.bar<> folder.
|
115
129
|
```
|
116
130
|
|
117
131
|
With a simple Turplefile containing...
|
132
|
+
|
118
133
|
```
|
119
|
-
name: Foo Template
|
120
134
|
data_map:
|
121
135
|
foo:
|
122
136
|
bar: What is the foo bar?
|
@@ -128,7 +142,8 @@ data_map:
|
|
128
142
|
* Notice how the content variables match the `content_regex`
|
129
143
|
* Notice how the separator of the content variables match the `content_separator`
|
130
144
|
|
131
|
-
**
|
145
|
+
**Now let's run Turple!**
|
146
|
+
|
132
147
|
```sh
|
133
148
|
Saving to: /your/current/directory/turple
|
134
149
|
There is some missing data. You will be prompted to enter each value.
|
@@ -146,6 +161,7 @@ Paths Turpleated: 2
|
|
146
161
|
```
|
147
162
|
|
148
163
|
### Ruby
|
164
|
+
|
149
165
|
You can run turple directly in ruby if needed as well. _This example matches the template from the above example._
|
150
166
|
|
151
167
|
```ruby
|
@@ -164,6 +180,7 @@ Turple.ate '~/Code/templates/mini_ruby_project', {
|
|
164
180
|
most notably the passing of the destination in the 3rd argument _(the configuration hash)_
|
165
181
|
|
166
182
|
### Development & Testing
|
183
|
+
|
167
184
|
```shell
|
168
185
|
gem install yuyi
|
169
186
|
yuyi -m https://raw.githubusercontent.com/brewster1134/turple/master/yuyi_menu
|
data/lib/turple.rb
CHANGED
@@ -110,13 +110,21 @@ class Turple
|
|
110
110
|
# @param file [String] relative/absolute path to a turplefile
|
111
111
|
# @return [Hash]
|
112
112
|
#
|
113
|
-
def self.load_turplefile turplefile_path
|
113
|
+
def self.load_turplefile turplefile_path, update_turpleobject = true
|
114
114
|
turplefile_path = File.expand_path turplefile_path
|
115
115
|
|
116
116
|
# return false if file doesnt exist
|
117
117
|
return false unless File.exists? turplefile_path
|
118
118
|
|
119
|
-
|
119
|
+
# read turplefile to ruby object
|
120
|
+
turplefile_data = YAML.load File.read turplefile_path
|
121
|
+
|
122
|
+
# update the turpleobject, or return a symbolized hash
|
123
|
+
if update_turpleobject
|
124
|
+
self.turpleobject = turplefile_data
|
125
|
+
else
|
126
|
+
turplefile_data.deep_symbolize_keys
|
127
|
+
end
|
120
128
|
end
|
121
129
|
|
122
130
|
# Add additional data to the collective turplefile
|
@@ -134,6 +142,18 @@ private
|
|
134
142
|
# load home turplefile
|
135
143
|
Turple.load_turplefile File.join(File.expand_path('~'), 'Turplefile')
|
136
144
|
|
145
|
+
# check if template path is an interpolated project
|
146
|
+
template_turplefile = Turple.load_turplefile(File.join(template_path, 'Turplefile'), false)
|
147
|
+
if template_turplefile && template_turplefile[:created_on]
|
148
|
+
# use the project template
|
149
|
+
template_path = template_turplefile[:template]
|
150
|
+
|
151
|
+
# load the project sources
|
152
|
+
Turple.turpleobject = {
|
153
|
+
:sources => template_turplefile[:sources]
|
154
|
+
}
|
155
|
+
end
|
156
|
+
|
137
157
|
# create sources
|
138
158
|
Turple.sources.each do |source_name, source_path|
|
139
159
|
Turple::Source.new source_name, source_path
|
data/lib/turple/interpolate.rb
CHANGED
data/lib/turple/source.rb
CHANGED
@@ -33,7 +33,8 @@ private
|
|
33
33
|
@template_paths = {}
|
34
34
|
@source = Sourcerer.new(source_path)
|
35
35
|
|
36
|
-
|
36
|
+
# after source is created
|
37
|
+
add_templates @source
|
37
38
|
|
38
39
|
# add new source to hash
|
39
40
|
@@sources[source_name] = self
|
@@ -41,10 +42,10 @@ private
|
|
41
42
|
|
42
43
|
# search through source and add any directory with a Turplefile as a turple template
|
43
44
|
#
|
44
|
-
# @param
|
45
|
+
# @param source [Sourcerer] A Sourcerer instance object
|
45
46
|
#
|
46
|
-
def add_templates
|
47
|
-
|
47
|
+
def add_templates source
|
48
|
+
source.files('**/Turplefile').each do |turplefile_path|
|
48
49
|
template_path = File.dirname(turplefile_path)
|
49
50
|
template_name = File.basename(template_path)
|
50
51
|
|
data/lib/turple/template.rb
CHANGED