From 18349a0a1f065c3dee958b727b44d6ace8cc3b2f Mon Sep 17 00:00:00 2001 From: realtradam Date: Tue, 7 Feb 2023 17:28:48 -0500 Subject: first release --- Gemfile.lock | 19 ++++++ README.md | 40 ++--------- exe/mruby_gem_scaffolding | 22 ++++++ lib/mruby_gem_scaffolding.rb | 125 ++++++++++++++++++++++++++++++++++- lib/mruby_gem_scaffolding/version.rb | 2 +- mruby_gem_scaffolding.gemspec | 13 ++-- 6 files changed, 176 insertions(+), 45 deletions(-) create mode 100644 Gemfile.lock create mode 100755 exe/mruby_gem_scaffolding 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"] = + < +#include + +// 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"] = + <= 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 -- cgit v1.2.3