Skip to content

Commit

Permalink
Merge pull request #9 from kiefernwald/list
Browse files Browse the repository at this point in the history
Add list call
  • Loading branch information
tacconthommy committed Nov 27, 2018
2 parents 016e09b + e94ac81 commit 508a08b
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 114 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/tmp/
/modules/*
.idea
Gemfile.lock

# rspec failure tracking
.rspec_status
93 changes: 0 additions & 93 deletions Gemfile.lock

This file was deleted.

27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,34 @@ Platte is a small command line tool that combines static HTML pages from modules

## Installation

Platte requires ruby. To install, run:
Platte requires a ruby environment with version 2.3 or higher. To install, run:

`bundle install`
`gem install platte`

## Usage

The main script to be used is `platte` in the main folder. It has a single command, called `combine` which lets you combine a main-module (usually the surrounding HTML structure with placeholders for resources) and other modules.
After the gem installation, `platte` is available in command line. It lets you combine a static HTML file from a given set of modules. Modules are folders with some configuation files and code in it and sit in the `modules` subfolder of the tool. They come in two flavours:

Example call:
1. Main modules names, ending with `.main` – usually they hold the surrounding HTML structure with placeholders for resources
2. Other modules names end with `.module` – they are building blocks you can freely combine together as the body of a main module

You can use the `platte` command as follows:

### list

`platte list`

This call shows you which modules are available in your system.

`platte combine html5 header content`
### combine

`platte combine <TARGET FILE> <MAIN MODULE> <MODULE 1> ... <MODULE N>`

This lets you combine a single main-module with any number of other modules to a given target file.

Example call:

All modules you define must be placed in the `modules` folder. Main modules names end with `.main`, other modules names end with `.module`.
`platte combine some/output/file.html html5 header content`

## Module structure

Expand Down
7 changes: 7 additions & 0 deletions bin/platte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby
# -*- mode: ruby -*-
# frozen_string_literal: true

require './lib/platte'

Platte.start
26 changes: 21 additions & 5 deletions platte → lib/platte.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'thor'
Expand All @@ -22,6 +21,14 @@ def combine file, main, *modules
output_error e, "Could not construct #{file}!"
end

desc 'list', 'list all available modules.'
def list
puts '🏢 The following main modules are available:'.green
get_modules_from_folder('modules', extension: 'main').each(&method(:output_single_module))
puts "\n📦 The following modules are available:".green
get_modules_from_folder('modules').each(&method(:output_single_module))
end

private

def combine_and_save file, main_module, platte_modules
Expand All @@ -41,8 +48,19 @@ def output_error error, message

def output_module_info file, main_module, platte_modules
puts "#{'🏗 Constructing'.green} #{file.yellow} #{'from the following modules:'.green}"
puts " * #{main_module.name} (main module) – #{main_module.description}".blue
platte_modules.each { |mod| puts " * #{mod.name}#{mod.description}".blue }
output_single_module(main_module, is_main: true)
platte_modules.each(&method(:output_single_module))
end

def output_single_module module_object, is_main: false
module_name = is_main ? "#{module_object.name} (main module)" : module_object.name
puts " * #{module_name}#{module_object.description}".blue
end

def get_modules_from_folder folder, extension: 'module'
loader = PlatteModuleLoader.new
Dir.glob("*.#{extension}", base: folder)
.map { |mod| loader.create_from_folder "modules/#{mod}" }
end

def get_modules main, modules
Expand All @@ -66,5 +84,3 @@ def copy_assets destination, main, modules
modules&.each { |mod| FileUtils.copy_entry "#{mod.directory}/assets", "#{destination}/assets" }
end
end

Platte.start
2 changes: 1 addition & 1 deletion lib/platte/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Platte
VERSION = '0.1.0'
VERSION = '0.1.1'
end
2 changes: 1 addition & 1 deletion lib/platte_module.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'json'
require './lib/exception/platte_module_creation_exception'
require_relative 'exception/platte_module_creation_exception'

# A single module
class PlatteModule
Expand Down
15 changes: 7 additions & 8 deletions platte.gemspec
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# frozen_string_literal: true

require './lib/platte/version'
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
require 'platte/version'

Gem::Specification.new do |s|
s.name = 'platte'
s.version = Platte::VERSION
s.authors = ['Thomas Bretzke']
s.homepage = 'https://github.com/kiefernwald/platte'
s.summary = 'A static generator tool for static HTML pages combined from modules.'
s.license = 'ISC'
s.license = 'MIT'

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless s.respond_to?(:metadata)
s.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"

s.files = Dir['.gemspec', 'lib/**/*.rb', 'license.txt', 'readme.md']
s.executables = %w[platte]
s.require_paths = %w[lib]
s.files = Dir['.gemspec', 'lib/**/*.rb', 'bin/*', 'license.txt', 'readme.md']

s.required_ruby_version = '~> 2.3'
s.add_development_dependency 'bundler', '~> 1.16'
Expand Down

0 comments on commit 508a08b

Please sign in to comment.