erlgen 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Dimitri Krassovski
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,22 @@
1
+ = erlgen
2
+
3
+ erlgen is a Erlang application generator. It generates the basic application layout with some simple files to build upon.
4
+
5
+ == Planned features:
6
+
7
+ * Include rake tasks (or command line arguments) to generate default gen_server, gen_fsm, etc. modules.
8
+ * Option to choose between Rake/Make/Emake.
9
+
10
+ == Note on Patches/Pull Requests
11
+
12
+ * Fork the project.
13
+ * Make your feature addition or bug fix.
14
+ * Add tests for it. This is important so I don't break it in a
15
+ future version unintentionally.
16
+ * Commit, do not mess with rakefile, version, or history.
17
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
18
+ * Send me a pull request. Bonus points for topic branches.
19
+
20
+ == Copyright
21
+
22
+ Copyright (c) 2010 Dimitri Krassovski. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "erlgen"
8
+ gem.summary = %Q{Erlang application generator}
9
+ gem.description = %Q{Erlang application generator}
10
+ gem.email = "labria@startika.com"
11
+ gem.homepage = "http://github.com/labria/erlgen"
12
+ gem.authors = ["Dimitri Krassovski"]
13
+ gem.add_dependency "git", ">= 1.2.5"
14
+ gem.add_development_dependency "rspec", ">= 1.2.9"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "erlgen #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/erlgen ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require 'erlgen/generator'
4
+ Erlgen::Generator.new(*ARGV).run
data/erlgen.gemspec ADDED
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{erlgen}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Dimitri Krassovski"]
12
+ s.date = %q{2010-04-01}
13
+ s.default_executable = %q{erlgen}
14
+ s.description = %q{Erlang application generator}
15
+ s.email = %q{labria@startika.com}
16
+ s.executables = ["erlgen"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/erlgen",
29
+ "erlgen.gemspec",
30
+ "lib/erlgen.rb",
31
+ "lib/erlgen/generator.rb",
32
+ "lib/erlgen/templates/Rakefile",
33
+ "lib/erlgen/templates/application.app",
34
+ "lib/erlgen/templates/application.erl",
35
+ "lib/erlgen/templates/application_sup.erl",
36
+ "spec/erlgen_spec.rb",
37
+ "spec/spec.opts",
38
+ "spec/spec_helper.rb"
39
+ ]
40
+ s.homepage = %q{http://github.com/labria/erlgen}
41
+ s.rdoc_options = ["--charset=UTF-8"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = %q{1.3.6}
44
+ s.summary = %q{Erlang application generator}
45
+ s.test_files = [
46
+ "spec/erlgen_spec.rb",
47
+ "spec/spec_helper.rb"
48
+ ]
49
+
50
+ if s.respond_to? :specification_version then
51
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
+ s.specification_version = 3
53
+
54
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
55
+ s.add_runtime_dependency(%q<git>, [">= 1.2.5"])
56
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
57
+ else
58
+ s.add_dependency(%q<git>, [">= 1.2.5"])
59
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<git>, [">= 1.2.5"])
63
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
64
+ end
65
+ end
66
+
@@ -0,0 +1,106 @@
1
+ require 'optparse'
2
+ require 'fileutils'
3
+ require 'erb'
4
+ require 'git'
5
+
6
+ class Erlgen
7
+ class Generator
8
+ attr_accessor :project_name, :options
9
+ def initialize(*args)
10
+
11
+ @options = {}
12
+ @opts = OptionParser.new do |o|
13
+ o.banner = "Usage: #{File.basename($0)} [options] appname\ne.g. #{File.basename($0)} superapp"
14
+ o.on('--with-git', 'initialize git repository') do
15
+ @options[:with_git] = true
16
+ end
17
+
18
+ o.on_tail('-h', '--help', 'display this help and exit') do
19
+ @options[:show_help] = true
20
+ end
21
+ end
22
+ @opts.parse!(args)
23
+
24
+ @project_name = args.shift
25
+
26
+
27
+ end
28
+
29
+ def run
30
+ if @options[:show_help]
31
+ $stderr.puts @opts
32
+ return 1
33
+ end
34
+
35
+ if @project_name.nil? || @project_name.squeeze.strip == ""
36
+ $stderr.puts @opts
37
+ return 1
38
+ end
39
+
40
+ create_files
41
+
42
+ if @options[:with_git]
43
+ create_version_control
44
+ end
45
+ end
46
+
47
+ def create_files
48
+ unless File.exists?(target_dir) || File.directory?(target_dir)
49
+ FileUtils.mkdir target_dir
50
+ else
51
+ raise "The directory #{target_dir} already exists, aborting. Maybe move it out of the way before continuing?"
52
+ end
53
+ mkdir_in_target 'src'
54
+ mkdir_in_target 'ebin'
55
+ mkdir_in_target 'priv'
56
+ mkdir_in_target 'include'
57
+ output_template_in_target 'application.app', File.join('ebin', "#{@project_name}.app")
58
+ output_template_in_target 'application.erl', File.join('src', "#{@project_name}.erl")
59
+ output_template_in_target 'application_sup.erl', File.join('src', "#{@project_name}_sup.erl")
60
+ output_template_in_target 'Rakefile'
61
+ end
62
+
63
+ def target_dir
64
+ @project_name
65
+ end
66
+
67
+ def mkdir_in_target(directory)
68
+ final_destination = File.join(target_dir, directory)
69
+ FileUtils.mkdir final_destination
70
+ $stdout.puts "\tcreate\t#{directory}"
71
+ end
72
+
73
+ def render_template(source)
74
+ template_contents = File.read(File.join(template_dir, source))
75
+ template = ERB.new(template_contents, nil, '<>')
76
+
77
+ # squish extraneous whitespace from some of the conditionals
78
+ template.result(binding).gsub(/\n\n\n+/, "\n\n")
79
+ end
80
+
81
+ def output_template_in_target(source, destination = source)
82
+ final_destination = File.join(target_dir, destination)
83
+ template_result = render_template(source)
84
+
85
+ File.open(final_destination, 'w') {|file| file.write(template_result)}
86
+
87
+ $stdout.puts "\tcreate\t#{destination}"
88
+ end
89
+
90
+ def template_dir
91
+ File.join(File.dirname(__FILE__), 'templates')
92
+ end
93
+
94
+ def create_version_control
95
+ Dir.chdir(target_dir) do
96
+ begin
97
+ @repo = Git.init()
98
+ rescue Git::GitExecuteError => e
99
+ raise GitInitFailed, "Encountered an error during gitification. Maybe the repo already exists, or has already been pushed to?"
100
+ end
101
+ end
102
+ end
103
+
104
+
105
+ end
106
+ end
@@ -0,0 +1,53 @@
1
+ require 'rake'
2
+ require 'rake/clean'
3
+
4
+ # Configuration
5
+ START_MODULE = "<%= @project_name%>"
6
+ TEST_MODULE = "test_<%= @project_name%>"
7
+ MNESIA_DIR = "/tmp"
8
+
9
+
10
+ # No Need to change
11
+ PWD = `pwd`.strip
12
+ INCLUDE = "include"
13
+ ERLC_FLAGS = "-I#{INCLUDE} +warn_unused_vars +warn_unused_import"
14
+
15
+ SRC = FileList['src/**/*.erl']
16
+ OBJ = SRC.pathmap("%{src,ebin}X.beam")
17
+ CLEAN.include(['**/*.dump'])
18
+ CLOBBER.include(['**/*.beam'])
19
+
20
+ directory 'ebin'
21
+
22
+
23
+ rule ".beam" => ["%{ebin,src}X.erl"] do |t|
24
+ sh "erlc -pa ebin -W #{ERLC_FLAGS} -o ebin #{t.source}"
25
+ end
26
+
27
+ desc "Compile all"
28
+ task :compile => ['ebin'] + OBJ
29
+
30
+ desc "Open up a shell"
31
+ task :shell => [:compile] do
32
+ sh("erl -sname #{START_MODULE} -pa #{PWD}/ebin")
33
+ end
34
+
35
+ desc "Open up a shell and run #{START_MODULE}:start()"
36
+ task :run => [:compile] do
37
+ sh("erl -sname #{START_MODULE} -pa #{PWD}/ebin -run #{START_MODULE} start")
38
+ end
39
+
40
+ desc "Run Unit Tests"
41
+ task :test do
42
+ sh("erl -noshell -s #{TEST_MODULE} test -s init stop")
43
+ end
44
+
45
+
46
+ desc "Generate Documentation"
47
+ task :doc do
48
+ sh("cd doc && erl -noshell -run edoc files ../#{SRC.join(" ../")} -run init stop")
49
+ end
50
+
51
+
52
+ task :default => :compile
53
+
@@ -0,0 +1,9 @@
1
+ {application, <%= @project_name%>,
2
+ [{description, "<%= @project_name%> application"},
3
+ {vsn, "0.2"},
4
+ {modules, [<%= @project_name%>]},
5
+ {registered, []},
6
+ {applications, [kernel, stdlib]},
7
+ {env, []},
8
+ {mod, {<%= @project_name%>, []}}]}.
9
+
@@ -0,0 +1,56 @@
1
+ %%%-------------------------------------------------------------------
2
+ %%% Author : Author Name
3
+ %%% @doc The entry point into our application.
4
+ %%% @end
5
+ %%%-------------------------------------------------------------------
6
+ -module(<%= @project_name%>).
7
+
8
+ -behaviour(application).
9
+ %%--------------------------------------------------------------------
10
+ %% Include files
11
+ %%--------------------------------------------------------------------
12
+ -include("<%= @project_name%>.hrl").
13
+
14
+ %%--------------------------------------------------------------------
15
+ %% External exports
16
+ %%--------------------------------------------------------------------
17
+ -export([
18
+ start/2,
19
+ shutdown/0,
20
+ stop/1
21
+ ]).
22
+
23
+ %%====================================================================
24
+ %% External functions
25
+ %%====================================================================
26
+ %%--------------------------------------------------------------------
27
+ %% @doc The starting point for an erlang application.
28
+ %% @spec start(Type, StartArgs) -> {ok, Pid} | {ok, Pid, State} | {error, Reason}
29
+ %% @end
30
+ %%--------------------------------------------------------------------
31
+ start(Type, StartArgs) ->
32
+ case <%= @project_name%>_sup:start_link(StartArgs) of
33
+ {ok, Pid} ->
34
+ {ok, Pid};
35
+ Error ->
36
+ Error
37
+ end.
38
+
39
+ %%--------------------------------------------------------------------
40
+ %% @doc Called to shudown the <%= @project_name%> application.
41
+ %% @spec shutdown() -> ok
42
+ %% @end
43
+ %%--------------------------------------------------------------------
44
+ shutdown() ->
45
+ application:stop(<%= @project_name%>).
46
+
47
+ %%====================================================================
48
+ %% Internal functions
49
+ %%====================================================================
50
+
51
+ %%--------------------------------------------------------------------
52
+ %% Called upon the termination of an application.
53
+ %%--------------------------------------------------------------------
54
+ stop(State) ->
55
+ ok.
56
+
@@ -0,0 +1,63 @@
1
+ %%%-------------------------------------------------------------------
2
+ %%% Author : Author Name
3
+ %%% @doc The top level supervisor for our application.
4
+ %%% @end
5
+ %%%-------------------------------------------------------------------
6
+ -module(<%= @project_name%>_sup).
7
+
8
+ -behaviour(supervisor).
9
+
10
+ %%--------------------------------------------------------------------
11
+ %% External exports
12
+ %%--------------------------------------------------------------------
13
+ -export([start_link/1]).
14
+
15
+ %%--------------------------------------------------------------------
16
+ %% Internal exports
17
+ %%--------------------------------------------------------------------
18
+ -export([init/1]).
19
+
20
+ %%--------------------------------------------------------------------
21
+ %% Macros
22
+ %%--------------------------------------------------------------------
23
+ -define(SERVER, ?MODULE).
24
+
25
+ %%====================================================================
26
+ %% External functions
27
+ %%====================================================================
28
+ %%--------------------------------------------------------------------
29
+ %% @doc Starts the supervisor.
30
+ %% @spec start_link(StartArgs) -> {ok, pid()} | Error
31
+ %% @end
32
+ %%--------------------------------------------------------------------
33
+ start_link(StartArgs) ->
34
+ supervisor:start_link({local, ?SERVER}, ?MODULE, []).
35
+
36
+ %%====================================================================
37
+ %% Server functions
38
+ %%====================================================================
39
+ %%--------------------------------------------------------------------
40
+ %% Func: init/1
41
+ %% Returns: {ok, {SupFlags, [ChildSpec]}} |
42
+ %% ignore |
43
+ %% {error, Reason}
44
+ %%--------------------------------------------------------------------
45
+ init([]) ->
46
+ RestartStrategy = one_for_one,
47
+ MaxRestarts = 1000,
48
+ MaxTimeBetRestarts = 3600,
49
+
50
+ SupFlags = {RestartStrategy, MaxRestarts, MaxTimeBetRestarts},
51
+
52
+ %% Replace <%= @project_name%>_server with your actual module
53
+ ChildSpecs =
54
+ [
55
+ {<%= @project_name%>_server,
56
+ {<%= @project_name%>_server, start_link, []},
57
+ permanent,
58
+ 1000,
59
+ worker,
60
+ [<%= @project_name%>_server]}
61
+ ],
62
+ {ok,{SupFlags, ChildSpecs}}.
63
+
data/lib/erlgen.rb ADDED
@@ -0,0 +1,3 @@
1
+ class Erlgen
2
+
3
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Erlgen" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'erlgen'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: erlgen
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Dimitri Krassovski
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-01 00:00:00 +03:00
18
+ default_executable: erlgen
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: git
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 5
31
+ version: 1.2.5
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 2
44
+ - 9
45
+ version: 1.2.9
46
+ type: :development
47
+ version_requirements: *id002
48
+ description: Erlang application generator
49
+ email: labria@startika.com
50
+ executables:
51
+ - erlgen
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - LICENSE
56
+ - README.rdoc
57
+ files:
58
+ - .document
59
+ - .gitignore
60
+ - LICENSE
61
+ - README.rdoc
62
+ - Rakefile
63
+ - VERSION
64
+ - bin/erlgen
65
+ - erlgen.gemspec
66
+ - lib/erlgen.rb
67
+ - lib/erlgen/generator.rb
68
+ - lib/erlgen/templates/Rakefile
69
+ - lib/erlgen/templates/application.app
70
+ - lib/erlgen/templates/application.erl
71
+ - lib/erlgen/templates/application_sup.erl
72
+ - spec/erlgen_spec.rb
73
+ - spec/spec.opts
74
+ - spec/spec_helper.rb
75
+ has_rdoc: true
76
+ homepage: http://github.com/labria/erlgen
77
+ licenses: []
78
+
79
+ post_install_message:
80
+ rdoc_options:
81
+ - --charset=UTF-8
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ requirements: []
99
+
100
+ rubyforge_project:
101
+ rubygems_version: 1.3.6
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Erlang application generator
105
+ test_files:
106
+ - spec/erlgen_spec.rb
107
+ - spec/spec_helper.rb