scaffoldish 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +86 -3
- data/bin/scaffoldish +12 -2
- data/lib/scaffoldish/application.rb +51 -7
- data/lib/scaffoldish/dsl/conf.rb +20 -0
- data/lib/scaffoldish/dsl/template.rb +50 -0
- data/lib/scaffoldish/scaffold.rb +23 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b89f6f556df00309eef7c0722c8e819a907a0654
|
4
|
+
data.tar.gz: 3d4e1e96248cf1f4ff5da83d38f21311e3476f54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9561b156509657eb847bf32734086e2c1bde5c79143edcf165978041633215ef7a13bf1f8a18d67944c5584e1ea3368c77abc8461ddc4da3d0dcd814b2343837
|
7
|
+
data.tar.gz: 6b241c6aefdf2dc6c210f4ca3683cfd7322e012d2000792d8cd0754aa75ce43927bb69df559de2c2fead730280778d9549a3c08a5ee7f38206b692c015f19175
|
data/README.md
CHANGED
@@ -1,7 +1,90 @@
|
|
1
|
-
#
|
1
|
+
# Scaffoldish
|
2
2
|
|
3
|
-
*Universal
|
3
|
+
*Universal scaffolding super powa for everyone!*
|
4
4
|
|
5
|
-
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/scaffoldish.svg)](http://badge.fury.io/rb/scaffoldish)
|
6
|
+
|
7
|
+
|
8
|
+
[![Build Status](https://travis-ci.org/debona/Scaffoldish.svg)](https://travis-ci.org/debona/Scaffoldish)
|
9
|
+
[![Coverage Status](https://coveralls.io/repos/debona/Scaffoldish/badge.png)](https://coveralls.io/r/debona/Scaffoldish)
|
10
|
+
[![Code Quality](https://codeclimate.com/github/debona/Scaffoldish.png)](https://codeclimate.com/github/debona/Scaffoldish)
|
6
11
|
|
7
12
|
Brings Rails-ish scaffolding super powa for every developpers, no matter they don't code with blessed RoR.
|
13
|
+
|
14
|
+
Current development status: Scaffoldish is still a **prototype**
|
15
|
+
|
16
|
+
That means your opinion is welcome and contributions will be appreciated.
|
17
|
+
|
18
|
+
## Install it
|
19
|
+
|
20
|
+
To install it, run `gem install scaffoldish` in your terminal to get the latest _stable_ version.
|
21
|
+
|
22
|
+
## Prepare your projects
|
23
|
+
|
24
|
+
Create a `./Scaffoldable` configuration file at your project root like that:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require 'ostruct'
|
28
|
+
|
29
|
+
project_root = File.dirname(__FILE__) # Ensure your project root is where your Scaffoldable live
|
30
|
+
templates_root = File.join(project_root, 'templates') # Specify the dir in which you drop your templates
|
31
|
+
|
32
|
+
scaffold :Model do |name, attribute| # Create a scaffold that you will call to generate files
|
33
|
+
|
34
|
+
# Prepare your data before to generate files
|
35
|
+
data = OpenStruct.new()
|
36
|
+
data.name = name = name.capitalize
|
37
|
+
data.attribute = attribute = attribute.downcase
|
38
|
+
|
39
|
+
# This will generate a file Model.java by executing the template Model.java.erb with data
|
40
|
+
generate('Model.java.erb', "#{name}.java", data)
|
41
|
+
|
42
|
+
# This will print console output asking to edit Controller.java by executing the template Controller.java.erb with data
|
43
|
+
chunk('Controller.java.erb', 'Controller.java', data)
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
Create the two templates in `./templates/`:
|
48
|
+
|
49
|
+
`Model.java.erb`:
|
50
|
+
```java
|
51
|
+
public class <%= name %> {
|
52
|
+
int <%= attribute %> = 0;
|
53
|
+
}
|
54
|
+
```
|
55
|
+
|
56
|
+
`Controller.java.erb`:
|
57
|
+
```java
|
58
|
+
Add the following attribute:
|
59
|
+
<%= name %> <%= name.downcase %> = new <%= name %>();
|
60
|
+
```
|
61
|
+
|
62
|
+
## Let's scaffold!
|
63
|
+
|
64
|
+
Open a terminal in your project and run: `cd your/project`
|
65
|
+
|
66
|
+
Then generate a new "Model" by running:
|
67
|
+
|
68
|
+
```shell
|
69
|
+
$ scaffoldish Model herp derp
|
70
|
+
```
|
71
|
+
|
72
|
+
It print that in your console, indicating what you should add to your `Controller.java`.
|
73
|
+
|
74
|
+
Run Model:
|
75
|
+
Edit Controller.java:
|
76
|
+
Add the following attribute:
|
77
|
+
Herp herp = new Herp();
|
78
|
+
|
79
|
+
It also generate the model `Herp`
|
80
|
+
|
81
|
+
`Herp.java`:
|
82
|
+
```java
|
83
|
+
public class Herp {
|
84
|
+
int derp = 0;
|
85
|
+
}
|
86
|
+
```
|
87
|
+
|
88
|
+
## Licensing
|
89
|
+
|
90
|
+
See LICENSE.md
|
data/bin/scaffoldish
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
require 'scaffoldish'
|
4
4
|
|
5
|
-
|
5
|
+
logger = Logger.new(STDERR)
|
6
|
+
logger.level = Logger::WARN
|
6
7
|
|
7
|
-
|
8
|
+
Kernel.send(:define_method, :logger) do
|
9
|
+
logger
|
10
|
+
end
|
11
|
+
|
12
|
+
begin
|
13
|
+
Scaffoldish::Application.instance.run(*ARGV)
|
14
|
+
rescue Exception => e
|
15
|
+
logger.error 'Scaffoldish crashed'
|
16
|
+
logger.error e
|
17
|
+
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
require 'singleton'
|
2
2
|
require 'logger'
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
require 'scaffoldish/scaffold'
|
6
|
+
require 'scaffoldish/dsl/conf'
|
3
7
|
|
4
8
|
module Scaffoldish
|
5
9
|
|
@@ -7,17 +11,57 @@ module Scaffoldish
|
|
7
11
|
|
8
12
|
include Singleton
|
9
13
|
|
10
|
-
attr_reader :
|
14
|
+
attr_reader :workspace
|
15
|
+
attr_reader :scaffolds, :project_root, :templates_root
|
11
16
|
|
12
17
|
def initialize
|
13
|
-
@
|
14
|
-
@
|
18
|
+
@workspace = Object.new
|
19
|
+
@workspace.extend(DSL::Conf)
|
20
|
+
|
21
|
+
@scaffolds = {}
|
22
|
+
@project_root = Dir.pwd
|
23
|
+
@templates_root = File.join(@project_root, 'templates')
|
15
24
|
end
|
16
25
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
26
|
+
def load_config
|
27
|
+
config_filename = 'Scaffoldable'
|
28
|
+
config_path = Dir.pwd
|
29
|
+
|
30
|
+
while config_path != '/' && !File.exist?(File.join(config_path, config_filename))
|
31
|
+
config_path = File.expand_path("..", config_path)
|
32
|
+
end
|
33
|
+
|
34
|
+
config = File.read(File.join(config_path, config_filename))
|
35
|
+
@project_root = config_path
|
36
|
+
|
37
|
+
workspace.scaffolds = @scaffolds
|
38
|
+
workspace.project_root = @project_root
|
39
|
+
workspace.templates_root = @templates_root
|
40
|
+
|
41
|
+
workspace.instance_eval(config)
|
42
|
+
|
43
|
+
@scaffolds = workspace.scaffolds
|
44
|
+
@project_root = workspace.project_root
|
45
|
+
@templates_root = workspace.templates_root
|
46
|
+
end
|
47
|
+
|
48
|
+
def run(*args)
|
49
|
+
|
50
|
+
load_config
|
51
|
+
|
52
|
+
scaffold_name = args.shift
|
53
|
+
|
54
|
+
# Parameters checking
|
55
|
+
raise OptionParser::MissingArgument.new("$1 => scaffold_name") if scaffold_name.nil?
|
56
|
+
unless scaffolds.has_key?(scaffold_name.to_sym)
|
57
|
+
raise OptionParser::InvalidArgument.new("$1 => scaffold_name should be one of the followings: #{scaffolds.keys}")
|
58
|
+
end
|
59
|
+
|
60
|
+
scaffold = scaffolds[scaffold_name.to_sym]
|
61
|
+
|
62
|
+
puts "Run #{scaffold_name}:"
|
63
|
+
|
64
|
+
scaffold.run(*args)
|
21
65
|
end
|
22
66
|
|
23
67
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
require 'scaffoldish/scaffold'
|
3
|
+
|
4
|
+
module Scaffoldish
|
5
|
+
|
6
|
+
module DSL
|
7
|
+
|
8
|
+
module Conf
|
9
|
+
|
10
|
+
attr_accessor :scaffolds, :project_root, :templates_root
|
11
|
+
|
12
|
+
def scaffold(name, &block)
|
13
|
+
@scaffolds ||= {}
|
14
|
+
@scaffolds[name.to_sym] = Scaffold.new(name.to_sym, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
require 'fileutils'
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
require 'scaffoldish/application'
|
6
|
+
|
7
|
+
module Scaffoldish
|
8
|
+
|
9
|
+
module DSL
|
10
|
+
|
11
|
+
module Template
|
12
|
+
|
13
|
+
def generate(template_path, output_path, data)
|
14
|
+
template = File.read(File.join(Application.instance.templates_root, template_path))
|
15
|
+
renderer = ERB.new(template)
|
16
|
+
|
17
|
+
result = renderer.result(data.instance_eval { binding })
|
18
|
+
|
19
|
+
absolute_output_path = File.join(Application.instance.project_root, output_path)
|
20
|
+
|
21
|
+
if File.exist?(absolute_output_path)
|
22
|
+
puts("Can't generate #{absolute_output_path}, it already exists. Skip it")
|
23
|
+
return
|
24
|
+
end
|
25
|
+
|
26
|
+
dir = File.dirname(absolute_output_path)
|
27
|
+
FileUtils.mkpath(dir)
|
28
|
+
|
29
|
+
File.open(absolute_output_path, 'w') do |file|
|
30
|
+
file.write(result)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def chunk(template_path, output_path, data)
|
35
|
+
template = File.read(File.join(Application.instance.templates_root, template_path))
|
36
|
+
renderer = ERB.new(template)
|
37
|
+
|
38
|
+
result = renderer.result(data.instance_eval { binding })
|
39
|
+
|
40
|
+
puts "Edit #{output_path}:"
|
41
|
+
puts result
|
42
|
+
puts ""
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
require 'scaffoldish/dsl/template'
|
3
|
+
|
4
|
+
module Scaffoldish
|
5
|
+
|
6
|
+
class Scaffold
|
7
|
+
|
8
|
+
include DSL::Template
|
9
|
+
|
10
|
+
attr_reader :name, :block
|
11
|
+
|
12
|
+
def initialize(name, &block)
|
13
|
+
@name = name
|
14
|
+
@block = block || Proc.new {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def run(*args)
|
18
|
+
instance_exec(*args, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scaffoldish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas DE BONA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Brings Rails-ish scaffolding super powa for every developpers, no matter
|
14
14
|
they don't code with blessed RoR.
|
@@ -23,7 +23,10 @@ files:
|
|
23
23
|
- bin/scaffoldish
|
24
24
|
- lib/scaffoldish.rb
|
25
25
|
- lib/scaffoldish/application.rb
|
26
|
-
|
26
|
+
- lib/scaffoldish/dsl/conf.rb
|
27
|
+
- lib/scaffoldish/dsl/template.rb
|
28
|
+
- lib/scaffoldish/scaffold.rb
|
29
|
+
homepage: http://github.com/debona/Scaffoldish
|
27
30
|
licenses:
|
28
31
|
- MIT
|
29
32
|
metadata: {}
|
@@ -46,5 +49,5 @@ rubyforge_project:
|
|
46
49
|
rubygems_version: 2.2.2
|
47
50
|
signing_key:
|
48
51
|
specification_version: 4
|
49
|
-
summary: Universal
|
52
|
+
summary: Universal scaffolding super powa for everyone!
|
50
53
|
test_files: []
|