├── .document ├── .gitignore ├── .gitmodules ├── .rspec ├── .yardopts ├── ChangeLog.md ├── Gemfile ├── GemspecYML.md ├── LICENSE.txt ├── README.md ├── Rakefile ├── bin ├── mine └── ore ├── data └── ore │ ├── abbreviations.txt │ ├── common_namespaces.yml │ └── templates │ ├── bin │ └── bin │ │ └── [name].erb │ └── gem │ ├── ChangeLog.md.erb │ ├── ChangeLog.rdoc.erb │ ├── ChangeLog.tt.erb │ ├── README.md.erb │ ├── README.rdoc.erb │ ├── README.tt.erb │ ├── Rakefile.erb │ ├── [name].gemspec.erb │ ├── lib │ ├── [namespace_path].rb.erb │ └── [namespace_path] │ │ └── version.rb.erb │ └── template.yml ├── gemspec.yml ├── lib ├── ore.rb └── ore │ ├── actions.rb │ ├── cli.rb │ ├── config.rb │ ├── generator.rb │ ├── naming.rb │ ├── options.rb │ ├── template.rb │ ├── template │ ├── directory.rb │ ├── exceptions.rb │ ├── exceptions │ │ └── invalid_template.rb │ ├── helpers.rb │ ├── helpers │ │ ├── markdown.rb │ │ ├── rdoc.rb │ │ └── textile.rb │ ├── interpolations.rb │ ├── markup.rb │ └── template.rb │ └── version.rb ├── ore.gemspec └── spec ├── gemspec_examples.rb ├── generator_spec.rb ├── helpers ├── generator.rb └── matchers.rb ├── naming_spec.rb ├── spec_helper.rb └── template └── helpers ├── markdown_spec.rb ├── rdoc_spec.rb └── textile_spec.rb /.document: -------------------------------------------------------------------------------- 1 | - 2 | ChangeLog.md 3 | LICENSE.txt 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /pkg 2 | /doc 3 | .DS_Store 4 | .bundle 5 | /.yardoc 6 | *.gem 7 | *.swp 8 | *~ 9 | Gemfile.lock 10 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "data/ore/templates/gemspec_yml"] 2 | path = data/ore/templates/gemspec_yml 3 | url = https://github.com/ruby-ore/gemspec_yml.git 4 | [submodule "data/ore/templates/bundler"] 5 | path = data/ore/templates/bundler 6 | url = https://github.com/ruby-ore/bundler.git 7 | [submodule "data/ore/templates/rspec"] 8 | path = data/ore/templates/rspec 9 | url = https://github.com/ruby-ore/rspec.git 10 | [submodule "data/ore/templates/minitest"] 11 | path = data/ore/templates/minitest 12 | url = https://github.com/ruby-ore/minitest.git 13 | [submodule "data/ore/templates/yard"] 14 | path = data/ore/templates/yard 15 | url = https://github.com/ruby-ore/yard.git 16 | [submodule "data/ore/templates/rdoc"] 17 | path = data/ore/templates/rdoc 18 | url = https://github.com/ruby-ore/rdoc.git 19 | [submodule "data/ore/templates/rubygems_tasks"] 20 | path = data/ore/templates/rubygems_tasks 21 | url = https://github.com/ruby-ore/rubygems_tasks.git 22 | [submodule "data/ore/templates/test_unit"] 23 | path = data/ore/templates/test_unit 24 | url = https://github.com/ruby-ore/test_unit.git 25 | [submodule "data/ore/templates/travis"] 26 | path = data/ore/templates/travis 27 | url = https://github.com/ruby-ore/travis.git 28 | [submodule "data/ore/templates/bsd"] 29 | path = data/ore/templates/bsd 30 | url = https://github.com/ruby-ore/bsd.git 31 | [submodule "data/ore/templates/gpl"] 32 | path = data/ore/templates/gpl 33 | url = https://github.com/ruby-ore/gpl.git 34 | [submodule "data/ore/templates/lgpl"] 35 | path = data/ore/templates/lgpl 36 | url = https://github.com/ruby-ore/lgpl.git 37 | [submodule "data/ore/templates/hg"] 38 | path = data/ore/templates/hg 39 | url = https://github.com/ruby-ore/hg.git 40 | [submodule "data/ore/templates/git"] 41 | path = data/ore/templates/git 42 | url = https://github.com/ruby-ore/git.git 43 | [submodule "data/ore/templates/apache"] 44 | path = data/ore/templates/apache 45 | url = https://github.com/ruby-ore/apache.git 46 | [submodule "data/ore/templates/gem_package_task"] 47 | path = data/ore/templates/gem_package_task 48 | url = https://github.com/ruby-ore/gem_package_task.git 49 | [submodule "data/ore/templates/mit"] 50 | path = data/ore/templates/mit 51 | url = https://github.com/ruby-ore/mit.git 52 | [submodule "data/ore/templates/code_climate"] 53 | path = data/ore/templates/code_climate 54 | url = https://github.com/ruby-ore/code_climate.git 55 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --colour --format documentation 2 | -------------------------------------------------------------------------------- /.yardopts: -------------------------------------------------------------------------------- 1 | --markup markdown --title 'Ore Documentation' --protected 2 | -------------------------------------------------------------------------------- /ChangeLog.md: -------------------------------------------------------------------------------- 1 | ### 0.11.0 / 2015-08-25 2 | 3 | * Added {Ore::Template::Helpers::Markdown}. 4 | * Added {Ore::Template::Helpers::Textile}. 5 | * Added {Ore::Template::Helpers::RDoc}. 6 | * Merged `Ore::Options` into {Ore::Generator}. 7 | * Moved SCM initialization code into {Ore::Generator#initialize_scm!}. 8 | * Moved data out of {Ore::Naming} and into `data/ore/` files. 9 | 10 | #### CLI 11 | 12 | * Added the `--namespace` option for overriding the gem namespace. 13 | * Added `--author`. 14 | * Added `--markup`. 15 | * Default `--markup` to `markdown`. 16 | * Enable `--bundler` by default. 17 | * Alias `--homepage` to `--website`. 18 | * Removed `--license` in favor of `[--mit | --bsd | --apache | --lgpl | --gpl]`. 19 | * Removed `--bundler-tasks` in favor of `--bundler --no-rubygems-tasks`. 20 | 21 | #### Templates 22 | 23 | * Moved all templates out into git submodules. 24 | * Added templates for [MIT][mit], [BSD][bsd], [GPLv3][gpl], [LGPLv3][lgpl] and 25 | [Apache 2.0][apache] licenses. 26 | * Added a [Travis][travis] template. 27 | * Added a [CodeClimate][code_climate] template. 28 | 29 | ##### bundler 30 | 31 | * Require bundler ~> 1.10. 32 | * Require rake ~> 10.0. 33 | * Use `https://rubygems.org/` as the `Gemfile` source. 34 | * Add `.bundle` to any SCM ignore files. 35 | * Merged in the [bundler_tasks] template. 36 | 37 | ##### gem 38 | 39 | * Renamed `base` to `gem`. 40 | * Merged in the [gemspec] template. 41 | * Simply require `bundler/setup` to activate bundler. 42 | * If a rake task gem cannot be loaded, define a dummy task that prints the error 43 | message. 44 | * Added support for listing files from git submodules. 45 | 46 | ##### gemspec_yml 47 | 48 | * Added support for automatically listing files from git submodules. 49 | 50 | ##### minitest 51 | 52 | * Updated to Minitest 5 (@elskwid). 53 | 54 | ##### rdoc 55 | 56 | * Require rdoc ~> 4.0. 57 | * Generate a `.rdoc_options` file. 58 | * Allow markdown or textile markup with rdoc. 59 | 60 | ##### yard 61 | 62 | * Add `.yardoc` to any SCM ignore files. 63 | 64 | ### 0.10.0 / 2012-10-14 65 | 66 | * Require thor ~> 0.15. 67 | * Strip the `ore-` prefix from the template name in {Ore::Template.register}. 68 | * Allow {Ore::Generator#disable_template} to disable templates that are not 69 | installed. 70 | 71 | #### Templates 72 | 73 | * Added the [mini_test] template. 74 | * Moved the `rvmrc` template out into the [rvm] template. 75 | * Moved the `jeweler_tasks` template out into the [jeweler] template. 76 | * Removed the `gem_test` template. 77 | 78 | #### CLI 79 | 80 | * Added a `--version` option to the `ore` command. 81 | 82 | ### 0.9.4 / 2012-07-23 83 | 84 | * Do not initialize the repository, if .git or .hg directories already exist. 85 | 86 | #### Templates 87 | 88 | * List all development dependencies in the [gemspec] and [gemspec_yml] 89 | templates. 90 | * Sort dependencies alphabetically. 91 | * Require `bundler/setup` in the [bin] script, if Bundler is enabled. 92 | 93 | ### 0.9.3 / 2012-05-28 94 | 95 | * Added the following template variables to {Ore::Generator}: 96 | * `@scm_user` - The username used by the SCM. 97 | * `@scm_email` - The email address used by the SCM. 98 | * `@uri` - The URI parsed from the `@homepage` variable. 99 | * `@markup_ext` - The file-extension used by the markup. 100 | * Support autodetecting the user name by invoking `git config user.name` or 101 | `hg showconfig ui.username`. 102 | * Support autodetecting the email address by invoking `git config user.email` or 103 | `hg showconfig ui.username`. 104 | 105 | #### Templates 106 | 107 | * Further simplified the `[name].gemspec` file in the [gemspec_yml] 108 | template. 109 | * Also fixed a small typo that set `gemspec.required_rubygems_version` to 110 | the value of `required_ruby_version` from the `gemspec.yml` file. 111 | * Fixed the `ChangeLog` entry in the `.document` file, from the [yard] template. 112 | 113 | ### 0.9.2 / 2012-05-21 114 | 115 | #### Templates 116 | 117 | * Test if `@email` is set, before emitting it in the [gemspec] template. 118 | * Convert the `@homepage` instance variable to a String in the [gemspec] 119 | template. 120 | * Specify the exact `ChangeLog` file in the `.document` file in the [yard] 121 | template. 122 | 123 | ### 0.9.1 / 2012-05-20 124 | 125 | * Require thor ~> 0.14. 126 | 127 | #### Templates 128 | 129 | * Use the newer `RDoc::Task` in the [rdoc] template. 130 | * Require rdoc ~> 3.0. 131 | * Simplify the `.rvmrc` file in the [rvmrc] template. 132 | 133 | ### 0.9.0 / 2012-04-28 134 | 135 | * Removed the ore-core dependency. 136 | * Removed the env dependency. 137 | * Switched from ore-tasks to rubygems-tasks ~> 0.2. 138 | * Added {Ore::Naming} from `ore-core`. 139 | * Added `Ore::Options`. 140 | * Added {Ore::Actions}. 141 | * Added {Ore::Template::Helpers#rubygems_tasks?}. 142 | * Added {Ore::Template::Helpers#bundler_tasks?}. 143 | * Added {Ore::Template::Helpers#gem_package_task?}. 144 | * Added {Ore::Template::Directory#ignore}. 145 | * Added {Ore::Template::Directory#dependencies}. 146 | * Added {Ore::Template::Directory#development_dependencies}. 147 | * Renamed `Ore::Config.default_options` to {Ore::Config.options}. 148 | * Renamed `Ore::Generator.defaults` to `Ore::Options.defaults`. 149 | * Renamed `Ore::Generator.generator_option` to `Ore::Options::ClassMethods`. 150 | * Renamed `Ore::Generator.templates` to {Ore::Template.templates}. 151 | * Renamed `Ore::Generator.template?` to {Ore::Template.template?}. 152 | * Renamed `Ore::Generator.register_template` to {Ore::Template.register}. 153 | 154 | #### Templates 155 | 156 | * Added the [gemspec] template. 157 | * Added the [gemspec_yml] template. 158 | * Added the [bundler_tasks] template. 159 | * Added the [gem\_package\_task] template. 160 | * Added the [hg] template. 161 | * Added the [rubygems_tasks] template. 162 | * Removed the `ore_tasks` template. 163 | * Define dependencies in the `template.yml` files. 164 | * Simplified the `[name].gemspec` file in the [gem] template. 165 | * Moved the `.gitignore` file into the [git] template. 166 | * If [git] is enabled and `github.user` is set in `~/.gitconfig`, default 167 | the `@homepage` variable to a `https://github.com/` URL. 168 | * Require the newer `rdoc/task` file in the [rdoc] template. 169 | * Relaxed the `rake` dependency in the [bundler] template to `~> 0.8`. 170 | * Relaxed the `bundler` dependency in the [bundler` template to `~> 1.0`. 171 | 172 | #### CLI 173 | 174 | * Removed the `ore gem` and `ore gemspec` sub-commands. 175 | * Added the `--bug-tracker` option to `mine`. 176 | * `mine` now hides the output of all commands. 177 | * `mine` suppresses all output when `--quiet` is specified. 178 | 179 | ### 0.8.1 / 2011-07-11 180 | 181 | * Generated `.gemspec` file: 182 | * Fixed a redundancy. 183 | * Load the `version.rb` file, after populating `$LOAD_PATH`. 184 | * Generated `Rakefile`: 185 | * Use `warn` instead of `STDERR.puts`. 186 | * Losen generated `yard` dependency to `~> 0.7`. 187 | 188 | ### 0.8.0 / 2011-06-18 189 | 190 | * Added the `markup`, `date`, `year`, `month` and `day` keywords to 191 | {Ore::Template::Interpolations}. 192 | * Added `encoding` comments to generated `Rakefile` and `*.gemspec` files. 193 | * Fixed chmoding of bin files. 194 | * Updated the generated `yard` dependency to `~> 0.7.0`. 195 | * No longer add `has_yard: true` to generated `gemspec.yml` files. 196 | * Generate a pure-Ruby `*.gemspec` file, which loads `gemspec.yml`. 197 | 198 | ### 0.7.2 / 2011-02-26 199 | 200 | * Require ore-core ~> 0.1, >= 0.1.4. 201 | * Added `Ore::Generator.template?`. 202 | * Added {Ore::Generator#enabled_templates}. 203 | * Added {Ore::Generator#disabled_templates}. 204 | * Added {Ore::Generator#templates}. 205 | * Added {Ore::Generator#generated_dirs}. 206 | * Added {Ore::Generator#generated_files}. 207 | * Allow {Ore::Template::Helpers#includes} to yield output. 208 | * Allow the `bundler` template to load `gemfile_prelude`, `gemfile` and 209 | `gemfile_development` includes. 210 | * Allow `--rdoc` to disable `--yard`. 211 | * Set `@markup` to `:rdoc` in the `rdoc` template. 212 | * Added separate `.document` files for the `rdoc` and `yard` templates. 213 | * Added the `doc` alias-task to the `rdoc` and `yard` templates. 214 | * Added `html/` to the generated `.gitignore` file in the `rdoc` template. 215 | * Allow `--test-unit` to disable `--rspec`. 216 | * Fixed the `test_unit` template. 217 | * Added a `Rakefile` task to the `test_unit` template. 218 | * Define options for installed templates as well. 219 | 220 | ### 0.7.1 / 2011-02-20 221 | 222 | * Added `Ore::Generator#generate_dir`. 223 | * Added `Ore::Generator#generate_file`. 224 | * Only chmod generated files, if they are supposed to be executable. 225 | 226 | ### 0.7.0 / 2011-02-19 227 | 228 | * Require ore-core ~> 0.1, >= 0.1.2. 229 | * Added {Ore::Template::Helpers#git?}. 230 | * Added {Ore::Template::Helpers#bin?}. 231 | * Added the `bin` template and `--bin` option to {Ore::Generator}. 232 | * Enable `--ore-tasks` by default. 233 | * Allow `--jeweler-tasks` to disable `--ore-tasks`. 234 | * Relax ore-tasks dependency to `~> 0.4`. 235 | * Relax rspec dependency to `~> 2.4`. 236 | * Relax ore-core dependency to `~> 0.1`. 237 | 238 | ### 0.6.0 / 2011-02-12 239 | 240 | * Require ore-core ~> 0.1.2. 241 | * Opted into [gem-testers.org](http://gem-testers.org/). 242 | * Added the `rvmrc` template and `--rvmrc` option to {Ore::Generator}: 243 | * Generates an `.rvmrc` file that creates a new gemset for the project 244 | and supports Bundler. 245 | * Added `mailto:` to the `Email` links in the generated `README` files. 246 | * Renamed the `ore cut` command to `ore gem`. 247 | * Use `__FILE__` instead of hard-coding the file name into the generated 248 | `.gemspec` file. 249 | * No longer necessary to require `ore/specification` in the generated 250 | `Gemfile`: 251 | * The new generated `.gemspec` files can auto-load `Ore::Specification`. 252 | * Do not include `ore-core` in the generated `Gemfile`, if `ore-tasks` 253 | has already been included. 254 | * Bumped the `ore-tasks` dependency to `~> 0.4.0` in the `ore_tasks` 255 | template. 256 | * Fixed typos in the documentation thanks to 257 | [yard-spellcheck](http://github.com/postmodern/yard-spellcheck). 258 | 259 | ### 0.5.0 / 2011-01-19 260 | 261 | * Require ore-core ~> 0.1.1. 262 | * Require rspec ~> 2.4.0. 263 | * Load default options from `~/.ore/options.yml`. 264 | * Added the `gem_test` template and `--gem-test` to {Ore::Generator}. 265 | This opts-in projects to be tested via the `gem test` command. 266 | * Auto-define options in {Ore::Generator} for builtin templates. 267 | * Added `lib/ore.rb`. 268 | * Added {Ore::Config.enable!}. 269 | * Added {Ore::Config.disable!}. 270 | * Added `Ore::Config.default_options`. 271 | * Added `Ore::Generator.defaults`. 272 | * Added `Ore::Generator.generator_option`. 273 | * Added `vendor/cache/*.gem` to `.gitignore` if `--bundler` is specified. 274 | * Attempt to auto-load `ore/specification` in the generated `*.gemspec` 275 | files. 276 | 277 | ### 0.4.1 / 2010-12-17 278 | 279 | * Added a post-install message. 280 | * Added links to [rubydoc.info](http://rubydoc.info) in the README 281 | templates. 282 | * Add `Gemfile.lock` to the generated `.gitignore` file when `--bundler` 283 | is used. 284 | * Use `platforms :jruby` and `platforms :ruby` to separate JRuby and 285 | non-JRuby dependencies when generating the `Gemfile`. 286 | * Fixed the link syntax in the Textile README template. 287 | 288 | ### 0.4.0 / 2010-11-24 289 | 290 | * Ore Template variables are now loaded from the `variables` Hash within 291 | a `template.yml` file: 292 | 293 | variables: 294 | x: foo 295 | y: bar 296 | 297 | * Allow Ore Templates to list other templates to be enabled via the 298 | `enable` field within a `template.yml` file: 299 | 300 | enable: 301 | - yard 302 | - rspec 303 | 304 | * Allow Ore Templates to list other templates to be disabled via the 305 | `disable` field within a `template.yml` file: 306 | 307 | disable: 308 | - rdoc 309 | 310 | * Renamed the `ore_depencency` template variable to `ore_core_dependency`. 311 | * Renamed `@namespace_dir` to `@namespace_path` within {Ore::Generator}. 312 | * `@namespace_dir` now stores the last sub-directory name, derived from 313 | the project name. 314 | * Include any `_development_dependencies.erb` and `_dependencies.erb` 315 | includes into the generated `gemspec.yml` file. 316 | * Added a default Example to generated `README` files. 317 | * Bumped the `ore_tasks_dependency` template variable to `~> 0.3.0`. 318 | * Bumped the `jeweler_dependency` template variable to `~> 1.5.0`. 319 | 320 | ### 0.3.0 / 2010-11-07 321 | 322 | * Split all non-CLI and non-Generator related code out into 323 | [ore-core](http://github.com/ruby-ore/ore-core). 324 | * {Ore::Generator}: 325 | * Added {Ore::Template::Helpers#jeweler_tasks?}. 326 | * Added `Ore::Template::Helpers#ore_tasks?`. 327 | * Do not include `ore-core` as a development dependency if either 328 | `--bundler` or `--ore-tasks` is enabled. 329 | 330 | ### 0.2.3 / 2010-11-01 331 | 332 | * Fixed path interpolation on Windows: 333 | * Windows does not allow the `:` character in paths, so path interpolation 334 | keywords are now wrapped in `[` and `]` characters. 335 | 336 | interpolate("[name].gemspec") 337 | # => "my-project.gemspec" 338 | 339 | * Do not include `ore-tasks` as a developmnet dependency in generated 340 | projects that also use Bundler. 341 | * Added more specs to {Ore::Generator} and the builtin templates. 342 | 343 | ### 0.2.2 / 2010-10-30 344 | 345 | * Added `Ore::Project#root`. 346 | 347 | ### 0.2.1 / 2010-10-29 348 | 349 | * Ignore 'ruby' and 'java' from namespace directories returned from 350 | `Ore::Naming#namespace_dirs_of`. 351 | * Ignore 'ruby' and 'java' from module names returned from 352 | `Ore::Naming#modules_of`. 353 | 354 | ### 0.2.0 / 2010-10-27 355 | 356 | * Added `Ore::Project#requirements`. 357 | * Added `Ore::Settings#set_requirements!`. 358 | * Added {Ore::Template::InvalidTemplate}. 359 | * Added {Ore::Template::Directory#load!}. 360 | * Suppress `no rubyforge_project specified` warnings by setting the 361 | `rubyforge_project` to the project name in `Ore::Project#to_gemspec`. 362 | * Do not add extra dependencies to the `gemspec.yml` file when generating 363 | a Bundler enabled project. Extra dependencies will be added to the 364 | `Gemfile` and controlled by Bundler. 365 | * Allow Ore template directories to contain `template.yml` which may list 366 | template variables: 367 | 368 | data: 369 | variable: Value 370 | 371 | ### 0.1.4 / 2010-10-26 372 | 373 | * Increased documentation coverage. 374 | * Make sure {Ore::Config.builtin_templates} and 375 | {Ore::Config.installed_templates} only yield valid directories. 376 | * Ensure that `Ore::Settings` handles versions as Strings. 377 | * Fixed two typos. 378 | 379 | ### 0.1.3 / 2010-10-25 380 | 381 | * Fixed URLs in the `gemspec.yml` and {file:README.md}. 382 | 383 | ### 0.1.2 / 2010-10-25 384 | 385 | * Renamed `--jeweler` to `--jeweler-tasks` in {Ore::Generator}. 386 | * Renamed `--ore` to `--ore-tasks` in {Ore::Generator}. 387 | * Fixed the `remove` task in {Ore::CLI}. 388 | 389 | ### 0.1.1 / 2010-10-25 390 | 391 | * Show stopper bug fixed. 392 | 393 | ### 0.1.0 / 2010-10-25 394 | 395 | * Initial release: 396 | * Added {Ore::Config}. 397 | * Added `Ore::Naming`. 398 | * Added `Ore::DocumentFile`. 399 | * Added `Ore::Versions`: 400 | * Added `Ore::Versions::Version`. 401 | * Added `Ore::Versions::VersionConstant`. 402 | * Added `Ore::Versions::VersionFile`. 403 | * Added `Ore::Project`: 404 | * Added `Ore::Checks`. 405 | * Added `Ore::Defaults`. 406 | * Added `Ore::Settings`. 407 | * Added `Ore::Specification`. 408 | * Added {Ore::Template}: 409 | * Added {Ore::Template::Directory}. 410 | * Added {Ore::Template::Interpolations}. 411 | * Added {Ore::Template::Helpers}. 412 | * Added {Ore::Generator}. 413 | 414 | [gem]: https://github.com/ruby-ore/ore/tree/master/data/ore/templates/gem 415 | [apache]: https://github.com/ruby-ore/apache 416 | [bin]: https://github.com/ruby-ore/ore/tree/master/data/ore/templates/bin 417 | [bsd]: https://github.com/ruby-ore/bsd 418 | [bundler]: https://github.com/ruby-ore/bundler 419 | [bundler_tasks]: https://github.com/ruby-ore/bundler/blob/master/_tasks.erb 420 | [code_climate]: https://github.com/ruby-ore/code_climate 421 | [gemspec]: https://github.com/ruby-ore/ore/blob/master/data/ore/templates/gem/%5Bname%5D.gemspec.erb 422 | [gemspec_yml]: https://github.com/ruby-ore/gemspec_yml 423 | [gem\_package\_task]: https://github.com/ruby-ore/gem_package_task 424 | [git]: https://github.com/ruby-ore/git 425 | [gpl]: https://github.com/ruby-ore/gpl 426 | [hg]: https://github.com/ruby-ore/hg 427 | [jeweler_tasks]: https://github.com/ruby-ore/jeweler_tasks 428 | [lgpl]: https://github.com/ruby-ore/lgpl 429 | [mit]: https://github.com/ruby-ore/mit 430 | [rdoc]: https://github.com/ruby-ore/rdoc 431 | [rspec]: https://github.com/ruby-ore/rspec 432 | [rubygems_tasks]: https://github.com/ruby-ore/rubygems_tasks 433 | [rvm]: https://github.com/ruby-ore/rvm 434 | [test_unit]: https://github.com/ruby-ore/test_unit 435 | [travis]: https://github.com/ruby-ore/travis 436 | [mini_test]: https://github.com/ruby-ore/mini_test 437 | [yard]: https://github.com/ruby-ore/yard 438 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | 5 | group :development do 6 | gem 'rake', '~> 10.0' 7 | gem 'rubygems-tasks', '~> 0.2' 8 | 9 | gem 'rspec', '~> 3.0' 10 | 11 | gem 'kramdown' 12 | gem 'yard', '~> 0.9' 13 | end 14 | -------------------------------------------------------------------------------- /GemspecYML.md: -------------------------------------------------------------------------------- 1 | # gemspec.yml 2 | 3 | Ore uses the `gemspec.yml` file to store all static data about a project. 4 | The `gemspec.yml` is a simple YAML file, which contains the same data 5 | that a normal Ruby `.gemspec` file would. Below is the complete listing 6 | of valid data that can be listed in a `gemspec.yml` file. 7 | 8 | ## name 9 | 10 | The name of the project can be listed like so: 11 | 12 | name: foo 13 | 14 | The name of the project must be specified. 15 | 16 | ## version 17 | 18 | The version of the project can be listed like so: 19 | 20 | version: 1.2.3 21 | 22 | If the version is not listed, Ore will first search for a `VERSION` 23 | file in the root of the project. If Ore cannot find any version files, 24 | it will then search within the `lib/` directory for a `version.rb`. 25 | 26 | ## summary 27 | 28 | The summary of the project can be listed like so: 29 | 30 | summary: My awesome project 31 | 32 | ## description 33 | 34 | The description of the project can be listed in a variety of ways: 35 | 36 | * Single line: 37 | 38 | description: My project, which provides various functionality. 39 | 40 | * Text block: 41 | 42 | description: 43 | My project, which provides the developer with various attributes 44 | and behaviors. 45 | 46 | If the description is not listed, it will default to the `summary`. 47 | 48 | ## license 49 | 50 | The license of the project can be listed like so: 51 | 52 | license: MIT 53 | 54 | Multiple licenses can also be listed: 55 | 56 | license: 57 | - LGPL-2.1 58 | - GPL-2 59 | 60 | ## authors 61 | 62 | The authors of the project can be listed like so: 63 | 64 | authors: Alice 65 | 66 | If a project has more than one author, each author can be listed: 67 | 68 | authors: 69 | - Alice 70 | - Eve 71 | - Bob 72 | 73 | ## email 74 | 75 | The primary email contact for the project can be listed like so: 76 | 77 | email: alice@example.com 78 | 79 | If a project has more than one email contact, each email address can be 80 | listed: 81 | 82 | email: 83 | - alice@example.com 84 | - eve@example.com 85 | - bob@example.com 86 | 87 | ## require_paths 88 | 89 | The require_paths of a project can be listed like so: 90 | 91 | require_paths: lib 92 | 93 | If there are more than one require_path that needs listing: 94 | 95 | require_paths: 96 | - ext 97 | - lib 98 | 99 | ## executables 100 | 101 | The names of the executables provided by the project can be listed like so: 102 | 103 | executables: bin/* 104 | 105 | One can also list the executables individually: 106 | 107 | executables: 108 | - util1 109 | - util2 110 | 111 | If the `executables` are not listed, Ore will use the names of any 112 | executable file within the `bin/` directory. 113 | 114 | ## extensions 115 | 116 | Any Ruby C-extensions can be listed like so: 117 | 118 | extensions: ext/foo/extconf.rb 119 | 120 | ## documentation 121 | 122 | The format of the documentation can be listed like so: 123 | 124 | documentation: yard 125 | 126 | ## extra_doc_files 127 | 128 | The extra files that should also be scanned for documentation can be listed 129 | like so: 130 | 131 | extra_doc_files: 132 | - ChangeLog.md 133 | - LICENSE.txt 134 | 135 | If `extra_doc_files` is not listed, Ore will use the extra-files listed in 136 | the `.document` file. 137 | 138 | ## files 139 | 140 | The files of the project can be listed like so: 141 | 142 | files: lib/**/*.rb 143 | 144 | More than one file pattern can be specification: 145 | 146 | files: 147 | - lib/**/*.rb 148 | - spec/**/* 149 | - data/**/* 150 | 151 | If `files` is not listed, Ore will check if the project is using 152 | [Git](http://www.git-scm.org/), can will find all tracked files using: 153 | 154 | git ls-files -z 155 | 156 | If the project is not using Git, Ore will default `files` to every file in 157 | the project. 158 | 159 | ## test_files 160 | 161 | The files used to test the project can be listed like so: 162 | 163 | test_files: spec/**/*_spec.rb 164 | 165 | More than one test-file pattern can be supplied: 166 | 167 | test_files: 168 | - spec/**/*_spec.rb 169 | - features/**/* 170 | 171 | If `test_files` is not listed, Ore will default `files` to 172 | `test/{**/}test_*.rb` and `spec/{**/}*_spec.rb`. 173 | 174 | ## post_install_message 175 | 176 | The post-installation message for a project can be listed like so: 177 | 178 | post_install_message: | 179 | 180 | Thank you for installing MyProject 0.1.0. To start MyProject, simply 181 | run the following command: 182 | 183 | $ my_project 184 | 185 | 186 | ## requirements 187 | 188 | The external requirements of the project can be listed like so: 189 | 190 | requirements: libcairo >= 1.8 191 | 192 | Multiple external requirements can also be listed: 193 | 194 | requirements: 195 | - libcairo >= 1.8.0 196 | - libclutter >= 1.2.0 197 | 198 | ## required_ruby_version 199 | 200 | The version of Ruby required by the project can be listed like so: 201 | 202 | required_ruby_version: >= 1.9.1 203 | 204 | ## required_rubygems_version 205 | 206 | The version of RubyGems required by the project can be listed like so: 207 | 208 | required_rubygems_version: >= 1.3.7 209 | 210 | If `required_rubygems_version` is not listed and the project uses 211 | [Bundler](http://gembundler.com/), Ore will default `required_rubygems_version` 212 | to `>= 1.3.6`. 213 | 214 | ## dependencies 215 | 216 | The dependencies of the project can be listed like so: 217 | 218 | dependencies: 219 | foo: ~> 0.1.0 220 | bar: 1.2.3 221 | 222 | More than one version can be specified for each dependency: 223 | 224 | dependencies: 225 | foo: ~> 0.1.0, >= 0.0.7 226 | bar: 227 | - 1.2.3 228 | - 1.3.1 229 | 230 | ## development_dependencies 231 | 232 | The purely developmental-dependencies for a project can be specified 233 | like so: 234 | 235 | development_dependencies: 236 | foo: ~> 0.1.0 237 | bar: 1.2.3 238 | 239 | More than one version can be specified for each dependency: 240 | 241 | development_dependencies: 242 | foo: ~> 0.1.0, >= 0.0.7 243 | bar: 244 | - 1.2.3 245 | - 1.3.1 246 | 247 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2015 Hal Brodigan 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 NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ore 2 | 3 | * [Source](https://github.com/ruby-ore/ore) 4 | * [Issues](https://github.com/ruby-ore/ore/issues) 5 | * [Documentation](http://rubydoc.info/gems/ore/frames) 6 | * [Email](mailto:postmodern.mod3 at gmail.com) 7 | 8 | ## Description 9 | 10 | Ore is a fully configurable and customisable Ruby gem generator. With Ore, you 11 | spend less time editing files and more time writing code. 12 | 13 | ## Features 14 | 15 | ### SCMs 16 | 17 | Ore supports generating [Git][git] (default), [Mercurial][hg] and using 18 | [SubVersion][svn] repositories: 19 | 20 | $ mine my-project [--git | --hg] 21 | 22 | ### Licenses 23 | 24 | Ore supports generating MIT (default), BSD, Apache 2.0, GPLv3 or LGPLv3 25 | licenses: 26 | 27 | $ mine my-project [--mit | --bsd | --apache | --gpl | --lgpl] 28 | 29 | ### Testing 30 | 31 | Ore supports generating [RSpec][rspec] (default), [Minitest][minitest] or 32 | [Test::Unit][test_unit] tests: 33 | 34 | $ mine my-project [--test-unit | --minitest | --rspec] 35 | 36 | ### TravisCI 37 | 38 | Ore also supports generating a [`.travis.yml`][travis.yml] file and README 39 | badge: 40 | 41 | $ mine my-project --travis 42 | 43 | ### Code Climate 44 | 45 | Ore also supports adds Code Climate GPA badges: 46 | 47 | $ mine my-project --code-climate 48 | 49 | ### Documentation 50 | 51 | Ore supports generating projects with [RDoc][rdoc] (default) or [YARD][yard] 52 | documentation: 53 | 54 | $ mine my-project [--rdoc | --yard] 55 | 56 | Ore also supports [Markdown][markdown] (default), [Textile][textile] and 57 | [RDoc][rdoc] markups: 58 | 59 | $ mine my-project --yard [--rdoc | --markdown | --textile] 60 | 61 | ### Bundler 62 | 63 | Ore supports [Bundler][bundler] by default. If you do not need bundler, you may 64 | disable it: 65 | 66 | $ mine my-project --no-bundler 67 | 68 | ### Gem Tasks 69 | 70 | Ore supports generating `Rakefile`s using [rubygems/tasks][rubygems_tasks] 71 | (default), [bundler/gem_tasks][bundler] or even 72 | [Gem::PackageTask][gem_package_task]: 73 | 74 | $ mine my-project [--rubygems-tasks | --bundler-tasks | --gem-package-task] 75 | 76 | ### Gemspecs 77 | 78 | Ore generates a minimal pure-Ruby gemspec by default: 79 | 80 | $ mine my-project 81 | 82 | Ore also supports generating a [gemspec.yml] file: 83 | 84 | $ mine my-project --gemspec-yml 85 | 86 | Gemspec files support listing files from Git, Hg and SubVersion. If the project 87 | uses Git submodules, the gemspecs will automatically include files from the 88 | submodules. 89 | 90 | ### Custom Templates 91 | 92 | Additional templates can also be installed from Git: 93 | 94 | $ ore install git://github.com/ruby-ore/rbenv.git 95 | $ mine my-project --rbenv 96 | 97 | ## Requirements 98 | 99 | * [ruby] >= 1.9.1 100 | * [thor] ~> 0.15 101 | 102 | ## Install 103 | 104 | $ gem install ore 105 | 106 | ## Synopsis 107 | 108 | Generate a new project: 109 | 110 | $ mine my_project 111 | 112 | Generate a new customized project: 113 | 114 | $ mine my_project --bundler --rspec --yard 115 | 116 | Generate a new project using previously installed templates: 117 | 118 | $ mine my_project --bundler --rspec --yard --templates rbenv 119 | 120 | Set your github username, so `mine` can generate GitHub project URLs: 121 | 122 | $ git config github.user foobar 123 | $ mine my_project 124 | 125 | Install a custom template: 126 | 127 | $ ore install git://github.com/ruby-ore/rbenv.git 128 | 129 | List installed templates: 130 | 131 | $ ore list 132 | 133 | Remove a previously installed template: 134 | 135 | $ ore remove rbenv 136 | 137 | Add default generator options to `~/.ore/options.yml`: 138 | 139 | gemspec_yml: true 140 | rubygems_tasks: true 141 | rspec: true 142 | yard: true 143 | markdown: true 144 | authors: 145 | - Alice 146 | email: alice@example.com 147 | 148 | ## License 149 | 150 | Copyright (c) 2010-2015 Hal Brodigan 151 | 152 | See {file:LICENSE.txt} for license information. 153 | 154 | [git]: http://git-scm.com/ 155 | [hg]: http://mercurial.selenic.com/ 156 | [svn]: http://subversion.tigris.org/ 157 | [gemspec.yml]: https://github.com/ruby-ore/ore/blob/master/gemspec.yml 158 | [rubygems_tasks]: https://github.com/postmodern/rubygems-tasks#readme 159 | [bundler]: http://gembundler.com/ 160 | [gem_package_task]: http://rubygems.rubyforge.org/rubygems-update/Gem/PackageTask.html 161 | [rdoc]: http://rdoc.rubyforge.org/ 162 | [markdown]: http://daringfireball.net/projects/markdown/ 163 | [textile]: http://textile.sitemonks.com/ 164 | [yard]: http://yardoc.org/ 165 | [rspec]: http://rspec.info/ 166 | [test_unit]: http://test-unit.rubyforge.org/ 167 | [minitest]: https://github.com/seattlerb/minitest#readme 168 | [travis.yml]: http://docs.travis-ci.com/user/languages/ruby/ 169 | 170 | [ruby]: https://www.ruby-lang.org/ 171 | [thor]: https://github.com/wycats/thor#readme 172 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | 3 | begin 4 | require 'bundler/setup' 5 | rescue LoadError => e 6 | abort e.message 7 | end 8 | 9 | require 'rake' 10 | 11 | require 'rubygems/tasks' 12 | Gem::Tasks.new 13 | 14 | require 'rspec/core/rake_task' 15 | RSpec::Core::RakeTask.new 16 | 17 | task :test => :spec 18 | task :default => :spec 19 | 20 | require 'yard' 21 | YARD::Rake::YardocTask.new 22 | 23 | namespace :update do 24 | Dir['data/ore/templates/*'].each do |template| 25 | name = File.basename(template) 26 | 27 | if File.exist?(File.join(template,'.git')) 28 | desc "Updates the #{name} template" 29 | task name do 30 | Dir.chdir(template) { sh 'git pull' } 31 | sh 'git', 'commit', template 32 | end 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /bin/mine: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'rubygems' 4 | 5 | begin 6 | require 'ore/generator' 7 | rescue LoadError => e 8 | abort 'Could not load "ore/generator"' 9 | end 10 | 11 | Ore::Generator.start 12 | -------------------------------------------------------------------------------- /bin/ore: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'rubygems' 4 | 5 | begin 6 | require 'ore/cli' 7 | rescue LoadError => e 8 | abort 'Could not load "ore/cli"' 9 | end 10 | 11 | Ore::CLI.start 12 | -------------------------------------------------------------------------------- /data/ore/abbreviations.txt: -------------------------------------------------------------------------------- 1 | ASM 2 | ARM 3 | BGP 4 | BSD 5 | CPP 6 | CSS 7 | CSV 8 | DKIM 9 | DHCP 10 | DMARC 11 | DNS 12 | FTP 13 | HTML 14 | HTTP 15 | HTTPS 16 | I18N 17 | IMAP 18 | IGMP 19 | IP 20 | IPv4 21 | IPv6 22 | JSON 23 | MIME 24 | MIPS 25 | POP3 26 | POSIX 27 | RPC 28 | RFID 29 | SMIME 30 | SMTP 31 | SNMP 32 | SPF 33 | SSH 34 | SSL 35 | TCP 36 | TLS 37 | UDP 38 | UNIX 39 | UPnP 40 | URI 41 | URL 42 | WWW 43 | X86 44 | XHTML 45 | XML 46 | XSL 47 | YAML 48 | -------------------------------------------------------------------------------- /data/ore/common_namespaces.yml: -------------------------------------------------------------------------------- 1 | --- 2 | activerecord: ActiveRecord 3 | ar: ActiveRecord 4 | dm: DataMapper 5 | em: EM 6 | ffi: FFI 7 | github: GitHub 8 | js: JavaScript 9 | msgpack: MsgPack 10 | rdoc: RDoc 11 | rspec: RSpec 12 | rubygems: Gem 13 | yard: YARD 14 | -------------------------------------------------------------------------------- /data/ore/templates/bin/bin/[name].erb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | <%- if (bundler? && (git? || hg? || svn?)) -%> 4 | root = File.expand_path(File.join(File.dirname(__FILE__),'..')) 5 | if File.directory?(File.join(root,'.<%= @scm %>')) 6 | Dir.chdir(root) do 7 | begin 8 | require 'bundler/setup' 9 | rescue LoadError => e 10 | warn e.message 11 | warn "Run `gem install bundler` to install Bundler" 12 | exit -1 13 | end 14 | end 15 | end 16 | <%- end -%> 17 | 18 | require '<%= @namespace_path %>' 19 | -------------------------------------------------------------------------------- /data/ore/templates/gem/ChangeLog.md.erb: -------------------------------------------------------------------------------- 1 | ### <%= @version %> / <%= @date %> 2 | 3 | * Initial release: 4 | 5 | -------------------------------------------------------------------------------- /data/ore/templates/gem/ChangeLog.rdoc.erb: -------------------------------------------------------------------------------- 1 | === <%= @version %> / <%= @date %> 2 | 3 | * Initial release: 4 | 5 | -------------------------------------------------------------------------------- /data/ore/templates/gem/ChangeLog.tt.erb: -------------------------------------------------------------------------------- 1 | h3. <%= @version %> / <%= @date %> 2 | 3 | * Initial release: 4 | 5 | -------------------------------------------------------------------------------- /data/ore/templates/gem/README.md.erb: -------------------------------------------------------------------------------- 1 | # <%= @name %> 2 | 3 | <%- if @homepage -%> 4 | * [Homepage](<%= @homepage %>) 5 | <%- end -%> 6 | <%- if @bug_tracker -%> 7 | * [Issues](<%= @bug_tracker %>) 8 | <%- end -%> 9 | * [Documentation](http://rubydoc.info/gems/<%= @name %>/frames) 10 | <%- if @safe_email -%> 11 | * [Email](mailto:<%= @safe_email %>) 12 | <%- end -%> 13 | <%- includes(:badges,'') do |badges| -%> 14 | 15 | <%= badges -%> 16 | <%- end -%> 17 | 18 | ## Description 19 | 20 | <%= @description %> 21 | 22 | ## Features 23 | 24 | ## Examples 25 | 26 | require '<%= @namespace_path -%>' 27 | 28 | ## Requirements 29 | 30 | ## Install 31 | 32 | $ gem install <%= @name %> 33 | 34 | <%- if bin? -%> 35 | ## Synopsis 36 | 37 | $ <%= @name %> 38 | 39 | <%- end -%> 40 | ## Copyright 41 | 42 | <%- if @author -%> 43 | Copyright (c) <%= @year %> <%= @author %> 44 | <%- else -%> 45 | Copyright (c) <%= @year %> 46 | <%- end -%> 47 | <%- if @license_file -%> 48 | 49 | <%- if yard? -%> 50 | See {file:<%= @license_file %>} for details. 51 | <%- else -%> 52 | See <%= @license_file %> for details. 53 | <%- end -%> 54 | <%- end -%> 55 | -------------------------------------------------------------------------------- /data/ore/templates/gem/README.rdoc.erb: -------------------------------------------------------------------------------- 1 | = <%= @name %> 2 | 3 | <%- if @homepage -%> 4 | * {Homepage}[<%= @homepage %>] 5 | <%- end -%> 6 | <%- if @bug_tracker -%> 7 | * {Issues}[<%= @bug_tracker %>] 8 | <%- end -%> 9 | * {Documentation}[http://rubydoc.info/gems/<%= @name %>/frames] 10 | <%- if @safe_email -%> 11 | * {Email}[mailto:<%= @safe_email.gsub(' ','%20') %>] 12 | <%- end -%> 13 | <%- includes(:badges,'') do |badges| -%> 14 | 15 | <%= badges -%> 16 | <%- end -%> 17 | 18 | == Description 19 | 20 | <%= @description %> 21 | 22 | == Features 23 | 24 | == Examples 25 | 26 | require '<%= @namespace_path -%>' 27 | 28 | == Requirements 29 | 30 | == Install 31 | 32 | $ gem install <%= @name %> 33 | 34 | <%- if bin? -%> 35 | == Synopsis 36 | 37 | $ <%= @name %> 38 | 39 | <%- end -%> 40 | == Copyright 41 | 42 | <%- if @author -%> 43 | Copyright (c) <%= @year %> <%= @author %> 44 | <%- else -%> 45 | Copyright (c) <%= @year %> 46 | <%- end -%> 47 | <%- if @license_file -%> 48 | 49 | <%- if yard? -%> 50 | See {file:<%= @license_file %>} for details. 51 | <%- else -%> 52 | See <%= @license_file %> for details. 53 | <%- end -%> 54 | <%- end -%> 55 | -------------------------------------------------------------------------------- /data/ore/templates/gem/README.tt.erb: -------------------------------------------------------------------------------- 1 | h1. <%= @name %> 2 | 3 | <%- if @homepage -%> 4 | * "Homepage":<%= @homepage %> 5 | <%- end -%> 6 | <%- if @bug_tracker -%> 7 | * "Issues":<%= @bug_tracker %> 8 | <%- end -%> 9 | * "Documentation":http://rubydoc.info/gems/<%= @name %>/frames 10 | <%- if @safe_email -%> 11 | * "Email":mailto:<%= @safe_email %> 12 | <%- end -%> 13 | <%- includes(:badges,'') do |badges| -%> 14 | 15 | <%= badges -%> 16 | <%- end -%> 17 | 18 | h2. Description 19 | 20 | <%= @description %> 21 | 22 | h2. Features 23 | 24 | h2. Examples 25 | 26 | bc. 27 | require '<%= @namespace_path -%>' 28 | 29 | h2. Requirements 30 | 31 | h2. Install 32 | 33 | bc. 34 | $ gem install <%= @name %> 35 | 36 | <%- if bin? -%> 37 | h2. Synopsis 38 | 39 | bc. 40 | $ <%= @name %> 41 | 42 | <%- end -%> 43 | h2. Copyright 44 | 45 | <%- if @author -%> 46 | Copyright (c) <%= @year %> <%= @author %> 47 | <%- else -%> 48 | Copyright (c) <%= @year %> 49 | <%- end -%> 50 | <%- if @license_file -%> 51 | 52 | <%- if yard? -%> 53 | See {file:<%= @license_file %>} for details. 54 | <%- else -%> 55 | See <%= @license_file %> for details. 56 | <%- end -%> 57 | <%- end -%> 58 | -------------------------------------------------------------------------------- /data/ore/templates/gem/Rakefile.erb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | require 'rubygems' 4 | <%- if bundler? -%> 5 | 6 | begin 7 | require 'bundler/setup' 8 | rescue LoadError => e 9 | abort e.message 10 | end 11 | 12 | <%- end -%> 13 | require 'rake' 14 | 15 | <%= includes :tasks -%> 16 | -------------------------------------------------------------------------------- /data/ore/templates/gem/[name].gemspec.erb: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | 3 | lib = File.expand_path('../lib', __FILE__) 4 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 5 | require '<%= @namespace_path %>/version' 6 | 7 | Gem::Specification.new do |gem| 8 | gem.name = <%= @name.inspect %> 9 | gem.version = <%= @namespace %>::VERSION 10 | gem.summary = %q{<%= @summary %>} 11 | gem.description = %q{<%= @description %>} 12 | gem.license = <%= @license.inspect %> 13 | gem.authors = <%= @authors.inspect %> 14 | <%- if @email -%> 15 | gem.email = <%= @email.inspect %> 16 | <%- end -%> 17 | gem.homepage = <%= @homepage.inspect %> 18 | 19 | <%- if git? -%> 20 | gem.files = `git ls-files`.split($/) 21 | 22 | `git submodule --quiet foreach --recursive pwd`.split($/).each do |submodule| 23 | submodule.sub!("#{Dir.pwd}/",'') 24 | 25 | Dir.chdir(submodule) do 26 | `git ls-files`.split($/).map do |subpath| 27 | gem.files << File.join(submodule,subpath) 28 | end 29 | end 30 | end 31 | <%- elsif hg? -%> 32 | gem.files = `hg manifest`.split($/) 33 | <%- elsif svn? -%> 34 | gem.files = `svn ls -R`.split($/).select { |path| File.file?(path) } 35 | <%- else -%> 36 | gem.files = Dir['{**/}{.*,*}'].select { |path| File.file?(path) } 37 | <%- end -%> 38 | gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } 39 | gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) 40 | gem.require_paths = ['lib'] 41 | <%- unless @dependencies.empty? -%> 42 | 43 | <%- @dependencies.sort.each do |name,version| -%> 44 | <%- if (version && !version.empty?) -%> 45 | gem.add_dependency '<%= name %>', '<%= version %>' 46 | <%- else -%> 47 | gem.add_dependency '<%= name %>' 48 | <%- end -%> 49 | <%- end -%> 50 | <%- end -%> 51 | 52 | <%- unless @development_dependencies.empty? -%> 53 | <%- @development_dependencies.sort.each do |name,version| -%> 54 | <%- if (version && !version.empty?) -%> 55 | gem.add_development_dependency '<%= name%>', '<%= version %>' 56 | <%- else -%> 57 | gem.add_development_dependency '<%= name%>' 58 | <%- end -%> 59 | <%- end -%> 60 | <%- end -%>end 61 | -------------------------------------------------------------------------------- /data/ore/templates/gem/lib/[namespace_path].rb.erb: -------------------------------------------------------------------------------- 1 | require '<%= @namespace_path %>/version' 2 | -------------------------------------------------------------------------------- /data/ore/templates/gem/lib/[namespace_path]/version.rb.erb: -------------------------------------------------------------------------------- 1 | <%- includes(:copyright,'') do |copyright| -%> 2 | <%= copyright -%> 3 | 4 | <%- end -%> 5 | <%- @modules.each_with_index do |namespace,n| -%> 6 | <%= indent(n) %>module <%= namespace %> 7 | <%- end -%> 8 | <%= indent(@module_depth) %># <%= @name %> version 9 | <%= indent(@module_depth) %>VERSION = <%= @version.dump %> 10 | <%- (@module_depth - 1).downto(0) do |n| -%> 11 | <%= indent(n) %>end 12 | <%- end -%> 13 | -------------------------------------------------------------------------------- /data/ore/templates/gem/template.yml: -------------------------------------------------------------------------------- 1 | enable: 2 | - mit 3 | 4 | ignore: 5 | - /pkg/ 6 | -------------------------------------------------------------------------------- /gemspec.yml: -------------------------------------------------------------------------------- 1 | name: ore 2 | summary: Generate perfect Ruby gems 3 | description: 4 | Ore is a fully configurable and extendable Ruby gem generator. With Ore you 5 | spend less time editing files, and more time writing code. 6 | 7 | license: MIT 8 | authors: Postmodern 9 | email: postmodern.mod3@gmail.com 10 | homepage: https://github.com/ruby-ore/ore#readme 11 | post_install_message: | 12 | ************************************************************************** 13 | Generate a new Ruby library: 14 | 15 | $ mine my_library --rspec --yard 16 | 17 | Build the library: 18 | 19 | $ rake build 20 | 21 | Release the library to rubygems.org: 22 | 23 | $ rake release 24 | 25 | ************************************************************************** 26 | 27 | required_ruby_version: ">= 1.9.1" 28 | 29 | dependencies: 30 | thor: ~> 0.15 31 | 32 | development_dependencies: 33 | bundler: ~> 1.0 34 | -------------------------------------------------------------------------------- /lib/ore.rb: -------------------------------------------------------------------------------- 1 | require 'ore/config' 2 | require 'ore/generator' 3 | require 'ore/cli' 4 | -------------------------------------------------------------------------------- /lib/ore/actions.rb: -------------------------------------------------------------------------------- 1 | module Ore 2 | # 3 | # Additional actions for the {Generator}. 4 | # 5 | # @api semipublic 6 | # 7 | # @since 0.9.0 8 | # 9 | module Actions 10 | protected 11 | 12 | # 13 | # Runs a command. 14 | # 15 | # @param [String] command 16 | # The command to execute. 17 | # 18 | # @param [Hash] config 19 | # Additional options. 20 | # 21 | # @see http://rubydoc.info/gems/thor/Thor/Actions#run-instance_method 22 | # 23 | def run(command,config={}) 24 | super(command,config.merge(capture: true)) 25 | end 26 | 27 | # 28 | # Generates an empty directory. 29 | # 30 | # @param [String] dest 31 | # The uninterpolated destination path. 32 | # 33 | # @return [String] 34 | # The destination path of the directory. 35 | # 36 | # @since 0.7.1 37 | # 38 | def generate_dir(dest) 39 | return if @generated_dirs.has_key?(dest) 40 | 41 | path = interpolate(dest) 42 | empty_directory path 43 | 44 | @generated_dirs[dest] = path 45 | return path 46 | end 47 | 48 | # 49 | # Generates a file. 50 | # 51 | # @param [String] dest 52 | # The uninterpolated destination path. 53 | # 54 | # @param [String] file 55 | # The source file or template. 56 | # 57 | # @param [Hash] options 58 | # Additional options. 59 | # 60 | # @option options [Boolean] :template 61 | # Specifies that the file is a template, and should be rendered. 62 | # 63 | # @return [String] 64 | # The destination path of the file. 65 | # 66 | # @since 0.7.1 67 | # 68 | def generate_file(dest,file,options={}) 69 | return if @generated_files.has_key?(dest) 70 | 71 | path = interpolate(dest) 72 | 73 | if options[:template] 74 | @current_template_dir = File.dirname(dest) 75 | template file, path 76 | @current_template_dir = nil 77 | else 78 | copy_file file, path 79 | end 80 | 81 | @generated_files[dest] = path 82 | return path 83 | end 84 | end 85 | end 86 | -------------------------------------------------------------------------------- /lib/ore/cli.rb: -------------------------------------------------------------------------------- 1 | require 'ore/config' 2 | require 'ore/generator' 3 | require 'ore/version' 4 | 5 | require 'thor' 6 | require 'fileutils' 7 | require 'uri' 8 | 9 | module Ore 10 | class CLI < Thor 11 | 12 | map '-l' => :list 13 | map '-u' => :update 14 | map '-r' => :remove 15 | 16 | # add a --version option 17 | map '--version' => :version 18 | 19 | desc 'list', 'List installed Ore templates' 20 | 21 | # 22 | # Lists builtin and installed templates. 23 | # 24 | def list 25 | print_template = lambda { |path| 26 | puts " #{File.basename(path)}" 27 | } 28 | 29 | say "Builtin templates:", :green 30 | Config.builtin_templates(&print_template) 31 | 32 | say "Installed templates:", :green 33 | Config.installed_templates(&print_template) 34 | end 35 | 36 | desc 'install URI', 'Installs an Ore template' 37 | 38 | # 39 | # Installs a template into `~/.ore/templates`. 40 | # 41 | # @param [String] uri 42 | # The Git URI to install the template from. 43 | # 44 | def install(uri) 45 | url = URI(uri) 46 | 47 | name = File.basename(url.path) 48 | name.gsub!(/\.git$/,'') 49 | 50 | path = File.join(Config::TEMPLATES_DIR,name) 51 | 52 | if File.directory?(path) 53 | say "Template #{name} already installed.", :red 54 | exit -1 55 | end 56 | 57 | FileUtils.mkdir_p(path) 58 | system('git','clone',uri,path) 59 | end 60 | 61 | desc 'update', 'Updates all installed templates' 62 | 63 | # 64 | # Updates all previously installed templates. 65 | # 66 | def update 67 | Config.installed_templates do |path| 68 | say "Updating #{File.basename(path)} ...", :green 69 | 70 | Dir.chdir(path) { system('git','pull','-q') } 71 | end 72 | end 73 | 74 | desc 'remove NAME', 'Removes an Ore template' 75 | 76 | # 77 | # Removes a previously installed template. 78 | # 79 | # @param [String] name 80 | # The name of the template to remove. 81 | # 82 | def remove(name) 83 | name = File.basename(name) 84 | path = File.join(Config::TEMPLATES_DIR,name) 85 | 86 | unless File.exists?(path) 87 | say "Unknown template: #{name}", :red 88 | exit -1 89 | end 90 | 91 | FileUtils.rm_rf(path) 92 | end 93 | 94 | desc 'version', 'Prints the version' 95 | 96 | # 97 | # Prints {Ore::VERSION}. 98 | # 99 | def version 100 | puts "ore #{Ore::VERSION}" 101 | end 102 | 103 | end 104 | end 105 | -------------------------------------------------------------------------------- /lib/ore/config.rb: -------------------------------------------------------------------------------- 1 | require 'ore/options' 2 | 3 | module Ore 4 | module Config 5 | # The users home directory 6 | HOME = Gem.user_home 7 | 8 | # Ore config directory 9 | PATH = File.join(HOME,'.ore') 10 | 11 | # Default options file. 12 | OPTIONS_FILE = File.join(PATH,'options.yml') 13 | 14 | # Custom Ore Templates directory 15 | TEMPLATES_DIR = File.join(PATH,'templates') 16 | 17 | # The `data/ore` directory for Ore 18 | DATA_DIR = File.expand_path(File.join('..','..','data','ore'),File.dirname(__FILE__)) 19 | 20 | # The `data/ore/templates` directory for Ore 21 | BUILTIN_TEMPLATES_DIR = File.join(DATA_DIR,'templates') 22 | 23 | @enabled = true 24 | 25 | # 26 | # Enables access to user config. 27 | # 28 | # @api private 29 | # 30 | # @since 0.5.0 31 | # 32 | def self.enable! 33 | @enabled = true 34 | end 35 | 36 | # 37 | # Disables access to user config. 38 | # 39 | # @api private 40 | # 41 | # @since 0.5.0 42 | # 43 | def self.disable! 44 | @enabled = false 45 | end 46 | 47 | # 48 | # Loads the default options from `~/.ore/options.yml`. 49 | # 50 | # @return [Options] 51 | # The loaded default options. 52 | # 53 | # @raise [RuntimeError] 54 | # The `~/.ore/options.yml` did not contain a YAML encoded Hash. 55 | # 56 | # @since 0.9.0 57 | # 58 | def self.options 59 | @options ||= if @enabled && File.file?(OPTIONS_FILE) 60 | Options.load(OPTIONS_FILE) 61 | else 62 | Options.new 63 | end 64 | end 65 | 66 | # 67 | # The builtin templates. 68 | # 69 | # @yield [path] 70 | # The given block will be passed every builtin template. 71 | # 72 | # @yieldparam [String] path 73 | # The path of a Ore template directory. 74 | # 75 | def self.builtin_templates 76 | if File.directory?(BUILTIN_TEMPLATES_DIR) 77 | Dir.glob("#{BUILTIN_TEMPLATES_DIR}/*") do |template| 78 | yield template if File.directory?(template) 79 | end 80 | end 81 | end 82 | 83 | # 84 | # The installed templates. 85 | # 86 | # @yield [path] 87 | # The given block will be passed every installed template. 88 | # 89 | # @yieldparam [String] path 90 | # The path of a Ore template directory. 91 | # 92 | def self.installed_templates 93 | return unless @enabled 94 | 95 | if File.directory?(TEMPLATES_DIR) 96 | Dir.glob("#{TEMPLATES_DIR}/*") do |template| 97 | yield template if File.directory?(template) 98 | end 99 | end 100 | end 101 | end 102 | end 103 | -------------------------------------------------------------------------------- /lib/ore/generator.rb: -------------------------------------------------------------------------------- 1 | require 'ore/config' 2 | require 'ore/actions' 3 | require 'ore/naming' 4 | require 'ore/template' 5 | 6 | require 'thor/group' 7 | require 'date' 8 | require 'set' 9 | require 'uri' 10 | 11 | module Ore 12 | class Generator < Thor::Group 13 | 14 | include Thor::Actions 15 | include Actions 16 | include Naming 17 | include Template::Interpolations 18 | include Template::Helpers 19 | 20 | # 21 | # Defines a generator option. 22 | # 23 | # @param [Symbol] name 24 | # 25 | # @param [Hash] options 26 | # 27 | def self.generator_option(name,options={}) 28 | default = options.fetch(:default,Config.options[name]) 29 | 30 | class_option(name,options.merge(default: default)) 31 | end 32 | 33 | Template.templates.each_key do |name| 34 | # skip the `base` template 35 | next if name == :gem 36 | 37 | generator_option name, type: :boolean, group: :template 38 | end 39 | 40 | # disable the Thor namespace 41 | namespace '' 42 | 43 | # define the options 44 | generator_option :markup, type: :string, 45 | banner: 'markdown|textile|rdoc' 46 | generator_option :markdown, type: :boolean 47 | generator_option :textile, type: :boolean 48 | generator_option :templates, type: :array, 49 | default: [], 50 | aliases: '-T', 51 | banner: 'TEMPLATE [...]' 52 | generator_option :name, type: :string, aliases: '-n' 53 | generator_option :namespace, type: :string, aliases: '-N' 54 | generator_option :version, type: :string, 55 | aliases: '-V' 56 | generator_option :summary, type: :string, 57 | aliases: '-s' 58 | generator_option :description, type: :string, 59 | aliases: '-D' 60 | generator_option :author, type: :string, 61 | aliases: '-A', 62 | banner: 'NAME' 63 | generator_option :authors, type: :array, 64 | aliases: '-a', 65 | banner: 'NAME [...]' 66 | generator_option :email, type: :string, aliases: '-e' 67 | generator_option :homepage, type: :string, aliases: %w[-U --website] 68 | generator_option :bug_tracker, type: :string, aliases: '-B' 69 | 70 | argument :path, required: true 71 | 72 | # The enabled templates. 73 | attr_reader :enabled_templates 74 | 75 | # The disabled templates. 76 | attr_reader :disabled_templates 77 | 78 | # The loaded templates. 79 | attr_reader :templates 80 | 81 | # The generated directories. 82 | attr_reader :generated_dirs 83 | 84 | # The generated files. 85 | attr_reader :generated_files 86 | 87 | # 88 | # Generates a new project. 89 | # 90 | def generate 91 | self.destination_root = path 92 | 93 | enable_templates! 94 | initialize_variables! 95 | 96 | extend Template::Helpers::MARKUP.fetch(@markup) 97 | 98 | unless options.quiet? 99 | say "Generating #{self.destination_root}", :green 100 | end 101 | 102 | generate_directories! 103 | generate_files! 104 | initialize_scm! 105 | end 106 | 107 | protected 108 | 109 | # 110 | # Enables a template, adding it to the generator. 111 | # 112 | # @param [Symbol, String] name 113 | # The name of the template to add. 114 | # 115 | # @since 0.4.0 116 | # 117 | def enable_template(name) 118 | name = name.to_sym 119 | 120 | return false if @enabled_templates.include?(name) 121 | 122 | unless (template_dir = Template.templates[name]) 123 | say "Unknown template #{name}", :red 124 | exit -1 125 | end 126 | 127 | new_template = Template::Directory.new(template_dir) 128 | 129 | # mark the template as enabled 130 | @enabled_templates << name 131 | 132 | # enable any other templates 133 | new_template.enable.each do |sub_template| 134 | enable_template(sub_template) 135 | end 136 | 137 | # append the new template to the end of the list, 138 | # to override previously loaded templates 139 | @templates << new_template 140 | 141 | # add the template directory to the source-paths 142 | self.source_paths << new_template.path 143 | return true 144 | end 145 | 146 | # 147 | # Disables a template in the generator. 148 | # 149 | # @param [Symbol, String] name 150 | # The name of the template. 151 | # 152 | # @since 0.4.0 153 | # 154 | def disable_template(name) 155 | name = name.to_sym 156 | 157 | return false if @disabled_templates.include?(name) 158 | 159 | if (template_dir = Template.templates[name]) 160 | source_paths.delete(template_dir) 161 | 162 | @templates.delete_if { |template| template.path == template_dir } 163 | @enabled_templates.delete(name) 164 | end 165 | 166 | @disabled_templates << name 167 | return true 168 | end 169 | 170 | # 171 | # Enables templates. 172 | # 173 | def enable_templates! 174 | @templates = [] 175 | @enabled_templates = Set[] 176 | @disabled_templates = Set[] 177 | 178 | enable_template :gem 179 | 180 | # enable the default templates first 181 | Options::DEFAULT_TEMPLATES.each do |name| 182 | if (Template.template?(name) && options[name]) 183 | enable_template(name) 184 | end 185 | end 186 | 187 | # enable the templates specified by option 188 | options.each do |name,value| 189 | if (Template.template?(name) && value) 190 | enable_template(name) 191 | end 192 | end 193 | 194 | # enable any additionally specified templates 195 | options.templates.each { |name| enable_template(name) } 196 | 197 | # disable any previously enabled templates 198 | @templates.reverse_each do |template| 199 | template.disable.each { |name| disable_template(name) } 200 | end 201 | end 202 | 203 | # 204 | # Initializes variables for the templates. 205 | # 206 | def initialize_variables! 207 | @root = destination_root 208 | @project_dir = File.basename(@root) 209 | @name = (options.name || @project_dir) 210 | 211 | @scm = if File.directory?(File.join(@root,'.git')) then :git 212 | elsif File.directory?(File.join(@root,'.hg')) then :hg 213 | elsif File.directory?(File.join(@root,'.svn')) then :svn 214 | elsif options.hg? then :hg 215 | elsif options.git? then :git 216 | end 217 | 218 | case @scm 219 | when :git 220 | @scm_user = `git config user.name`.chomp 221 | @scm_email = `git config user.email`.chomp 222 | 223 | @github_user = `git config github.user`.chomp 224 | when :hg 225 | user_email = `hg showconfig ui.username`.chomp 226 | user_email.scan(/([^<]+)\s+<([^>]+)>/) do |(user,email)| 227 | @scm_user, @scm_email = user, email 228 | end 229 | end 230 | 231 | @modules = modules_of(@name) 232 | @module_depth = @modules.length 233 | @module = @modules.last 234 | 235 | @namespace = options.namespace || namespace_of(@name) 236 | @namespace_dirs = namespace_dirs_of(@name) 237 | @namespace_path = namespace_path_of(@name) 238 | @namespace_dir = @namespace_dirs.last 239 | 240 | @version = options.version 241 | @summary = options.summary 242 | @description = options.description 243 | 244 | @authors = if options.author || options.author 245 | [*options.author, *options.authors] 246 | else 247 | [@scm_user || ENV['USERNAME'] || ENV['USER'].capitalize] 248 | end 249 | @author = @authors.first 250 | 251 | @email = (options.email || @scm_email) 252 | @safe_email = @email.sub('@',' at ') if @email 253 | 254 | @homepage = if options.homepage 255 | options.homepage 256 | elsif !(@github_user.nil? || @github_user.empty?) 257 | "https://github.com/#{@github_user}/#{@name}#readme" 258 | else 259 | "https://rubygems.org/gems/#{@name}" 260 | end 261 | @uri = URI(@homepage) 262 | @bug_tracker = case @uri.host 263 | when 'github.com' 264 | "https://#{@uri.host}#{@uri.path}/issues" 265 | end 266 | 267 | @markup = if options.markdown? then :markdown 268 | elsif options.textile? then :textile 269 | elsif options.markup? then options.markup.to_sym 270 | end 271 | 272 | @markup_ext = Template::Markup::EXT.fetch(@markup) do 273 | say "Unknown markup: #{@markup}", :red 274 | exit -1 275 | end 276 | 277 | @date = Date.today 278 | @year = @date.year 279 | @month = @date.month 280 | @day = @date.day 281 | 282 | @ignore = SortedSet[] 283 | @dependencies = {} 284 | @development_dependencies = {} 285 | 286 | @templates.each do |template| 287 | @ignore.merge(template.ignore) 288 | 289 | @dependencies.merge!(template.dependencies) 290 | @development_dependencies.merge!(template.development_dependencies) 291 | 292 | template.variables.each do |name,value| 293 | instance_variable_set("@#{name}",value) 294 | end 295 | end 296 | 297 | @generated_dirs = {} 298 | @generated_files = {} 299 | end 300 | 301 | # 302 | # Creates directories listed in the template directories. 303 | # 304 | def generate_directories! 305 | @templates.each do |template| 306 | template.each_directory do |dir| 307 | generate_dir dir 308 | end 309 | end 310 | end 311 | 312 | # 313 | # Copies static files and renders templates in the template directories. 314 | # 315 | def generate_files! 316 | # iterate through the templates in reverse, so files in the templates 317 | # loaded last override the previously templates. 318 | @templates.reverse_each do |template| 319 | # copy in the static files first 320 | template.each_file(@markup) do |dest,file| 321 | generate_file dest, file 322 | end 323 | 324 | # then render the templates 325 | template.each_template(@markup) do |dest,file| 326 | generate_file dest, file, template: true 327 | end 328 | end 329 | 330 | @generated_files.each_value do |path| 331 | dir = path.split(File::SEPARATOR,2).first 332 | 333 | if dir == 'bin' 334 | chmod path, 0755 335 | end 336 | end 337 | end 338 | 339 | # 340 | # Initializes the project repository and commits all files. 341 | # 342 | # @since 0.10.0 343 | # 344 | def initialize_scm! 345 | in_root do 346 | case @scm 347 | when :git 348 | unless File.directory?('.git') 349 | run 'git init' 350 | run 'git add .' 351 | run 'git commit -m "Initial commit."' 352 | end 353 | when :hg 354 | unless File.directory?('.hg') 355 | run 'hg init' 356 | run 'hg add .' 357 | run 'hg commit -m "Initial commit."' 358 | end 359 | when :svn 360 | @ignore.each do |pattern| 361 | run "svn propset svn:ignore #{pattern.dump}" 362 | end 363 | 364 | run 'svn add .' 365 | run 'svn commit -m "Initial commit."' 366 | end 367 | end 368 | end 369 | 370 | end 371 | end 372 | -------------------------------------------------------------------------------- /lib/ore/naming.rb: -------------------------------------------------------------------------------- 1 | require 'ore/config' 2 | 3 | require 'yaml' 4 | 5 | module Ore 6 | # 7 | # Provides methods for guessing the namespaces and directories 8 | # of projects. {Naming} uses the naming conventions of project names 9 | # defined by the 10 | # [Ruby Packaging Standard (RPS)](http://chneukirchen.github.com/rps/). 11 | # 12 | # @since 0.9.0 13 | # 14 | module Naming 15 | # The directory which contains executables for a project 16 | BIN_DIR = 'bin' 17 | 18 | # The directory which contains the code for a project 19 | LIB_DIR = 'lib' 20 | 21 | # The directory which contains C extension code for a project 22 | EXT_DIR = 'ext' 23 | 24 | # The directory which contains data files for a project 25 | DATA_DIR = 'data' 26 | 27 | # The directory which contains unit-tests for a project 28 | TEST_DIR = 'test' 29 | 30 | # The directory which contains spec-tests for a project 31 | SPEC_DIR = 'spec' 32 | 33 | # The directory which contains built packages 34 | PKG_DIR = 'pkg' 35 | 36 | # Words used in project names, but never in directory names 37 | IGNORE_NAMESPACES = %w[core ruby rb java] 38 | 39 | # Common abbrevations used in namespaces 40 | COMMON_ABBREVIATIONS = Hash[File.readlines(File.join(Config::DATA_DIR,'abbreviations.txt')).map { |abbrev| 41 | abbrev.chomp! 42 | [abbrev.downcase, abbrev] 43 | }] 44 | 45 | # Common project prefixes and namespaces 46 | COMMON_NAMESPACES = YAML.load_file(File.join(Config::DATA_DIR,'common_namespaces.yml')) 47 | 48 | # 49 | # Splits the project name into individual names. 50 | # 51 | # @param [String] name 52 | # The name to split. 53 | # 54 | # @return [Array] 55 | # The individual names of the project name. 56 | # 57 | def names_in(name) 58 | name.split('-').reject do |word| 59 | IGNORE_NAMESPACES.include?(word) 60 | end 61 | end 62 | 63 | # 64 | # Guesses the module name for a word within a project name. 65 | # 66 | # @param [String] word 67 | # The word within a project name. 68 | # 69 | # @return [String] 70 | # The module name. 71 | # 72 | # @since 0.1.1 73 | # 74 | def module_of(word) 75 | if COMMON_NAMESPACES.has_key?(word) 76 | COMMON_NAMESPACES[word] 77 | elsif COMMON_ABBREVIATIONS.has_key?(word) 78 | COMMON_ABBREVIATIONS[word] 79 | else 80 | word.capitalize 81 | end 82 | end 83 | 84 | # 85 | # Guesses the module names from a project name. 86 | # 87 | # @param [String] name 88 | # The name of the project. 89 | # 90 | # @return [Array] 91 | # The module names for a project. 92 | # 93 | def modules_of(name) 94 | names_in(name).map do |words| 95 | words.split('_').map { |word| module_of(word) }.join 96 | end 97 | end 98 | 99 | # 100 | # Guesses the full namespace for a project. 101 | # 102 | # @param [String] name 103 | # The name of the project. 104 | # 105 | # @return [String] 106 | # The full module namespace for a project. 107 | # 108 | def namespace_of(name) 109 | modules_of(name).join('::') 110 | end 111 | 112 | # 113 | # Converts a camel-case name to an underscored file name. 114 | # 115 | # @param [String] name 116 | # The name to underscore. 117 | # 118 | # @return [String] 119 | # The underscored version of the name. 120 | # 121 | def underscore(name) 122 | name.gsub(/[^A-Z_][A-Z][^A-Z_]/) { |cap| 123 | cap[0,1] + '_' + cap[1..-1] 124 | }.downcase 125 | end 126 | 127 | # 128 | # Guesses the namespace directories within `lib/` for a project. 129 | # 130 | # @param [String] name 131 | # The name of the project. 132 | # 133 | # @return [Array] 134 | # The namespace directories for the project. 135 | # 136 | def namespace_dirs_of(name) 137 | names_in(name).map { |word| underscore(word) } 138 | end 139 | 140 | # 141 | # Guesses the namespace directory within `lib/` for a project. 142 | # 143 | # @param [String] name 144 | # The name of the project. 145 | # 146 | # @return [String] 147 | # The namespace directory for the project. 148 | # 149 | def namespace_path_of(name) 150 | File.join(namespace_dirs_of(name)) 151 | end 152 | end 153 | end 154 | -------------------------------------------------------------------------------- /lib/ore/options.rb: -------------------------------------------------------------------------------- 1 | require 'yaml' 2 | 3 | module Ore 4 | # 5 | # Value object to contain `~/.ore/options.yml` data. 6 | # 7 | # @since 0.11.0 8 | # 9 | class Options 10 | 11 | # Default markup 12 | DEFAULT_MARKUP = 'markdown' 13 | 14 | # Default version 15 | DEFAULT_VERSION = '0.1.0' 16 | 17 | # Default summary 18 | DEFAULT_SUMMARY = %q{TODO: Summary} 19 | 20 | # Default description 21 | DEFAULT_DESCRIPTION = %q{TODO: Description} 22 | 23 | # Default templates 24 | DEFAULT_TEMPLATES = [ 25 | :git, 26 | :mit, 27 | :bundler, 28 | :rubygems_tasks, 29 | :rdoc, 30 | :rspec 31 | ] 32 | 33 | # Default options 34 | DEFAULTS = { 35 | markup: DEFAULT_MARKUP, 36 | version: DEFAULT_VERSION, 37 | summary: DEFAULT_SUMMARY, 38 | description: DEFAULT_DESCRIPTION 39 | } 40 | DEFAULT_TEMPLATES.each { |name| DEFAULTS[name] = true } 41 | 42 | # 43 | # Initializes the options. 44 | # 45 | # @param [Hash{Symbol => Object}] options 46 | # The options hash. 47 | # 48 | def initialize(options={}) 49 | @options = DEFAULTS.merge(options) 50 | end 51 | 52 | # 53 | # Loads the options from a YAML file. 54 | # 55 | # @param [String] path 56 | # Path to the options file. 57 | # 58 | # @return [Options] 59 | # The loaded options. 60 | # 61 | # @raise [RuntimeError] 62 | # The file contained malformed YAML. 63 | # 64 | def self.load(path) 65 | data = YAML.load_file(path) 66 | 67 | unless data.kind_of?(Hash) 68 | raise("#{path} must contain a YAML encoded Hash") 69 | end 70 | 71 | options = {} 72 | 73 | data.each do |key,value| 74 | options[key.to_sym] = value 75 | end 76 | 77 | return new(options) 78 | end 79 | 80 | # 81 | # Accesses an option. 82 | # 83 | # @param [Symbol] key 84 | # The option name. 85 | # 86 | # @return [Object] 87 | # The option value. 88 | # 89 | def [](key) 90 | @options[key] 91 | end 92 | 93 | end 94 | end 95 | -------------------------------------------------------------------------------- /lib/ore/template.rb: -------------------------------------------------------------------------------- 1 | require 'ore/template/directory' 2 | require 'ore/template/interpolations' 3 | require 'ore/template/helpers' 4 | require 'ore/template/template' 5 | require 'ore/config' 6 | 7 | # register builtin templates 8 | Ore::Config.builtin_templates { |path| Ore::Template.register(path) } 9 | 10 | # register installed templates 11 | Ore::Config.installed_templates { |path| Ore::Template.register(path) } 12 | -------------------------------------------------------------------------------- /lib/ore/template/directory.rb: -------------------------------------------------------------------------------- 1 | require 'ore/template/exceptions/invalid_template' 2 | require 'ore/template/markup' 3 | 4 | require 'yaml' 5 | require 'find' 6 | 7 | module Ore 8 | module Template 9 | # 10 | # Represents a template directory and the static files, `.erb` files 11 | # and sub-directories within it. 12 | # 13 | class Directory 14 | 15 | # The template configuration file 16 | CONFIG_FILE = 'template.yml' 17 | 18 | # Files or directory names to ignore 19 | IGNORE = ['.git', CONFIG_FILE] 20 | 21 | # The path of the template directory 22 | attr_reader :path 23 | 24 | # The directories within the template directory 25 | attr_reader :directories 26 | 27 | # The static files in the template directory 28 | attr_reader :files 29 | 30 | # The ERb templates in the template directory 31 | attr_reader :templates 32 | 33 | # The include templates in the template directory 34 | attr_reader :includes 35 | 36 | # Other templates to be disabled 37 | attr_reader :disable 38 | 39 | # Other templates to be enabled 40 | attr_reader :enable 41 | 42 | # The variables to use when rendering the template files 43 | attr_reader :variables 44 | 45 | # Files to ignore 46 | # 47 | # @since 0.9.0 48 | attr_reader :ignore 49 | 50 | # Runtime dependencies defined by the template 51 | # 52 | # @since 0.9.0 53 | attr_reader :dependencies 54 | 55 | # Development dependencies defined by the template 56 | # 57 | # @since 0.9.0 58 | attr_reader :development_dependencies 59 | 60 | # 61 | # Initializes a new template directory. 62 | # 63 | # @param [String] path 64 | # The path to the template directory. 65 | # 66 | def initialize(path) 67 | @path = File.expand_path(path) 68 | 69 | @directories = [] 70 | @files = {} 71 | @templates = {} 72 | @includes = Hash.new { |hash,key| hash[key] = {} } 73 | 74 | @disable = [] 75 | @enable = [] 76 | 77 | @ignore = [] 78 | @dependencies = {} 79 | @development_dependencies = {} 80 | @variables = {} 81 | 82 | load! 83 | scan! 84 | end 85 | 86 | # 87 | # Enumerates through the directories in the template directory. 88 | # 89 | # @yield [path] 90 | # The given block will be passed each directory path. 91 | # 92 | # @yieldparam [String] path 93 | # The relative path of a directory within the template directory. 94 | # 95 | def each_directory(&block) 96 | @directories.each(&block) 97 | end 98 | 99 | # 100 | # Enumerates through every file in the template directory. 101 | # 102 | # @param [Symbol] markup 103 | # The markup to look for. 104 | # 105 | # @yield [path] 106 | # The given block will be passed each file path. 107 | # 108 | # @yieldparam [String] path 109 | # A relative path of a file within the template directory. 110 | # 111 | def each_file(markup) 112 | @files.each do |dest,file| 113 | if (formatted_like?(dest,markup) || !formatted?(dest)) 114 | yield dest, file 115 | end 116 | end 117 | end 118 | 119 | # 120 | # Enumerates over every template within the template directory. 121 | # 122 | # @param [Symbol] markup 123 | # The markup to look for. 124 | # 125 | # @yield [path] 126 | # The given block will be passed each template path. 127 | # 128 | # @yieldparam [String] path 129 | # A relative path of a template within the template directory. 130 | # 131 | def each_template(markup) 132 | @templates.each do |dest,file| 133 | if (formatted_like?(dest,markup) || !formatted?(dest)) 134 | yield dest, file 135 | end 136 | end 137 | end 138 | 139 | protected 140 | 141 | # 142 | # Loads template configuration information from `template.yml`. 143 | # 144 | # @raise [InvalidTemplate] 145 | # The `template.yml` file did not contain a YAML Hash. 146 | # 147 | # @since 0.2.0 148 | # 149 | def load! 150 | config_path = File.join(@path,CONFIG_FILE) 151 | return false unless File.file?(config_path) 152 | 153 | config = YAML.load_file(config_path) 154 | return false unless config.kind_of?(Hash) 155 | 156 | @disable = Array(config['disable']).map(&:to_sym) 157 | @enable = Array(config['enable']).map(&:to_sym) 158 | 159 | @ignore = Array(config['ignore']) 160 | 161 | case (dependencies = config['dependencies']) 162 | when Hash 163 | @dependencies.merge!(dependencies) 164 | when nil 165 | else 166 | raise(InvalidTemplate,"template dependencies must be a Hash: #{config_path.dump}") 167 | end 168 | 169 | case (dependencies = config['development_dependencies']) 170 | when Hash 171 | @development_dependencies.merge!(dependencies) 172 | when nil 173 | else 174 | raise(InvalidTemplate,"template dependencies must be a Hash: #{config_path.dump}") 175 | end 176 | 177 | case (variables = config['variables']) 178 | when Hash 179 | variables.each do |name,value| 180 | @variables[name.to_sym] = value 181 | end 182 | when nil 183 | else 184 | raise(InvalidTemplate,"template variables must be a Hash: #{config_path.dump}") 185 | end 186 | 187 | return true 188 | end 189 | 190 | # 191 | # Scans the template directory recursively recording the directories, 192 | # files and partial templates. 193 | # 194 | def scan! 195 | Dir.chdir(@path) do 196 | Find.find('.') do |file| 197 | next if file == '.' 198 | 199 | # ignore the ./ 200 | file = file[2..-1] 201 | name = File.basename(file) 202 | 203 | # ignore certain files/directories 204 | Find.prune if ignored?(name) 205 | 206 | if File.directory?(file) 207 | @directories << file 208 | elsif File.file?(file) 209 | src = File.join(@path,file) 210 | 211 | case File.extname(name) 212 | when '.erb' 213 | # erb template 214 | if name.start_with?('_') 215 | # partial template 216 | template_dir = File.dirname(file) 217 | template_name = name[1..-1].chomp('.erb').to_sym 218 | 219 | @includes[template_dir][template_name] = src 220 | else 221 | dest = file.chomp('.erb') 222 | 223 | @templates[dest] = src 224 | end 225 | else 226 | # static file 227 | @files[file] = src 228 | end 229 | end 230 | end 231 | end 232 | end 233 | 234 | # 235 | # Determines whether a file is markup formatted. 236 | # 237 | # @param [String] path 238 | # The path to the file. 239 | # 240 | # @return [Boolean] 241 | # Specifies whether the file is formatting. 242 | # 243 | def formatted?(path) 244 | Markup::EXTS.values.any? { |exts| exts.include?(File.extname(path)) } 245 | end 246 | 247 | # 248 | # Determines if a file has a specific type of markup formatting. 249 | # 250 | # @param [String] path 251 | # The path to the file. 252 | # 253 | # @param [Symbol] markup 254 | # The specified type of markup. 255 | # 256 | # @return [Boolean] 257 | # Specifies whether the file contains the given formatting. 258 | # 259 | def formatted_like?(path,markup) 260 | Markup::EXTS[markup].include?(File.extname(path)) 261 | end 262 | 263 | private 264 | def ignored?(filename) 265 | IGNORE.include?(filename) || @ignore.include?(filename) 266 | end 267 | end 268 | end 269 | end 270 | -------------------------------------------------------------------------------- /lib/ore/template/exceptions.rb: -------------------------------------------------------------------------------- 1 | require 'ore/template/exceptions/invalid_template' 2 | -------------------------------------------------------------------------------- /lib/ore/template/exceptions/invalid_template.rb: -------------------------------------------------------------------------------- 1 | module Ore 2 | module Template 3 | # 4 | # @since 0.2.0 5 | # 6 | class InvalidTemplate < RuntimeError 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/ore/template/helpers.rb: -------------------------------------------------------------------------------- 1 | require 'ore/template/helpers/markdown' 2 | require 'ore/template/helpers/textile' 3 | require 'ore/template/helpers/rdoc' 4 | 5 | module Ore 6 | module Template 7 | # 8 | # Helper methods that can be used within ERb templates. 9 | # 10 | module Helpers 11 | # Markup helpers 12 | MARKUP = { 13 | markdown: Markdown, 14 | textile: Textile, 15 | rdoc: RDoc 16 | } 17 | 18 | # 19 | # Renders all include files with the given name. 20 | # 21 | # @param [Symbol] name 22 | # The name of the include. 23 | # 24 | # @param [String] separator 25 | # The separator to join includes with. 26 | # 27 | # @yield [output] 28 | # If a block is given, it will be passed the rendered include files. 29 | # 30 | # @yieldparam [String] output 31 | # The combined result of the rendered include files. 32 | # 33 | # @return [String, nil] 34 | # The combined result of the rendered include files. 35 | # If no includes were found, `nil` will be returned. 36 | # 37 | def includes(name,separator=$/) 38 | name = name.to_sym 39 | output_buffer = [] 40 | 41 | if @current_template_dir 42 | context = instance_eval('binding') 43 | 44 | @templates.each do |template| 45 | if template.includes.has_key?(@current_template_dir) 46 | path = template.includes[@current_template_dir][name] 47 | 48 | if path 49 | erb = ERB.new(File.read(path),nil,'-') 50 | output_buffer << erb.result(context) 51 | end 52 | end 53 | end 54 | end 55 | 56 | output = output_buffer.join(separator) 57 | output = nil if output.empty? 58 | 59 | if (block_given? && output) 60 | output = yield(output) 61 | end 62 | 63 | return output 64 | end 65 | 66 | # 67 | # Determines if Git is enabled. 68 | # 69 | # @return [Boolean] 70 | # Specifies whether Git was enabled. 71 | # 72 | # @since 0.7.0 73 | # 74 | def git? 75 | @scm == :git 76 | end 77 | 78 | # 79 | # Determines if Hg is enabled. 80 | # 81 | # @return [Boolean] 82 | # Specifies whether Hg was enabled. 83 | # 84 | # @since 0.9.0 85 | # 86 | def hg? 87 | @scm == :hg 88 | end 89 | 90 | # 91 | # Determines if SVN is enabled. 92 | # 93 | # @return [Boolean] 94 | # Specifies whether SVN was enabled. 95 | # 96 | # @since 0.9.0 97 | # 98 | def svn? 99 | @scm == :svn 100 | end 101 | 102 | # 103 | # Determines if a template was enabled. 104 | # 105 | # @return [Boolean] 106 | # Specifies whether the template was enabled. 107 | # 108 | def enabled?(name) 109 | @enabled_templates.include?(name.to_sym) 110 | end 111 | 112 | # 113 | # Determines whether the project will have a bin script. 114 | # 115 | # @return [Boolean] 116 | # Specifies whether the project will have a bin script. 117 | # 118 | # @since 0.7.0 119 | # 120 | def bin? 121 | enabled?(:bin) 122 | end 123 | 124 | # 125 | # Determines if the project will contain RDoc documented. 126 | # 127 | # @return [Boolean] 128 | # Specifies whether the project will contain RDoc documented. 129 | # 130 | def rdoc? 131 | enabled?(:rdoc) 132 | end 133 | 134 | # 135 | # Determines if the project will contain YARD documented. 136 | # 137 | # @return [Boolean] 138 | # Specifies whether the project will contain YARD documentation. 139 | # 140 | def yard? 141 | enabled?(:yard) 142 | end 143 | 144 | # 145 | # Determines if the project is using test-unit. 146 | # 147 | # @return [Boolean] 148 | # Specifies whether the project is using test-unit. 149 | # 150 | def test_unit? 151 | enabled?(:test_unit) 152 | end 153 | 154 | # 155 | # Determines if the project is using RSpec. 156 | # 157 | # @return [Boolean] 158 | # Specifies whether the project is using RSpec. 159 | # 160 | def rspec? 161 | enabled?(:rspec) 162 | end 163 | 164 | # 165 | # Determines if the project is using Bundler. 166 | # 167 | # @return [Boolean] 168 | # Specifies whether the project is using Bundler. 169 | # 170 | def bundler? 171 | enabled?(:bundler) 172 | end 173 | 174 | # 175 | # Determines if the project is using `Bundler::GemHelper`. 176 | # 177 | # @return [Boolean] 178 | # Specifies whether the project is using `Bundler::GemHelper`. 179 | # 180 | # @since 0.9.0 181 | # 182 | def bundler_tasks? 183 | enabled?(:bundler_tasks) 184 | end 185 | 186 | # 187 | # Determines if the project is using `Gem::Tasks`. 188 | # 189 | # @return [Boolean] 190 | # Specifies whether the project is using `Gem::Tasks`. 191 | # 192 | # @since 0.9.0 193 | # 194 | def rubygems_tasks? 195 | enabled?(:rubygems_tasks) 196 | end 197 | 198 | # 199 | # Determines if the project is using `Jeweler::Tasks`. 200 | # 201 | # @return [Boolean] 202 | # Specifies whether the project is using `Jeweler::Tasks`. 203 | # 204 | # @since 0.3.0 205 | # 206 | def jeweler_tasks? 207 | enabled?(:jeweler_tasks) 208 | end 209 | 210 | # 211 | # Determines if the project is using `Gem::PackageTask`. 212 | # 213 | # @return [Boolean] 214 | # Specifies whether the project is using `Gem::PackageTask`. 215 | # 216 | # @since 0.9.0 217 | # 218 | def gem_package_task? 219 | enabled?(:gem_package_task) 220 | end 221 | 222 | # 223 | # Creates an indentation string. 224 | # 225 | # @param [Integer] n 226 | # The number of times to indent. 227 | # 228 | # @param [Integer] spaces 229 | # The number of spaces to indent by. 230 | # 231 | # @yield [] 232 | # The given block will be used as the text. 233 | # 234 | # @return [String] 235 | # The indentation string. 236 | # 237 | def indent(n,spaces=2) 238 | @indent ||= 0 239 | @indent += (spaces * n) 240 | 241 | margin = ' ' * @indent 242 | 243 | text = if block_given? 244 | yield.each_line.map { |line| margin + line }.join 245 | else 246 | margin 247 | end 248 | 249 | @indent -= (spaces * n) 250 | return text 251 | end 252 | 253 | # 254 | # Escapes data for YAML encoding. 255 | # 256 | # @param [String] data 257 | # The data to escape. 258 | # 259 | # @return [String] 260 | # The YAML safe data. 261 | # 262 | def yaml_escape(data) 263 | case data 264 | when String 265 | if data =~ /:\s/ 266 | data.dump 267 | elsif data.include?($/) 268 | lines = [''] 269 | 270 | data.each_line do |line| 271 | lines << " #{line.strip}" 272 | end 273 | 274 | lines.join($/) 275 | else 276 | data 277 | end 278 | else 279 | data.to_s 280 | end 281 | end 282 | end 283 | end 284 | end 285 | -------------------------------------------------------------------------------- /lib/ore/template/helpers/markdown.rb: -------------------------------------------------------------------------------- 1 | module Ore 2 | module Template 3 | module Helpers 4 | # 5 | # @api semipublic 6 | # 7 | # @since 0.10.0 8 | # 9 | module Markdown 10 | # 11 | # Emits a markdown link. 12 | # 13 | # @param [String, nil] text 14 | # 15 | # @param [String] url 16 | # 17 | # @return [String] 18 | # 19 | def link_to(text,url) 20 | "[#{text}](#{url})" 21 | end 22 | 23 | # 24 | # Emits a markdown image. 25 | # 26 | # @param [String] url 27 | # 28 | # @param [String, nil] alt 29 | # 30 | # @return [String] 31 | # 32 | def image(url,alt=nil) 33 | "![#{alt}](#{url})" 34 | end 35 | 36 | # 37 | # Emits a markdown h1 heading. 38 | # 39 | # @param [String] title 40 | # 41 | # @return [String] 42 | # 43 | def h1(title) 44 | "# #{title}" 45 | end 46 | 47 | # 48 | # Emits a markdown h2 heading. 49 | # 50 | # @param [String] title 51 | # 52 | # @return [String] 53 | # 54 | def h2(title) 55 | "## #{title}" 56 | end 57 | 58 | # 59 | # Emits a markdown h3 heading. 60 | # 61 | # @param [String] title 62 | # 63 | # @return [String] 64 | # 65 | def h3(title) 66 | "### #{title}" 67 | end 68 | 69 | # 70 | # Emits a markdown h4 heading. 71 | # 72 | # @param [String] title 73 | # 74 | # @return [String] 75 | # 76 | def h4(title) 77 | "#### #{title}" 78 | end 79 | 80 | # 81 | # Emits a markdown code block. 82 | # 83 | # @param [String] code 84 | # 85 | # @yield [] 86 | # The return value of the given block will be used as the code. 87 | # 88 | # @return [String] 89 | # 90 | def pre(code) 91 | code.each_line.map { |line| " #{line}" }.join 92 | end 93 | end 94 | end 95 | end 96 | end 97 | -------------------------------------------------------------------------------- /lib/ore/template/helpers/rdoc.rb: -------------------------------------------------------------------------------- 1 | module Ore 2 | module Template 3 | module Helpers 4 | # 5 | # @api semipublic 6 | # 7 | # @since 0.10.0 8 | # 9 | module RDoc 10 | # 11 | # Emits a RDoc link. 12 | # 13 | # @param [String, nil] text 14 | # 15 | # @param [String] url 16 | # 17 | # @return [String] 18 | # 19 | def link_to(text,url) 20 | "{#{text}}[#{url}]" 21 | end 22 | 23 | # 24 | # Emits a RDoc image. 25 | # 26 | # @param [String] url 27 | # 28 | # @param [String, nil] alt 29 | # 30 | # @return [String] 31 | # 32 | def image(url,alt=nil) 33 | "{#{alt}}[rdoc-image:#{url}]" 34 | end 35 | 36 | # 37 | # Emits a RDoc h1 heading. 38 | # 39 | # @param [String] title 40 | # 41 | # @return [String] 42 | # 43 | def h1(title) 44 | "= #{title}" 45 | end 46 | 47 | # 48 | # Emits a RDoc h2 heading. 49 | # 50 | # @param [String] title 51 | # 52 | # @return [String] 53 | # 54 | def h2(title) 55 | "== #{title}" 56 | end 57 | 58 | # 59 | # Emits a RDoc h3 heading. 60 | # 61 | # @param [String] title 62 | # 63 | # @return [String] 64 | # 65 | def h3(title) 66 | "=== #{title}" 67 | end 68 | 69 | # 70 | # Emits a RDoc h4 heading. 71 | # 72 | # @param [String] title 73 | # 74 | # @return [String] 75 | # 76 | def h4(title) 77 | "==== #{title}" 78 | end 79 | 80 | # 81 | # Emits a RDoc code block. 82 | # 83 | # @param [String] code 84 | # 85 | # @yield [] 86 | # The return value of the given block will be used as the code. 87 | # 88 | # @return [String] 89 | # 90 | def pre(code) 91 | code.each_line.map { |line| " #{line}" }.join 92 | end 93 | end 94 | end 95 | end 96 | end 97 | -------------------------------------------------------------------------------- /lib/ore/template/helpers/textile.rb: -------------------------------------------------------------------------------- 1 | module Ore 2 | module Template 3 | module Helpers 4 | # 5 | # @api semipublic 6 | # 7 | # @since 0.10.0 8 | # 9 | module Textile 10 | # 11 | # Emits a Textile link. 12 | # 13 | # @param [String, nil] text 14 | # 15 | # @param [String] url 16 | # 17 | # @return [String] 18 | # 19 | def link_to(text,url) 20 | if text 21 | "#{text.dump}:#{url}" 22 | else 23 | url 24 | end 25 | end 26 | 27 | # 28 | # Emits a Textile image tag. 29 | # 30 | # @param [String] url 31 | # 32 | # @param [String, nil] alt 33 | # 34 | # @return [String] 35 | # 36 | def image(url,alt=nil) 37 | if alt then "!#{url}(#{alt})!" 38 | else "!#{url}!" 39 | end 40 | end 41 | 42 | # 43 | # Emits a Textile h1 heading. 44 | # 45 | # @param [String] title 46 | # 47 | # @return [String] 48 | # 49 | def h1(title) 50 | "h1. #{title}" 51 | end 52 | 53 | # 54 | # Emits a Textile h2 heading. 55 | # 56 | # @param [String] title 57 | # 58 | # @return [String] 59 | # 60 | def h2(title) 61 | "h2. #{title}" 62 | end 63 | 64 | # 65 | # Emits a Textile h3 heading. 66 | # 67 | # @param [String] title 68 | # 69 | # @return [String] 70 | # 71 | def h3(title) 72 | "h3. #{title}" 73 | end 74 | 75 | # 76 | # Emits a Textile h4 heading. 77 | # 78 | # @param [String] title 79 | # 80 | # @return [String] 81 | # 82 | def h4(title) 83 | "h4. #{title}" 84 | end 85 | 86 | # 87 | # Emits a Textile code block. 88 | # 89 | # @param [String] code 90 | # 91 | # @yield [] 92 | # The return value of the given block will be used as the code. 93 | # 94 | # @return [String] 95 | # 96 | def pre(code) 97 | if code =~ /#{$/}\s*#{$/}/ 98 | "bc.. #{code}" 99 | else 100 | "bc. #{code}" 101 | end 102 | end 103 | end 104 | end 105 | end 106 | end 107 | -------------------------------------------------------------------------------- /lib/ore/template/interpolations.rb: -------------------------------------------------------------------------------- 1 | module Ore 2 | module Template 3 | # 4 | # Handles the expansion of paths and substitution of path keywords. 5 | # The following keywords are supported: 6 | # 7 | # * `[name]` - The name of the project. 8 | # * `[project_dir]` - The directory base-name derived from the project 9 | # name. 10 | # * `[namespace_path]` - The full directory path derived from the 11 | # project name. 12 | # * `[namespace_dir]` - The last directory name derived from the 13 | # project name. 14 | # 15 | module Interpolations 16 | # The accepted interpolation keywords that may be used in paths 17 | @@keywords = %w[ 18 | name 19 | version 20 | project_dir 21 | namespace_path 22 | namespace_dir 23 | markup 24 | date 25 | year 26 | month 27 | day 28 | ] 29 | 30 | protected 31 | 32 | # 33 | # Expands the given path by substituting the interpolation keywords 34 | # for the related instance variables. 35 | # 36 | # @param [String] path 37 | # The path to expand. 38 | # 39 | # @return [String] 40 | # The expanded path. 41 | # 42 | # @example Assuming `@project_dir` contains `my_project`. 43 | # interpolate("lib/[project_dir].rb") 44 | # # => "lib/my_project.rb" 45 | # 46 | # @example Assuming `@namespace_path` contains `my/project`. 47 | # interpolate("spec/[namespace_path]_spec.rb") 48 | # # => "spec/my/project_spec.rb" 49 | # 50 | def interpolate(path) 51 | dirs = path.split(File::SEPARATOR) 52 | 53 | dirs.each do |dir| 54 | dir.gsub!(/(\[[a-z_]+\])/) do |capture| 55 | keyword = capture[1..-2] 56 | 57 | if @@keywords.include?(keyword) 58 | instance_variable_get("@#{keyword}") 59 | else 60 | capture 61 | end 62 | end 63 | end 64 | 65 | return File.join(dirs.reject { |dir| dir.empty? }) 66 | end 67 | end 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /lib/ore/template/markup.rb: -------------------------------------------------------------------------------- 1 | module Ore 2 | module Template 3 | module Markup 4 | # Official file extensions for various markups 5 | EXT = { 6 | markdown: 'md', 7 | textile: 'tt', 8 | rdoc: 'rdoc' 9 | } 10 | 11 | # Other common file extensions for various markups 12 | EXTS = { 13 | markdown: %w[.md .markdown], 14 | textile: %w[.tt .textile], 15 | rdoc: %w[.rdoc] 16 | } 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/ore/template/template.rb: -------------------------------------------------------------------------------- 1 | module Ore 2 | module Template 3 | # 4 | # The templates registered with the generator. 5 | # 6 | # @return [Hash{Symbol => String}] 7 | # The template names and paths. 8 | # 9 | # @api semipublic 10 | # 11 | # @since 0.9.0 12 | # 13 | def self.templates 14 | @@templates ||= {} 15 | end 16 | 17 | # 18 | # Determines whether a template was registered. 19 | # 20 | # @param [Symbol, String] name 21 | # The name of the template. 22 | # 23 | # @return [Boolean] 24 | # Specifies whether the template was registered. 25 | # 26 | # @api semipublic 27 | # 28 | # @since 0.9.0 29 | # 30 | def self.template?(name) 31 | self.templates.has_key?(name.to_sym) 32 | end 33 | 34 | # 35 | # Registers a template with the generator. 36 | # 37 | # @param [String] path 38 | # The path to the template. 39 | # 40 | # @return [Symbol] 41 | # The name of the registered template. 42 | # 43 | # @raise [StandardError] 44 | # The given path was not a directory. 45 | # 46 | # @api semipublic 47 | # 48 | # @since 0.9.0 49 | # 50 | def self.register(path) 51 | unless File.directory?(path) 52 | raise(StandardError,"#{path.dump} is must be a directory") 53 | end 54 | 55 | name = File.basename(path).sub(/^ore-/,'').to_sym 56 | 57 | self.templates[name] = path 58 | return name 59 | end 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /lib/ore/version.rb: -------------------------------------------------------------------------------- 1 | module Ore 2 | # ore version 3 | VERSION = '0.11.0' 4 | end 5 | -------------------------------------------------------------------------------- /ore.gemspec: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | require 'yaml' 4 | 5 | Gem::Specification.new do |gem| 6 | gemspec = YAML.load_file('gemspec.yml') 7 | 8 | gem.name = gemspec.fetch('name') 9 | gem.version = gemspec.fetch('version') do 10 | lib_dir = File.join(File.dirname(__FILE__),'lib') 11 | $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir) 12 | 13 | require 'ore/version' 14 | Ore::VERSION 15 | end 16 | 17 | gem.summary = gemspec['summary'] 18 | gem.description = gemspec['description'] 19 | gem.licenses = Array(gemspec['license']) 20 | gem.authors = Array(gemspec['authors']) 21 | gem.email = gemspec['email'] 22 | gem.homepage = gemspec['homepage'] 23 | 24 | glob = lambda { |patterns| gem.files & Dir[*patterns] } 25 | 26 | gem.files = `git ls-files`.split($/) 27 | 28 | `git submodule --quiet foreach --recursive pwd`.split($/).each do |submodule| 29 | submodule.sub!("#{Dir.pwd}/",'') 30 | 31 | Dir.chdir(submodule) do 32 | `git ls-files`.split($/).map do |subpath| 33 | gem.files << File.join(submodule,subpath) 34 | end 35 | end 36 | end 37 | 38 | gem.files = glob[gemspec['files']] if gemspec['files'] 39 | 40 | gem.executables = gemspec.fetch('executables') do 41 | glob['bin/*'].map { |path| File.basename(path) } 42 | end 43 | gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.' 44 | 45 | gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb'] 46 | gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb'] 47 | gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}'] 48 | 49 | gem.require_paths = Array(gemspec.fetch('require_paths') { 50 | %w[ext lib].select { |dir| File.directory?(dir) } 51 | }) 52 | 53 | gem.requirements = gemspec['requirements'] 54 | gem.required_ruby_version = gemspec['required_ruby_version'] 55 | gem.required_rubygems_version = gemspec['required_rubygems_version'] 56 | gem.post_install_message = gemspec['post_install_message'] 57 | 58 | split = lambda { |string| string.split(/,\s*/) } 59 | 60 | if gemspec['dependencies'] 61 | gemspec['dependencies'].each do |name,versions| 62 | gem.add_dependency(name,split[versions]) 63 | end 64 | end 65 | 66 | if gemspec['development_dependencies'] 67 | gemspec['development_dependencies'].each do |name,versions| 68 | gem.add_development_dependency(name,split[versions]) 69 | end 70 | end 71 | end 72 | -------------------------------------------------------------------------------- /spec/gemspec_examples.rb: -------------------------------------------------------------------------------- 1 | require 'rspec' 2 | 3 | require 'ore/generator' 4 | 5 | shared_examples "a gemspec" do 6 | it "should have a name" do 7 | expect(subject.name).to eq(@name) 8 | end 9 | 10 | it "should not contain a version by default" do 11 | expect(subject.version.version).to eq(Ore::Options::DEFAULT_VERSION) 12 | end 13 | 14 | it "should a dummy summary" do 15 | expect(subject.summary).to eq(Ore::Options::DEFAULT_SUMMARY) 16 | end 17 | 18 | it "should a dummy description" do 19 | expect(subject.description).to eq(Ore::Options::DEFAULT_DESCRIPTION) 20 | end 21 | 22 | it "should have a license" do 23 | expect(subject.license).to be == 'MIT' 24 | end 25 | 26 | it "should have authors" do 27 | expect(subject.authors).not_to be_empty 28 | end 29 | 30 | it "should have a dummy homepage" do 31 | expect(subject.homepage).not_to be_empty 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /spec/generator_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'gemspec_examples' 3 | require 'helpers/generator' 4 | require 'ore/generator' 5 | 6 | describe Generator do 7 | include Helpers::Generator 8 | 9 | context "default" do 10 | before(:all) do 11 | @name = 'my-project' 12 | 13 | generate!(@name) 14 | end 15 | 16 | it "should create the project root directory" do 17 | expect(@path).to be_directory 18 | end 19 | 20 | it "should create the lib/ directory" do 21 | expect(@path).to have_directory('lib') 22 | end 23 | 24 | it "should create a file to load the project within lib/" do 25 | expect(@path).to have_file('lib','my','project.rb') 26 | end 27 | 28 | it "should create a namespace directory within lib/" do 29 | expect(@path).to have_directory('lib','my','project') 30 | end 31 | 32 | it "should create a version.rb file within the namespace directory" do 33 | expect(@path).to have_file('lib','my','project','version.rb') 34 | end 35 | 36 | it "should not create the bin/ directory by default" do 37 | expect(@path).not_to have_directory('bin') 38 | end 39 | 40 | it "should create a test/ directory by default" do 41 | expect(@path).not_to have_directory('test') 42 | end 43 | 44 | it "should add a *.gemspec file" do 45 | expect(@path.join("#{@name}.gemspec")).to be_file 46 | end 47 | 48 | it "should add a .document file" do 49 | expect(@path).to have_file('.document') 50 | end 51 | 52 | it "should add a Rakefile" do 53 | expect(@path).to have_file('Rakefile') 54 | end 55 | 56 | it "should add a README.md file" do 57 | expect(@path).to have_file('README.md') 58 | end 59 | 60 | it "should add a ChangeLog.md file" do 61 | expect(@path).to have_file('ChangeLog.md') 62 | end 63 | 64 | it "should add a LICENSE.txt file" do 65 | expect(@path).to have_file('LICENSE.txt') 66 | end 67 | 68 | it "should add a Gemfile" do 69 | expect(@path).to have_file('Gemfile') 70 | end 71 | 72 | it "should add 'bundler' as a development dependency" do 73 | expect(@gemspec).to have_development_dependency('bundler') 74 | end 75 | 76 | it "should not have any dependencies in the Gemfile" do 77 | gemfile = (@path + 'Gemfile').read 78 | expect(gemfile).to eq(<<-GEMFILE) 79 | source 'https://rubygems.org' 80 | 81 | gemspec 82 | GEMFILE 83 | end 84 | 85 | it "should add 'Gemfile.lock' to the .gitignore file" do 86 | expect(gitignore).to include('/Gemfile.lock') 87 | end 88 | end 89 | 90 | context "gemspec_yml" do 91 | before(:all) do 92 | @name = 'gemspec_yml_project' 93 | 94 | generate!(@name, gemspec_yml: true) 95 | end 96 | 97 | it "should add a gemspec.yml file" do 98 | expect(@path).to have_file('gemspec.yml') 99 | end 100 | 101 | describe "gemspec.yml" do 102 | subject { YAML.load_file(@path.join('gemspec.yml')) } 103 | 104 | it "should have a name" do 105 | expect(subject['name']).to eq(@name) 106 | end 107 | 108 | it "should not contain a version by default" do 109 | expect(subject).not_to have_key('version') 110 | end 111 | 112 | it "should a dummy summary" do 113 | expect(subject['summary']).to eq(Ore::Options::DEFAULT_SUMMARY) 114 | end 115 | 116 | it "should a dummy description" do 117 | expect(subject['description']).to eq(Ore::Options::DEFAULT_DESCRIPTION) 118 | end 119 | 120 | it "should have a license" do 121 | expect(subject['license']).to be == 'MIT' 122 | end 123 | 124 | it "should have authors" do 125 | expect(subject['authors']).not_to be_empty 126 | end 127 | 128 | it "should have a dummy homepage" do 129 | expect(subject['homepage']).not_to be_empty 130 | end 131 | 132 | it "should have 'rubygems-tasks' as a development dependency" do 133 | expect(subject['development_dependencies']).to have_key('rubygems-tasks') 134 | end 135 | end 136 | 137 | it "should add a *.gemspec file" do 138 | expect(@path).to have_file("#{@name}.gemspec") 139 | end 140 | 141 | describe "*.gemspec file" do 142 | subject { @gemspec } 143 | 144 | it_should_behave_like "a gemspec" 145 | end 146 | end 147 | 148 | context "gemspec" do 149 | before(:all) do 150 | @name = 'gemspec_project' 151 | 152 | generate!(@name, gemspec: true) 153 | end 154 | 155 | it "should add a *.gemspec file" do 156 | expect(@path).to have_file("#{@name}.gemspec") 157 | end 158 | 159 | context "*.gemspec file" do 160 | subject { @gemspec } 161 | 162 | it_should_behave_like "a gemspec" 163 | 164 | it "should have 'rubygems-tasks' as a development dependency" do 165 | expect(subject).to have_development_dependency('rubygems-tasks') 166 | end 167 | end 168 | end 169 | 170 | context "git" do 171 | before(:all) do 172 | @name = 'git-project' 173 | 174 | generate!(@name, git: true) 175 | end 176 | 177 | it "should create a .git directory" do 178 | expect(@path).to have_directory('.git') 179 | end 180 | 181 | it "should create a .gitignore file" do 182 | expect(@path).to have_file('.gitignore') 183 | end 184 | end 185 | 186 | context "hg" do 187 | before(:all) do 188 | @name = 'hg-project' 189 | 190 | generate!(@name, hg: true) 191 | end 192 | 193 | it "should create a .hg directory" do 194 | expect(@path).to have_directory('.hg') 195 | end 196 | 197 | it "should create a .hgignore file" do 198 | expect(@path).to have_file('.hgignore') 199 | end 200 | end 201 | 202 | context "bin" do 203 | before(:all) do 204 | @name = 'script-project' 205 | @script = File.join('bin',@name) 206 | 207 | generate!(@name, bin: true) 208 | end 209 | 210 | it "should add a 'bin/' directory" do 211 | expect(@path).to have_directory('bin') 212 | end 213 | 214 | it "should add a bin/script-project file" do 215 | expect(@path).to have_file(@script) 216 | end 217 | 218 | it "should make the bin/script-project file executable" do 219 | expect(@path).to have_executable(@script) 220 | end 221 | end 222 | 223 | context "without bundler" do 224 | before(:all) do 225 | @name = 'bundled_project' 226 | 227 | generate!(@name, bundler: false) 228 | end 229 | 230 | it "should not add a Gemfile" do 231 | expect(@path).to_not have_file('Gemfile') 232 | end 233 | 234 | it "should not add 'bundler' as a development dependency" do 235 | expect(@gemspec).to_not have_development_dependency('bundler') 236 | end 237 | 238 | it "should not add 'Gemfile.lock' to the .gitignore file" do 239 | expect(gitignore).to_not include('/Gemfile.lock') 240 | end 241 | end 242 | 243 | context "rdoc" do 244 | before(:all) do 245 | @name = 'rdoc-project' 246 | 247 | generate!(@name, rdoc: true) 248 | end 249 | 250 | it "should disable the yard template" do 251 | expect(@generator.disabled_templates).to include(:yard) 252 | end 253 | 254 | it "should add 'rdoc' as a development dependency" do 255 | expect(@gemspec).to have_development_dependency('rdoc') 256 | end 257 | 258 | it "should default @markup to :markdown" do 259 | expect(@generator.instance_variable_get('@markup')).to eq(:markdown) 260 | end 261 | 262 | it "should add 'html/' to the .gitignore file" do 263 | expect(gitignore).to include('/html/') 264 | end 265 | 266 | it "should add a '.document' file" do 267 | expect(@path).to have_file('.document') 268 | end 269 | 270 | context ".document" do 271 | it "should include 'lib/**/*.rb'" do 272 | expect(document).to include('lib/**/*.rb') 273 | end 274 | 275 | it "should include 'README.rdoc'" do 276 | expect(document).to include('README.md') 277 | end 278 | 279 | it "should include 'ChangeLog.rdoc'" do 280 | expect(document).to include('ChangeLog.md') 281 | end 282 | 283 | it "should include 'LICENSE.txt'" do 284 | expect(document).to include('LICENSE.txt') 285 | end 286 | end 287 | end 288 | 289 | context "rdoc with rdoc markup" do 290 | before(:all) do 291 | @name = 'rdoc_rdoc-project' 292 | 293 | generate!(@name, rdoc: true, markup: 'rdoc') 294 | end 295 | 296 | it "should disable the yard template" do 297 | expect(@generator.disabled_templates).to include(:yard) 298 | end 299 | 300 | it "should add 'rdoc' as a development dependency" do 301 | expect(@gemspec).to have_development_dependency('rdoc') 302 | end 303 | 304 | it "should set @markup to :rdoc" do 305 | expect(@generator.instance_variable_get('@markup')).to eq(:rdoc) 306 | end 307 | 308 | it "should add 'html/' to the .gitignore file" do 309 | expect(gitignore).to include('/html/') 310 | end 311 | 312 | it "should add a '.document' file" do 313 | expect(@path).to have_file('.document') 314 | end 315 | 316 | context ".document" do 317 | it "should include 'lib/**/*.rb'" do 318 | expect(document).to include('lib/**/*.rb') 319 | end 320 | 321 | it "should include 'README.md'" do 322 | expect(document).to include('README.rdoc') 323 | end 324 | 325 | it "should include 'ChangeLog.md'" do 326 | expect(document).to include('ChangeLog.rdoc') 327 | end 328 | 329 | it "should include 'LICENSE.txt'" do 330 | expect(document).to include('LICENSE.txt') 331 | end 332 | end 333 | end 334 | 335 | context "yard" do 336 | before(:all) do 337 | @name = 'yard-project' 338 | 339 | generate!(@name, yard: true) 340 | end 341 | 342 | it "should disable the rdoc template" do 343 | expect(@generator.disabled_templates).to include(:rdoc) 344 | end 345 | 346 | it "should add a .yardopts file" do 347 | expect(@path).to have_file('.yardopts') 348 | end 349 | 350 | it "should add a '.document' file" do 351 | expect(@path).to have_file('.document') 352 | end 353 | 354 | it "should add 'yard' as a development dependency" do 355 | expect(@gemspec).to have_development_dependency('yard') 356 | end 357 | 358 | context ".document" do 359 | it "should not include 'lib/**/*.rb'" do 360 | expect(document).not_to include('lib/**/*.rb') 361 | end 362 | 363 | it "should include a '-' separator for non-code files" do 364 | expect(document).to include('-') 365 | end 366 | 367 | it "should not include 'README.md'" do 368 | expect(document).not_to include('README.md') 369 | end 370 | 371 | it "should include 'ChangeLog.md'" do 372 | expect(document).to include('ChangeLog.md') 373 | end 374 | 375 | it "should include 'LICENSE.txt'" do 376 | expect(document).to include('LICENSE.txt') 377 | end 378 | end 379 | end 380 | 381 | context "yard with rdoc markup" do 382 | before(:all) do 383 | @name = 'yard_rdoc-project' 384 | 385 | generate!(@name, yard: true, markup: 'rdoc') 386 | end 387 | 388 | it "should add a README.rdoc file" do 389 | expect(@path).to have_file('README.rdoc') 390 | end 391 | 392 | it "should add a ChangeLog.rdoc file" do 393 | expect(@path).to have_file('ChangeLog.rdoc') 394 | end 395 | 396 | it "should set --markup to rdoc in .yardopts" do 397 | expect(yard_opts).to include('--markup rdoc') 398 | end 399 | 400 | context ".document" do 401 | it "should include 'ChangeLog.rdoc'" do 402 | expect(document).to include('ChangeLog.rdoc') 403 | end 404 | end 405 | end 406 | 407 | context "yard with textile markup" do 408 | before(:all) do 409 | @name = 'yard_textile-project' 410 | 411 | generate!(@name, yard: true, markup: 'textile') 412 | end 413 | 414 | it "should add a README.tt file" do 415 | expect(@path).to have_file('README.tt') 416 | end 417 | 418 | it "should add a ChangeLog.tt file" do 419 | expect(@path).to have_file('ChangeLog.tt') 420 | end 421 | 422 | it "should set --markup to textile in .yardopts" do 423 | expect(yard_opts).to include('--markup textile') 424 | end 425 | 426 | context ".document" do 427 | it "should include 'ChangeLog.tt'" do 428 | expect(document).to include('ChangeLog.tt') 429 | end 430 | end 431 | end 432 | 433 | context "yard with bundler" do 434 | before(:all) do 435 | @name = 'bundled_yard_project' 436 | 437 | generate!(@name, bundler: true, yard: true) 438 | end 439 | 440 | it "should still add 'yard' as a development dependency" do 441 | expect(@gemspec).to have_development_dependency('yard') 442 | end 443 | end 444 | 445 | context "test_unit" do 446 | before(:all) do 447 | @name = 'test_unit_project' 448 | 449 | generate!(@name, test_unit: true) 450 | end 451 | 452 | it "should disable the minitest template" do 453 | expect(@generator.disabled_templates).to include(:minitest) 454 | end 455 | 456 | it "should disable the rspec template" do 457 | expect(@generator.disabled_templates).to include(:rspec) 458 | end 459 | 460 | it "should create the test/ directory" do 461 | expect(@path).to have_directory('test') 462 | end 463 | 464 | it "should create the test/helper.rb file" do 465 | expect(@path).to have_file('test','helper.rb') 466 | end 467 | 468 | it "should add a single test_*.rb file" do 469 | expect(@path).to have_file('test',"test_#{@name}.rb") 470 | end 471 | end 472 | 473 | context "minitest" do 474 | before(:all) do 475 | @name = 'minitest_project' 476 | 477 | generate!(@name, minitest: true) 478 | end 479 | 480 | it "should disable the test_unit template" do 481 | expect(@generator.disabled_templates).to include(:test_unit) 482 | end 483 | 484 | it "should disable the rspec template" do 485 | expect(@generator.disabled_templates).to include(:rspec) 486 | end 487 | 488 | it "should create the test/ directory" do 489 | expect(@path).to have_directory('test') 490 | end 491 | 492 | it "should create the test/helper.rb file" do 493 | expect(@path).to have_file('test','helper.rb') 494 | end 495 | 496 | it "should add a single test_*.rb file" do 497 | expect(@path).to have_file('test',"test_#{@name}.rb") 498 | end 499 | end 500 | 501 | context "rspec" do 502 | before(:all) do 503 | @name = 'rspec_project' 504 | 505 | generate!(@name, rspec: true) 506 | end 507 | 508 | it "should disable the test_unit template" do 509 | expect(@generator.disabled_templates).to include(:test_unit) 510 | end 511 | 512 | it "should disable the minitest template" do 513 | expect(@generator.disabled_templates).to include(:minitest) 514 | end 515 | 516 | it "should not create the test/ directory" do 517 | expect(@path).not_to have_directory('test') 518 | end 519 | 520 | it "should create the spec/ directory" do 521 | expect(@path).to have_directory('spec') 522 | end 523 | 524 | it "should add a spec_helper.rb file" do 525 | expect(@path).to have_file('spec','spec_helper.rb') 526 | end 527 | 528 | it "should add a single *_spec.rb file" do 529 | expect(@path).to have_file('spec','rspec_project_spec.rb') 530 | end 531 | 532 | it "should add a .rspec file" do 533 | expect(@path).to have_file('.rspec') 534 | end 535 | 536 | it "should add 'rspec' as a development dependency" do 537 | expect(@gemspec).to have_development_dependency('rspec') 538 | end 539 | end 540 | 541 | context "rspec with bundler" do 542 | before(:all) do 543 | @name = 'bundled_rspec_project' 544 | 545 | generate!(@name, bundler: true, rspec: true) 546 | end 547 | 548 | it "should add 'rspec' as a development dependency" do 549 | expect(@gemspec).to have_development_dependency('rspec') 550 | end 551 | end 552 | 553 | context "rubygems-tasks" do 554 | before(:all) do 555 | @name = 'rubygems_tasks_project' 556 | 557 | generate!(@name, rubygems_tasks: true) 558 | end 559 | 560 | it "should disable the bundler_tasks template" do 561 | expect(@generator.disabled_templates).to include(:bundler_tasks) 562 | end 563 | 564 | it "should add 'rubygems-tasks' as a development dependency" do 565 | expect(@gemspec).to have_development_dependency('rubygems-tasks') 566 | end 567 | end 568 | 569 | context "rubygems-tasks with bundler" do 570 | before(:all) do 571 | @name = 'bundled_ore_project' 572 | 573 | generate!(@name, bundler: true, rubygems_tasks: true) 574 | end 575 | 576 | it "should add 'rubygems-tasks' as a development dependency" do 577 | expect(@gemspec).to have_development_dependency('rubygems-tasks') 578 | end 579 | end 580 | 581 | context "bundler without rubygems-tasks" do 582 | before(:all) do 583 | @name = 'bundler_without_rubygems_tasks_project' 584 | 585 | generate!(@name, bundler: true, rubygems_tasks: false) 586 | end 587 | 588 | it "should add \"require 'bundler/gem_tasks'\" to the Rakefile" do 589 | expect(rakefile).to include("require 'bundler/gem_tasks'") 590 | end 591 | end 592 | 593 | context "gem_package_task" do 594 | before(:all) do 595 | @name = 'gem_package_task_project' 596 | 597 | generate!(@name, gem_package_task: true) 598 | end 599 | 600 | it "should disable the rubygems_tasks template" do 601 | expect(@generator.disabled_templates).to include(:rubygems_tasks) 602 | end 603 | 604 | it "should disable the bundler_tasks template" do 605 | expect(@generator.disabled_templates).to include(:bundler_tasks) 606 | end 607 | end 608 | 609 | after(:all) do 610 | cleanup! 611 | end 612 | end 613 | -------------------------------------------------------------------------------- /spec/helpers/generator.rb: -------------------------------------------------------------------------------- 1 | require 'tempfile' 2 | require 'pathname' 3 | require 'yaml' 4 | require 'fileutils' 5 | 6 | module Helpers 7 | module Generator 8 | ROOT = File.join(Dir.tmpdir,'ore') 9 | 10 | def generate!(path,options={}) 11 | path = File.join(ROOT,path) 12 | 13 | @generator = Ore::Generator.new( 14 | [path], 15 | options.merge(quiet: true) 16 | ) 17 | @generator.invoke_all 18 | 19 | @path = Pathname.new(path) 20 | @gemspec = Dir.chdir(@path) do 21 | Gem::Specification.load(@generator.generated_files['[name].gemspec']) 22 | end 23 | end 24 | 25 | def rakefile 26 | @path.join('Rakefile').read 27 | end 28 | 29 | def rspec_opts 30 | @path.join('.rspec').read 31 | end 32 | 33 | def yard_opts 34 | @path.join('.yardopts').read 35 | end 36 | 37 | def document 38 | unless @document 39 | @document = [] 40 | 41 | @path.join('.document').open do |file| 42 | file.each_line do |line| 43 | unless (line.empty? && line =~ /\s*\#/) 44 | @document << line.strip 45 | end 46 | end 47 | end 48 | end 49 | 50 | return @document 51 | end 52 | 53 | def gitignore 54 | unless @gitignore 55 | @gitignore = [] 56 | 57 | @path.join('.gitignore').open do |file| 58 | file.each_line do |line| 59 | unless (line.empty? && line =~ /\s*\#/) 60 | @gitignore << line.strip 61 | end 62 | end 63 | end 64 | end 65 | 66 | return @gitignore 67 | end 68 | 69 | def cleanup! 70 | FileUtils.rm_r(ROOT) 71 | end 72 | end 73 | end 74 | -------------------------------------------------------------------------------- /spec/helpers/matchers.rb: -------------------------------------------------------------------------------- 1 | require 'rspec' 2 | 3 | RSpec::Matchers.define :have_directory do |*names| 4 | match do |directory| 5 | directory.join(*names).directory? 6 | end 7 | end 8 | 9 | RSpec::Matchers.define :have_file do |*names| 10 | match do |directory| 11 | directory.join(*names).file? 12 | end 13 | end 14 | 15 | RSpec::Matchers.define :have_executable do |*names| 16 | match do |directory| 17 | path = directory.join(*names) 18 | 19 | path.file? && path.executable? 20 | end 21 | end 22 | 23 | RSpec::Matchers.define :have_dependency do |name| 24 | match do |gemspec| 25 | gemspec.dependencies.any? { |dep| dep.name == name } 26 | end 27 | end 28 | 29 | RSpec::Matchers.define :have_development_dependency do |name| 30 | match do |gemspec| 31 | gemspec.development_dependencies.any? { |dep| dep.name == name } 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /spec/naming_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'ore/naming' 3 | 4 | describe Naming do 5 | subject do 6 | obj = Object.new 7 | obj.extend Ore::Naming 8 | obj 9 | end 10 | 11 | describe "underscore" do 12 | it "should underscore CamelCase names" do 13 | expect(subject.underscore('FooBar')).to eq('foo_bar') 14 | end 15 | 16 | it "should not add leading underscores to Capitalized names" do 17 | expect(subject.underscore('Foo')).to eq('foo') 18 | end 19 | 20 | it "should not add tailing underscores to CamelCase names" do 21 | expect(subject.underscore('FooX')).to eq('foox') 22 | end 23 | 24 | it "should not add underscores when they already exist" do 25 | expect(subject.underscore('Foo_Bar')).to eq('foo_bar') 26 | end 27 | end 28 | 29 | it "should guess the module names from a project name" do 30 | expect(subject.modules_of('foo-bar')).to eq(['Foo', 'Bar']) 31 | end 32 | 33 | it "should filter out obvious names from the module names" do 34 | expect(subject.modules_of('ruby-foo')).to eq(['Foo']) 35 | end 36 | 37 | it "should recognize common acronyms in project names" do 38 | expect(subject.modules_of('ffi-bar')).to eq(['FFI', 'Bar']) 39 | end 40 | 41 | it "should guess the namespace from a project name" do 42 | expect(subject.namespace_of('foo-bar')).to eq('Foo::Bar') 43 | end 44 | 45 | it "should guess the namespace directories from a project name" do 46 | expect(subject.namespace_dirs_of('foo-bar')).to eq(['foo', 'bar']) 47 | end 48 | 49 | it "should filter out namespaces that are rarely used in directory names" do 50 | expect(subject.namespace_dirs_of('ruby-foo')).to eq(['foo']) 51 | end 52 | 53 | it "should guess the namespace directory from a project name" do 54 | expect(subject.namespace_path_of('foo-bar')).to eq('foo/bar') 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'rspec' 2 | require 'helpers/matchers' 3 | 4 | require 'ore/config' 5 | Ore::Config.disable! 6 | 7 | include Ore 8 | -------------------------------------------------------------------------------- /spec/template/helpers/markdown_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'ore/template/helpers/markdown' 3 | 4 | describe Ore::Template::Helpers::Markdown do 5 | subject do 6 | Object.new.extend described_class 7 | end 8 | 9 | describe "#link_to" do 10 | let(:text) { "foo bar" } 11 | let(:url) { "https://example.com/foo/bar" } 12 | 13 | it "should return a link with the text and url" do 14 | expect(subject.link_to(text,url)).to be == "[#{text}](#{url})" 15 | end 16 | end 17 | 18 | describe "#image" do 19 | let(:url) { "https://example.com/foo/bar.png" } 20 | 21 | context "with alt text" do 22 | let(:alt) { "foo bar" } 23 | 24 | it "should return a link with the alt text and url" do 25 | expect(subject.image(url,alt)).to be == "![#{alt}](#{url})" 26 | end 27 | end 28 | 29 | context "without alt text" do 30 | it "should return a link with the alt text and url" do 31 | expect(subject.image(url)).to be == "![](#{url})" 32 | end 33 | end 34 | end 35 | 36 | describe "#h1" do 37 | let(:title) { "Foo Bar" } 38 | 39 | it "should return a h1 header" do 40 | expect(subject.h1(title)).to be == "# #{title}" 41 | end 42 | end 43 | 44 | describe "#h2" do 45 | let(:title) { "Foo Bar" } 46 | 47 | it "should return a h2 header" do 48 | expect(subject.h2(title)).to be == "## #{title}" 49 | end 50 | end 51 | 52 | describe "#h3" do 53 | let(:title) { "Foo Bar" } 54 | 55 | it "should return a h3 header" do 56 | expect(subject.h3(title)).to be == "### #{title}" 57 | end 58 | end 59 | 60 | describe "#h4" do 61 | let(:title) { "Foo Bar" } 62 | 63 | it "should return a h4 header" do 64 | expect(subject.h4(title)).to be == "#### #{title}" 65 | end 66 | end 67 | 68 | describe "#pre" do 69 | let(:lines) do 70 | [ 71 | %{puts "hello"}, 72 | %{}, 73 | %{puts "world"} 74 | ] 75 | end 76 | let(:code) { lines.join($/) } 77 | 78 | it "should indent each line" do 79 | expect(subject.pre(code)).to be == lines.map { |line| 80 | " #{line}" 81 | }.join($/) 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /spec/template/helpers/rdoc_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'ore/template/helpers/rdoc' 3 | 4 | describe Ore::Template::Helpers::RDoc do 5 | subject do 6 | Object.new.extend described_class 7 | end 8 | 9 | describe "#link_to" do 10 | let(:text) { "foo bar" } 11 | let(:url) { "https://example.com/foo/bar" } 12 | 13 | it "should return a link with the text and url" do 14 | expect(subject.link_to(text,url)).to be == %{{#{text}}[#{url}]} 15 | end 16 | end 17 | 18 | describe "#image" do 19 | let(:url) { "https://example.com/foo/bar.png" } 20 | 21 | context "with alt text" do 22 | let(:alt) { "foo bar" } 23 | 24 | it "should return a link with the alt text and url" do 25 | expect(subject.image(url,alt)).to be == "{#{alt}}[rdoc-image:#{url}]" 26 | end 27 | end 28 | 29 | context "without alt text" do 30 | it "should return a link with the alt text and url" do 31 | expect(subject.image(url)).to be == "{}[rdoc-image:#{url}]" 32 | end 33 | end 34 | end 35 | 36 | describe "#h1" do 37 | let(:title) { "Foo Bar" } 38 | 39 | it "should return a h1 header" do 40 | expect(subject.h1(title)).to be == "= #{title}" 41 | end 42 | end 43 | 44 | describe "#h2" do 45 | let(:title) { "Foo Bar" } 46 | 47 | it "should return a h2 header" do 48 | expect(subject.h2(title)).to be == "== #{title}" 49 | end 50 | end 51 | 52 | describe "#h3" do 53 | let(:title) { "Foo Bar" } 54 | 55 | it "should return a h3 header" do 56 | expect(subject.h3(title)).to be == "=== #{title}" 57 | end 58 | end 59 | 60 | describe "#h4" do 61 | let(:title) { "Foo Bar" } 62 | 63 | it "should return a h4 header" do 64 | expect(subject.h4(title)).to be == "==== #{title}" 65 | end 66 | end 67 | 68 | describe "#pre" do 69 | let(:lines) do 70 | [ 71 | %{puts "hello"}, 72 | %{}, 73 | %{puts "world"} 74 | ] 75 | end 76 | let(:code) { lines.join($/) } 77 | 78 | it "should indent each line" do 79 | expect(subject.pre(code)).to be == lines.map { |line| 80 | " #{line}" 81 | }.join($/) 82 | end 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /spec/template/helpers/textile_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'ore/template/helpers/textile' 3 | 4 | describe Ore::Template::Helpers::Textile do 5 | subject do 6 | Object.new.extend described_class 7 | end 8 | 9 | describe "#link_to" do 10 | let(:text) { "foo bar" } 11 | let(:url) { "https://example.com/foo/bar" } 12 | 13 | it "should return a link with the text and url" do 14 | expect(subject.link_to(text,url)).to be == %{"#{text}":#{url}} 15 | end 16 | end 17 | 18 | describe "#image" do 19 | let(:url) { "https://example.com/foo/bar.png" } 20 | 21 | context "with alt text" do 22 | let(:alt) { "foo bar" } 23 | 24 | it "should return a link with the alt text and url" do 25 | expect(subject.image(url,alt)).to be == "!#{url}(#{alt})!" 26 | end 27 | end 28 | 29 | context "without alt text" do 30 | it "should return a link with the alt text and url" do 31 | expect(subject.image(url)).to be == "!#{url}!" 32 | end 33 | end 34 | end 35 | 36 | describe "#h1" do 37 | let(:title) { "Foo Bar" } 38 | 39 | it "should return a h1 header" do 40 | expect(subject.h1(title)).to be == "h1. #{title}" 41 | end 42 | end 43 | 44 | describe "#h2" do 45 | let(:title) { "Foo Bar" } 46 | 47 | it "should return a h2 header" do 48 | expect(subject.h2(title)).to be == "h2. #{title}" 49 | end 50 | end 51 | 52 | describe "#h3" do 53 | let(:title) { "Foo Bar" } 54 | 55 | it "should return a h3 header" do 56 | expect(subject.h3(title)).to be == "h3. #{title}" 57 | end 58 | end 59 | 60 | describe "#h4" do 61 | let(:title) { "Foo Bar" } 62 | 63 | it "should return a h4 header" do 64 | expect(subject.h4(title)).to be == "h4. #{title}" 65 | end 66 | end 67 | 68 | describe "#pre" do 69 | context "with a single line" do 70 | let(:code) { %{puts "hello world"} } 71 | 72 | it "should prepend bc." do 73 | expect(subject.pre(code)).to be == "bc. #{code}" 74 | end 75 | end 76 | 77 | context "with multiple lines" do 78 | let(:lines) do 79 | [ 80 | %{puts "hello"}, 81 | %{}, 82 | %{puts "world"} 83 | ] 84 | end 85 | let(:code) { lines.join($/) } 86 | 87 | it "should prepend bc.." do 88 | expect(subject.pre(code)).to be == "bc.. #{code}" 89 | end 90 | end 91 | end 92 | end 93 | --------------------------------------------------------------------------------