summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2023-02-07 17:28:48 -0500
committerrealtradam <[email protected]>2023-02-07 17:28:48 -0500
commit18349a0a1f065c3dee958b727b44d6ace8cc3b2f (patch)
tree5feec2d26c522ced934fe1d26514d787c18c6740
parent5852ca2761e1cadc95e2ffd70fed47a1cf8f7610 (diff)
downloadmruby_gem_scaffolding-18349a0a1f065c3dee958b727b44d6ace8cc3b2f.tar.gz
mruby_gem_scaffolding-18349a0a1f065c3dee958b727b44d6ace8cc3b2f.zip
first releasev1.0.0
-rw-r--r--Gemfile.lock19
-rw-r--r--README.md40
-rwxr-xr-xexe/mruby_gem_scaffolding22
-rw-r--r--lib/mruby_gem_scaffolding.rb125
-rw-r--r--lib/mruby_gem_scaffolding/version.rb2
-rw-r--r--mruby_gem_scaffolding.gemspec13
6 files changed, 176 insertions, 45 deletions
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644
index 0000000..27d2a09
--- /dev/null
+++ b/Gemfile.lock
@@ -0,0 +1,19 @@
+PATH
+ remote: .
+ specs:
+ mruby_gem_scaffolding (0.1.0)
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ rake (12.3.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ mruby_gem_scaffolding!
+ rake (~> 12.0)
+
+BUNDLED WITH
+ 2.1.4
diff --git a/README.md b/README.md
index 66adf41..4922e21 100644
--- a/README.md
+++ b/README.md
@@ -1,40 +1,8 @@
-# MrubyGemScaffolding
+# mruby Gem Scaffolding
-Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mruby_gem_scaffolding`. To experiment with that code, run `bin/console` for an interactive prompt.
+This gem allows you to easily create a basic working scaffold of an mruby gem.
-TODO: Delete this and the text above, and describe your gem
+Install the gem by `gem install mruby_gem_scaffolding` and then run with `mruby_gem_scaffolding`
-## Installation
+https://rubygems.org/gems/mruby_gem_scaffolding
-Add this line to your application's Gemfile:
-
-```ruby
-gem 'mruby_gem_scaffolding'
-```
-
-And then execute:
-
- $ bundle install
-
-Or install it yourself as:
-
- $ gem install mruby_gem_scaffolding
-
-## Usage
-
-TODO: Write usage instructions here
-
-## Development
-
-After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
-
-To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
-
-## Contributing
-
-Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mruby_gem_scaffolding.
-
-
-## License
-
-The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
diff --git a/exe/mruby_gem_scaffolding b/exe/mruby_gem_scaffolding
new file mode 100755
index 0000000..b101570
--- /dev/null
+++ b/exe/mruby_gem_scaffolding
@@ -0,0 +1,22 @@
+#!/usr/bin/env ruby
+
+require "mruby_gem_scaffolding"
+
+print "Enter your project name: "
+project_name = gets.chomp
+
+Dir.mkdir project_name unless File.exists? project_name
+if !Dir.empty? project_name
+ puts "#{project_name} directory is not empty. Quitting..."
+ return
+end
+
+print "Enter your author name: "
+user_name = gets.chomp
+
+MrubyGemScaffolding.write(
+ "./#{project_name}",
+ MrubyGemScaffolding.generate(user_name: user_name, project_name: project_name)
+)
+
+puts "Done!"
diff --git a/lib/mruby_gem_scaffolding.rb b/lib/mruby_gem_scaffolding.rb
index 8dca6f3..67ffba6 100644
--- a/lib/mruby_gem_scaffolding.rb
+++ b/lib/mruby_gem_scaffolding.rb
@@ -1,6 +1,127 @@
require "mruby_gem_scaffolding/version"
module MrubyGemScaffolding
- class Error < StandardError; end
- # Your code goes here...
+ module Utility
+ class << self
+ # from thor gem
+ def snake_case(str)
+ return str.downcase if str =~ /^[A-Z_]+$/
+ str.gsub(/\B[A-Z]/, '_\&').squeeze("_") =~ /_*(.*)/
+ Regexp.last_match(-1).downcase
+ end
+
+ # from thor gem
+ def camel_case(str)
+ return str if str !~ /_/ && str =~ /[A-Z]+.*/
+ str.split("_").map(&:capitalize).join
+ end
+ end
+ end
+
+ class << self
+ def empty_project
+ {
+ "README.md" => '',
+ "mrbgem.rake" => '',
+ "include" => {},
+ "mrblib" => {},
+ "src" => {},
+ "tools" => {},
+ "test" => {},
+ "LICENSE" => '',
+ }
+ end
+
+ def generate(user_name:, project_name:)
+ result = empty_project
+
+ result["README.md"] =
+ <<MULTILINE
+# #{Utility.camel_case(project_name)}
+An mruby gem created by #{user_name} using mruby_gem_scaffolding.
+MULTILINE
+
+ result["mrbgem.rake"] =
+ <<MULTILINE
+MRuby::Gem::Specification.new('#{Utility.snake_case(project_name)}') do |spec|
+ spec.license = 'MIT'
+ spec.author = '#{user_name}'
+end
+MULTILINE
+
+ result["src"]["main.c"] =
+ <<MULTILINE
+#include <mruby.h>
+#include <stdio.h>
+
+// defining the function to be later bound to a ruby method
+static mrb_value
+hello_world(mrb_state *mrb, mrb_value self)
+{
+ printf("Hello World");
+
+ return mrb_nil_value(); // return null
+}
+
+// gem initializer
+void
+mrb_#{Utility.snake_case(project_name)}_gem_init(mrb_state* mrb) {
+ struct RClass *#{Utility.snake_case(project_name)}_class = mrb_define_module(mrb, "#{Utility.camel_case(project_name)}");
+ mrb_define_class_method(
+ mrb, // Mruby VM state
+ #{Utility.snake_case(project_name)}_class, // Class we bind method to
+ "say_hello", // Name of method
+ hello_world, // Function we are binding as a method
+ MRB_ARGS_NONE() // How many arguments are optional/required
+ );
+}
+
+// gem finalizer
+void
+mrb_#{Utility.snake_case(project_name)}_gem_final(mrb_state* mrb) {
+
+}
+MULTILINE
+
+ result["LICENSE"] =
+ <<MULTILINE
+The MIT License (MIT)
+
+Copyright (c) #{Time.now.year} #{user_name}
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+MULTILINE
+
+ return result
+ end
+
+ def write(dir, hash_data)
+ Dir.mkdir dir unless File.exists? dir
+ hash_data.each do |key, value|
+ if value.is_a? Hash
+ write("#{dir}/#{key}", value)
+ else
+ File.open("#{dir}/#{key}", 'w') { |file| file.write(value) }
+ end
+ end
+ end
+ end
+
end
diff --git a/lib/mruby_gem_scaffolding/version.rb b/lib/mruby_gem_scaffolding/version.rb
index 9d33fe9..e629139 100644
--- a/lib/mruby_gem_scaffolding/version.rb
+++ b/lib/mruby_gem_scaffolding/version.rb
@@ -1,3 +1,3 @@
module MrubyGemScaffolding
- VERSION = "0.1.0"
+ VERSION = "1.0.0"
end
diff --git a/mruby_gem_scaffolding.gemspec b/mruby_gem_scaffolding.gemspec
index dc61992..e9a944a 100644
--- a/mruby_gem_scaffolding.gemspec
+++ b/mruby_gem_scaffolding.gemspec
@@ -8,15 +8,15 @@ Gem::Specification.new do |spec|
spec.summary = %q{Creates a blank mruby gem for you with all the required files generated automatically.}
#spec.description = %q{TODO: Write a longer description or delete this line.}
- spec.homepage = "TODO: Put your gem's website or public repo URL here."
+ #spec.homepage = "TODO: Put your gem's website or public repo URL here."
spec.license = "MIT"
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
- spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
+ #spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
- spec.metadata["homepage_uri"] = spec.homepage
- spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
- spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
+ #spec.metadata["homepage_uri"] = spec.homepage
+ spec.metadata["source_code_uri"] = "https://github.com/realtradam/mruby_gem_scaffolding"
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = "exe"
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
+ #spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
+ spec.executables = "mruby_gem_scaffolding"
spec.require_paths = ["lib"]
end