roject 0.7.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5265b6ec336684e4ba63f8fb0348512446e55f16
4
- data.tar.gz: 26971fbf99b1b2ccac6d935ab74acaebc78dcd3a
3
+ metadata.gz: 807cc469992c60c0377a1a0544b487e71f39d6cd
4
+ data.tar.gz: 290adb3e83bb77773cf86265fe64c9962aa00353
5
5
  SHA512:
6
- metadata.gz: c7fc1107661b11a7818ffb400fc1da28b76589eed4c78478ab85268cb4735f6669251ae9affb00b7e419631a857e908df01fddd232eb8c074f76187d75c1336c
7
- data.tar.gz: 63de4a62904dbf091ce60006df1c5ad46be5be35b86ccc01ea50045640e3f61d067dad914b1a9d32a664dc8f44b28b8f9df316b8b65c10d4f056fd22b33674b9
6
+ metadata.gz: a886dc73ee4ad3ab267f51b7ef5fa14c78074e581a1d6a83b05546efbce326c3d99be8d2a7909a10da15c508d4387d354f36c1c09cba48136943ca7f1d801b9d
7
+ data.tar.gz: dc5437b8cd0605dbbfd94497dc3cd810e57a0451c891da46138631fe9c2574d3008d0d53b0b56271dc70a2a405ea2b17d9dca4cbe472d95fc934f8976561cfe2
data/README.md CHANGED
@@ -1,3 +1,149 @@
1
1
  # Roject
2
2
 
3
- Roject is a programming project manager written in Ruby. With Roject, you can create and edit projects based on templates and using simple, customisable commands without a heavy IDE.
3
+ Roject is a programming project manager written in Ruby. With Roject, you can create and edit projects based on templates and using simple, customisable commands without a heavy IDE.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Project Script](#project-script)
8
+ - [Config](#config)
9
+ - [Makers](#makers)
10
+ - [The Command Line](#the-command-line)
11
+
12
+ ## Project Script
13
+
14
+ A Roject project is configured using a project script in a project directory, create a ruby script called "project.rb". This ruby script is evaluated in the context of a Roject project object and contains information about the project, the types of files that can be made, and the tasks that can be performed.
15
+
16
+ ```ruby
17
+ # Config
18
+ config project_name: "Dre",
19
+ author: "Anshul Kharbanda",
20
+ created: "7 - 23 - 2016",
21
+ short_description: "Forgot about Dre.",
22
+ long_description: "Nowadays everybody wanna talk like" \
23
+ " they got somethin' to say but nothin' comes out" \
24
+ " when they move their lips just a bunch of gibberish" \
25
+ " and they all acting like they forgot about Dre."
26
+
27
+ #---------------------------MAKERS---------------------------
28
+
29
+ # Header file
30
+ file :header,
31
+ path: "include/@(project_name)/@(path)",
32
+ template: "header.general",
33
+ extension: "h"
34
+
35
+ # Source file
36
+ file :source,
37
+ path: "src/@(path)",
38
+ template: "source.general",
39
+ extension: "cpp"
40
+
41
+ # Module includes a source and include
42
+ task :module do |args|
43
+ # Add header id
44
+ args[:header_id] = c_header_id(args[:path])
45
+
46
+ # Create source and header
47
+ make :header, args
48
+ make :source, args
49
+ end
50
+ ```
51
+
52
+ In this script, the project information (project_name, author, etc.) is configured using the `config` method, which is given a hash of the project info. After which, project makers (automated tasks that can be called via the command line) are defined using the `file` and `task` methods. The `file` method creates a file maker which makes files according to the information given using the command line arguments. The `task` method creates a task maker which executes the given block with the command line arguments.
53
+
54
+ ### Config
55
+
56
+ Projects are configured using the `config` method:
57
+
58
+ ```ruby
59
+ config project_name: "Dre",
60
+ author: "Anshul Kharbanda",
61
+ created: "7 - 23 - 2016",
62
+ short_description: "Forgot about Dre.",
63
+ long_description: "Nowadays everybody wanna talk like" \
64
+ " they got somethin' to say but nothin' comes out" \
65
+ " when they move their lips just a bunch of gibberish" \
66
+ " and they all acting like they forgot about Dre."
67
+ ```
68
+
69
+ This command should be passed a hash of project info keys, of which are the following:
70
+
71
+ | Key | Description |
72
+ |:-----------------:|:----------------------------------:|
73
+ | project_name | the name of the project |
74
+ | author | the project's author |
75
+ | created | the date the project was created |
76
+ | short_description | a short description of the project |
77
+ | long_description | a long description of the project |
78
+
79
+ There are also optional options to set. The `directory` key is a hash of essential directories. The `templates` key within the `directory` hash determines where project templates are located, and defaults to `_templates`. Of course, this can also be changed to your liking.
80
+
81
+ ```ruby
82
+ config project_name: "Dre",
83
+ author: "Anshul Kharbanda",
84
+ created: "7 - 23 - 2016",
85
+ short_description: "Forgot about Dre.",
86
+ long_description: "Nowadays everybody wanna talk like" \
87
+ " they got somethin' to say but nothin' comes out" \
88
+ " when they move their lips just a bunch of gibberish" \
89
+ " and they all acting like they forgot about Dre.",
90
+ directory: {
91
+ templates: "new-templates-dir"
92
+ }
93
+ ```
94
+
95
+ ### Makers
96
+
97
+ Project makers are also specified int the Project script. Makers are automated tasks that create new files. There are two types of makers to date.
98
+
99
+ #### File Makers
100
+
101
+ File makers are specified using the `file` method.
102
+
103
+ ```ruby
104
+ file :header,
105
+ path: "include/@(project_name)/@(path)",
106
+ template: "header.general",
107
+ extension: "h"
108
+ ```
109
+
110
+ Roject uses the [General](http://andydevs.github.io/general) templating library for file and string templates. FileMakers use general templates, project information, and command line arguments to create files of specific types. File templates are located in the `templates` directory (which is set using `config`).
111
+
112
+ The `file` method is passed a name (used to call the maker via the command line arguments), and a hash of options, which should include the following:
113
+
114
+ | Key | Description |
115
+ |:---------:|:---------------------------------------------------------------------------------------:|
116
+ | path | The path of the file, as a General template string (parsed on creation of the file) |
117
+ | template | The filename of the General template file to format |
118
+ | extension | The file extension |
119
+
120
+ #### Task Makers
121
+
122
+ Task makers are specified using the `task` method.
123
+
124
+ ```ruby
125
+ # Module includes a source and include
126
+ task :module do |args|
127
+ # Add header id
128
+ args[:header_id] = c_header_id(args[:path])
129
+
130
+ # Create source and header
131
+ make :header, args
132
+ make :source, args
133
+ end
134
+ ```
135
+
136
+ The `task` method is passed the command line name and a block which is called when the task is called from the command line, which takes one hash of arguments parsed from the command line.
137
+
138
+ ## The Command Line
139
+
140
+ The Roject library comes with the `roject` binary script, from which you call the project makers that were defined.
141
+
142
+ ```
143
+ $ roject [maker name] [command line arguments]
144
+ ```
145
+
146
+ Command line arguments are key-value pairs which follow the following pattern: `[key]:[value]`. The script will search the current directory for a project script, read it, and run the given maker in the context of the project.
147
+
148
+ ---
149
+ Anshul Kharbanda
data/Rakefile CHANGED
@@ -14,6 +14,7 @@ Created: 7 - 8 - 2016
14
14
  # Required libraries
15
15
  require "rspec/core/rake_task"
16
16
  require "rubygems/tasks"
17
+ require "fileutils"
17
18
 
18
19
  # Requird files
19
20
  require_relative "lib/roject"
@@ -22,6 +23,10 @@ require_relative "lib/roject"
22
23
  GEMDIR = "gem"
23
24
  SPECDIR = "spec"
24
25
 
26
+ # Test argument sets
27
+ TEST_ARG_SETS = "header path:\"path/to/file\"",
28
+ "module path:\"path/to/second/file\""
29
+
25
30
  # Default task
26
31
  task :default => :spec
27
32
 
@@ -51,12 +56,34 @@ namespace :git do
51
56
  end
52
57
 
53
58
  desc "Soft git reset"
54
- task :reset do
55
- sh "git reset"
56
- end
59
+ task :reset do sh "git reset" end
57
60
 
58
61
  desc "Hard git reset"
59
- task :reset_hard do
60
- sh "git reset --hard HEAD"
61
- end
62
+ task :reset_hard do sh "git reset --hard HEAD" end
63
+ end
64
+
65
+ #----------------------------------SCRIPT----------------------------------
66
+
67
+ desc "Runs the script with test arguments"
68
+ task :test, [:index] do |task, args|
69
+ # Changedown to project
70
+ Dir.chdir "exp/project"
71
+
72
+ # Run each test arg set
73
+ sh "../../bin/roject #{TEST_ARG_SETS[args[:index].to_i]}"
74
+
75
+ # Changeup
76
+ Dir.chdir "../.."
77
+ end
78
+
79
+ desc "Cleans the project directory"
80
+ task :cleantest do
81
+ # Changedown to project
82
+ Dir.chdir "exp/project"
83
+
84
+ # Cleanup
85
+ FileUtils.rmtree ["include", "src"]
86
+
87
+ # Changeup
88
+ Dir.chdir "../.."
62
89
  end
data/bin/roject ADDED
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ =begin
4
+
5
+ Program: Roject
6
+
7
+ Roject is a programming project manager written in Ruby.
8
+ With Roject, you can create and edit projects based on templates
9
+ using simple commands without a heavy IDE.
10
+
11
+ Author: Anshul Kharbanda
12
+ Created: 7 - 8 - 2016
13
+
14
+ =end
15
+
16
+ # Require roject library
17
+ require_relative "../lib/roject"
18
+
19
+ # Regular expression for parsing arguments
20
+ ARGREGEX = /(?<key>\w+):(?<value>.+)/
21
+
22
+ # Parses command line arguments into a task
23
+ # and hash of arguments
24
+ #
25
+ # Parameter: args - the command line arguments
26
+ #
27
+ # Return: parsed task and hash of arguments
28
+ def parse_arguments args
29
+ # First argument is the maker
30
+ makr = args[0].to_sym
31
+
32
+ # Parse remaining arguments
33
+ argh = {}; args[1..-1].each do |arg|
34
+ ARGREGEX.match(arg) do |match|
35
+ argh[match[:key].to_sym] = match[:value]
36
+ end
37
+ end
38
+
39
+ # Return maker and args
40
+ return [makr, argh]
41
+ end
42
+
43
+ # If working dir is project
44
+ if Roject::Project.exist?
45
+
46
+ # Parse command line arguments
47
+ task, args = parse_arguments ARGV
48
+
49
+ # Print info
50
+ puts "making #{task}", "args #{args}"
51
+
52
+ # Make maker and args
53
+ Roject::Project.open { make task, args }
54
+
55
+ # Else raise error
56
+ else
57
+ raise IOError, "Could not locate a project script in current directory: #{Dir.getwd}"
58
+ end
@@ -2,4 +2,4 @@ config project_name: "Foo",
2
2
  author: "Anshul Kharbanda",
3
3
  created: "7 - 24 - 2016",
4
4
  short_description: "Foo bar",
5
- long_description: "Foo bar baz ju jar jaz nu nar naz"
5
+ long_description: "Foo bar baz joo jar jaz noo kar kaz"
data/lib/project.rb CHANGED
@@ -25,7 +25,7 @@ module Roject
25
25
  # Author: Anshul Kharbanda
26
26
  # Created: 7 - 10 - 2016
27
27
  class Project
28
- # Includes
28
+ # Helper methods for creating and manipulating projects
29
29
  include Helpers
30
30
 
31
31
  # Default filename
@@ -43,6 +43,34 @@ module Roject
43
43
  }
44
44
  }
45
45
 
46
+ # Check if a project file exists in the current directory
47
+ #
48
+ # Parameter: filename - the filename to check
49
+ # (defaults to the default filename)
50
+ #
51
+ # Returns: true if the project file exists in the current
52
+ # directory
53
+ def self.exist? filename=FILENAME_DEFAULT
54
+ File.file?(FILENAME_DEFAULT)
55
+ end
56
+
57
+ #-----------------------------------CLASS CONFIG-----------------------------------
58
+
59
+ # Alias for load if no block is given. Evaluates the given
60
+ # block in the context of the project if block is given
61
+ #
62
+ # Parameter: filename - the name of the file to parse
63
+ # (defaults to the default filename)
64
+ # Parameter: block - the block to evaluate within the
65
+ # context of the project
66
+ #
67
+ # Return: Project loaded from the file
68
+ def self.open filename=FILENAME_DEFAULT, &block
69
+ project = self.load(filename)
70
+ project.instance_eval(&block) unless block.nil?
71
+ return project
72
+ end
73
+
46
74
  # Loads a Project from the project file with the given filename
47
75
  #
48
76
  # Parameter: filename - the name of the file to parse
@@ -50,17 +78,23 @@ module Roject
50
78
  #
51
79
  # Return: Project loaded from the file
52
80
  def self.load filename=FILENAME_DEFAULT
53
- project = Roject::Project.new
81
+ project = self.new
54
82
  project.instance_eval(IO.read(filename))
55
83
  return project
56
84
  end
57
85
 
58
- #----------------------------------INIT AND CONFIG----------------------------------
86
+ #----------------------------------INSTANCE CONFIG----------------------------------
59
87
 
60
88
  # Called upon the initialization of a Project
61
89
  # Creates config and makers hashes
62
90
  def initialize; @config = CONFIG_DEFAULT; @makers = {}; end
63
91
 
92
+ # Reloads the project with the file with the given filename
93
+ #
94
+ # Parameter: filename - the name of the file to parse
95
+ # (defaults to the default filename)
96
+ def reload(filename=FILENAME_DEFAULT); initialize and instance_eval(IO.read(filename)); end
97
+
64
98
  # If a hash is given, sets the Project configuration to the hash.
65
99
  # Else, returns the configuration of the Project.
66
100
  #
data/lib/roject.rb CHANGED
@@ -20,5 +20,5 @@ require_relative "project"
20
20
  # Created: 7 - 8 - 2016
21
21
  module Roject
22
22
  # The Version of Roject
23
- VERSION = "0.7.0"
23
+ VERSION = "1.0.0"
24
24
  end
data/spec/project_spec.rb CHANGED
@@ -21,14 +21,20 @@ require_relative "../lib/roject"
21
21
  describe Roject::Project do
22
22
  # Do before
23
23
  before :all do
24
+ # Change to project
24
25
  Dir.chdir "exp/project"
26
+
27
+ # Create base project
25
28
  @project = Roject::Project.new
26
- @config = Roject::Project::CONFIG_DEFAULT.merge({
29
+
30
+ # Foobar file
31
+ @foofle = "foobar.rb"
32
+ @foocfg = Roject::Project::CONFIG_DEFAULT.merge({
27
33
  project_name: "Foo",
28
34
  author: "Anshul Kharbanda",
29
35
  created: "7 - 24 - 2016",
30
36
  short_description: "Foo bar",
31
- long_description: "Foo bar baz ju lar laz nu kar kaz"
37
+ long_description: "Foo bar baz joo jar jaz noo kar kaz"
32
38
  })
33
39
  end
34
40
 
@@ -49,37 +55,127 @@ describe Roject::Project do
49
55
 
50
56
  context 'with hash given' do
51
57
  it 'configures the Project with the given hash' do
52
- expect{@project.config(@config)}.not_to raise_error
53
- expect(@project.config).to eql @config
58
+ expect{@project.config(@foocfg)}.not_to raise_error
59
+ expect(@project.config).to eql @foocfg
54
60
  end
55
61
  end
56
62
  end
57
63
 
58
- # Describe Roject::Project::load
64
+ # Describe Roject::Project loading system
59
65
  #
60
- # Loads a Project from the project file with the given filename
61
- #
62
- # Parameter: filename - the name of the file to parse
66
+ # The system of loading and reloading from a file
63
67
  #
64
- # Return: Project loaded from the file
65
- describe '::load' do
66
- context 'with a filename given' do
67
- it 'loads a project from the given filename' do
68
- expect{@project = Roject::Project.load("project.rb")}.not_to raise_error
69
- expect(@project).to be_an_instance_of Roject::Project
68
+ # Author: Anshul Kharbanda
69
+ # Created: 7 - 25 - 2016
70
+ describe 'loading' do
71
+ # Describe Roject::Project::exist?
72
+ #
73
+ # Check if a project file exists in the current directory
74
+ #
75
+ # Parameter: filename - the filename to check
76
+ # (defaults to the default filename)
77
+ #
78
+ # Returns: true if the project file exists in the current
79
+ # directory
80
+ describe '::exist?' do
81
+ context 'with a filename given' do
82
+ it 'checks if the given project filename exists in the current directory' do
83
+ expect(Roject::Project).to be_exist(@foofle)
84
+ end
85
+ end
86
+
87
+ context 'with no filename given' do
88
+ it 'checks if the default project filename exists in the current directory' do
89
+ expect(Roject::Project).to be_exist
90
+ end
70
91
  end
71
92
  end
72
93
 
73
- context 'with no filename given' do
74
- it 'loads a project from the default filename' do
75
- expect{@project = Roject::Project.load}.not_to raise_error
76
- expect(@project).to be_an_instance_of Roject::Project
94
+ # Describe Roject::Project::load
95
+ #
96
+ # Loads a Project from the project file with the given filename
97
+ #
98
+ # Parameter: filename - the name of the file to parse
99
+ #
100
+ # Return: Project loaded from the file
101
+ describe '::load' do
102
+ # Check when filename is given
103
+ context 'with a filename given' do
104
+ it 'loads a project from the given filename' do
105
+ # Test loading foobar.rb file
106
+ expect{@project = Roject::Project.load(@foofle)}.not_to raise_error
107
+ expect(@project).to be_an_instance_of Roject::Project
108
+ expect(@project.config).to eql @foocfg
109
+ end
110
+ end
111
+
112
+ # Check when filename is not given
113
+ context 'with no filename given' do
114
+ it 'loads a project from the default filename' do
115
+ # Test loading default file
116
+ expect{@project = Roject::Project.load}.not_to raise_error
117
+ expect(@project).to be_an_instance_of Roject::Project
118
+ end
77
119
  end
78
120
  end
79
121
 
80
- after :all do
81
- @project.instance_variable_set :@makers, {}
122
+ # Describe Roject::Project::open
123
+ #
124
+ # Alias for load if no block is given. Evaluates the given
125
+ # block in the context of the project if block is given
126
+ #
127
+ # Parameter: filename - the name of the file to parse
128
+ # (defaults to the default filename)
129
+ # Parameter: block - the block to evaluate within the
130
+ # context of the project
131
+ #
132
+ # Return: Project loaded from the file
133
+ describe '::open' do
134
+ # Check for when block is given
135
+ context 'with a block given' do
136
+ it 'loads the project and evaluates it within the given block' do
137
+ project = nil
138
+ expect { Roject::Project.open { project = self } }.not_to raise_error
139
+ expect(project).to be_an_instance_of Roject::Project
140
+ end
141
+ end
142
+
143
+ # Check for when no block is given
144
+ context 'with no block given' do
145
+ it 'loads the project' do
146
+ expect { @project = Roject::Project.open }.not_to raise_error
147
+ expect(@project).to be_an_instance_of Roject::Project
148
+ end
149
+ end
82
150
  end
151
+
152
+ # Describe Roject::Project#reload
153
+ #
154
+ # Reloads the project with the file with the given filename
155
+ #
156
+ # Parameter: filename - the name of the file to parse
157
+ # (defaults to the default filename)
158
+ describe '#reload' do
159
+ context 'with a filename given' do
160
+ it 'loads the given filename into the project' do
161
+ # Test loading foobar.rb file
162
+ expect{@project.reload("foobar.rb")}.not_to raise_error
163
+ expect(@project).to be_an_instance_of Roject::Project
164
+ expect(@project.config).to eql @foocfg
165
+ end
166
+ end
167
+
168
+ context 'with no filename given' do
169
+ it 'loads the default filename into the project' do
170
+ # Test loading default file
171
+ expect{@project.reload}.not_to raise_error
172
+ expect(@project).to be_an_instance_of Roject::Project
173
+ end
174
+ end
175
+ end
176
+
177
+ # Delete makers
178
+ after :all do @project.instance_variable_set :@makers, {} end
83
179
  end
84
180
 
85
181
  # Describe Roject::Project makers
@@ -218,5 +314,6 @@ describe Roject::Project do
218
314
  end
219
315
  end
220
316
 
317
+ # Change back to root
221
318
  after :all do Dir.chdir "../.." end
222
319
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roject
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anshul Kharbanda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-25 00:00:00.000000000 Z
11
+ date: 2016-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: general
@@ -70,13 +70,15 @@ description: Roject is a programming project manager written in Ruby. With Rojec
70
70
  you can create and edit projects based on templates using simple commands without
71
71
  a heavy IDE.
72
72
  email: akanshul97@gmail.com
73
- executables: []
73
+ executables:
74
+ - roject
74
75
  extensions: []
75
76
  extra_rdoc_files: []
76
77
  files:
77
78
  - LICENSE
78
79
  - README.md
79
80
  - Rakefile
81
+ - bin/roject
80
82
  - exp/project/_templates/header.general
81
83
  - exp/project/_templates/source.general
82
84
  - exp/project/foobar.rb