lib/rabbit/command/rabbit-theme.rb in rabbit-2.0.1 vs lib/rabbit/command/rabbit-theme.rb in rabbit-2.0.2
- old
+ new
@@ -16,11 +16,13 @@
require "yaml"
require "rabbit/console"
require "rabbit/author-configuration"
+require "rabbit/theme-configuration"
require "rabbit/path-manipulatable"
+require "rabbit/source-generator"
module Rabbit
module Command
class RabbitTheme
include GetText
@@ -31,12 +33,11 @@
new.run(arguments)
end
end
def initialize
- @config_yaml_path = "config.yaml"
- @id = nil
+ @theme_conf = nil
@author_conf = nil
@logger = nil
end
def run(arguments)
@@ -58,10 +59,12 @@
def parse_command_line_arguments(arguments)
Rabbit::Console.parse!(ARGV) do |parser, options|
@logger = options.default_logger
@author_conf = AuthorConfiguration.new(@logger)
@author_conf.load
+ @theme_conf = ThemeConfiguration.new(@logger)
+ @theme_conf.author = @author_conf
format = _("Usage: %s new [options]\n" \
" e.g.: %s new \\\n" \
" --id rubykaigi2012 \\\n" \
" --name \"Kouhei Sutou\" \\\n" \
@@ -77,11 +80,11 @@
parser.on("--id=ID",
_("Theme ID"),
_("(e.g.: %s)") % "--id=rubykaigi2012",
_("(must)")) do |id|
- @id = id
+ @theme_conf.id = id
end
parser.separator(_("Your information"))
messages = [
@@ -147,142 +150,112 @@
@validation_errors << message
end
end
def validate_id
- if @id.nil?
+ if @theme_conf.id.nil?
@validation_errors << (_("%s is missing") % "--id")
end
end
def generate
generate_directory
generate_data_directory
- generate_config_yaml
+ generate_dot_gitignore
+ generate_theme_configuration
generate_readme
generate_rakefile
generate_property_rb
generate_theme_rb
end
def generate_directory
- create_directory(@id)
+ create_directory(@theme_conf.id)
end
def generate_data_directory
- create_directory(File.join(@id, "data"))
+ create_directory(File.join(@theme_conf.id, "data"))
end
- def generate_config_yaml
- create_file(@config_yaml_path) do |config_yaml|
- config = {
- "id" => @id,
- "name" => @author_conf.name,
- "email" => @author_conf.email,
- "rubygems_user" => @author_conf.rubygems_user,
- }
- config_yaml.puts(config.to_yaml)
+ def generate_dot_gitignore
+ create_file(".gitignore") do |dot_gitignore|
+ dot_gitignore.puts(<<-EOD)
+/.tmp/
+/pkg/
+/pdf/
+EOD
end
end
+ def generate_theme_configuration
+ @theme_conf.save(@theme_conf.id)
+ end
+
def generate_readme
create_file("README.#{readme_extension}") do |readme|
readme.puts(readme_content)
end
end
def readme_content
markup_language = @author_conf.markup_language || :rd
- syntax = markup_syntax(markup_language)
+ generator = Rabbit::SourceGenerator.find(markup_language)
content = ""
- content << (syntax[:heading1] % {:title => _("TODO: THEME TITLE")})
+ content << generator.heading(1, _("TODO: THEME TITLE"))
content << "\n\n"
content << _("TODO: THEME DESCRIPTION")
content << "\n\n"
- content << (syntax[:heading2] % {:title => _("For author")})
+ content << generator.heading(2, _("For author"))
content << "\n\n"
- content << (syntax[:heading3] % {:title => _("Show")})
+ content << generator.heading(3, _("Show"))
content << "\n\n"
- content << (syntax[:preformatted_line] % {:content => "rake"})
+ content << generator.preformatted_line("rake")
content << "\n\n"
- content << (syntax[:heading3] % {:title => _("Publish")})
+ content << generator.heading(3, _("Publish"))
content << "\n\n"
- content << (syntax[:preformatted_line] % {:content => "rake publish"})
+ content << generator.preformatted_line("rake publish")
content << "\n\n"
- content << (syntax[:heading2] % {:title => _("For users")})
+ content << generator.heading(2, _("For users"))
content << "\n\n"
- content << (syntax[:heading3] % {:title => _("Install")})
+ content << generator.heading(3, _("Install"))
content << "\n\n"
- install_command = "gem install #{gem_name}"
- content << (syntax[:preformatted_line] % {:content => install_command})
+ install_command = "gem install #{@theme_conf.gem_name}"
+ content << generator.preformatted_line(install_command)
content << "\n\n"
- content << (syntax[:heading3] % {:title => _("Show")})
+ content << generator.heading(3, _("Show"))
content << "\n\n"
theme_benchmark_gem = _("rabbit-theme-benchmark-en.gem")
- show_command = "rabbit -t #{gem_name} #{theme_benchmark_gem}"
- content << (syntax[:preformatted_line] % {:content => show_command})
+ show_command = "rabbit -t #{@theme_conf.gem_name} #{theme_benchmark_gem}"
+ content << generator.preformatted_line(show_command)
content << "\n\n"
end
def generate_rakefile
create_file("Rakefile") do |rakefile|
rakefile.puts(<<-EOR)
-require "time"
-require "yaml"
require "rabbit/task/theme"
-config = YAML.load(File.read("#{@config_yaml_path}"))
+# Edit ./config.yaml to customize meta data
-theme_id = config["id"]
-
-version = "1.0.0"
-
-name = config["name"]
-email = config["email"]
-rubygems_user = config["rubygems_user"]
-
-readme = File.read(Dir.glob("README*")[0])
-
-readme_blocks = readme.split(/(?:\\r?\\n){2,}/)
-summary = (readme_blocks[0] || "TODO").gsub(/\\A(?:[=*!]+|h\\d\\.)\s*/, "")
-description = readme_blocks[1] || "TODO"
-
-specification = Gem::Specification.new do |spec|
- prefix = "#{gem_name_prefix}"
- spec.name = "\#{prefix}-\#{theme_id}"
- spec.version = version
- spec.homepage = "http://theme.rabbit-shockers.org/\#{theme_id}/"
- spec.authors = [name]
- spec.email = [email]
- spec.summary = summary
- spec.description = description
- spec.licenses = [] # ["CC BY-SA 3.0"]
-
- spec.files = ["#{@config_yaml_path}", "Rakefile"]
- spec.files += Dir.glob("{theme.rb,COPYING,GPL,README*}")
- spec.files += Dir.glob("data/**/*.{svg,png,jpg,jpeg,gif,eps,pdf}")
- spec.files += Dir.glob("locale/**/*.mo")
- spec.files += Dir.glob("po/*/*.po")
-
- spec.add_runtime_dependency("rabbit")
+Rabbit::Task::Theme.new do |task|
+ # task.spec.licenses = ["CC BY-SA 3.0"]
+ # task.spec.files += Dir.glob("doc/**/*.*")
+ # task.spec.files -= Dir.glob("private/**/*.*")
+ # task.spec.add_runtime_dependency("DEPENDED THEME")
end
-
-Rabbit::Task::Theme.new(specification) do |task|
- task.rubygems_user = rubygems_user
-end
EOR
end
end
def generate_property_rb
create_file("property.rb") do |property_rb|
property_rb.puts(<<-EOP)
@category = N_("#{category}")
-@title = N_("#{@id}")
+@title = N_("#{@theme_conf.id}")
# @abstract = N_("TODO")
# @description = N_("TODO")
EOP
end
end
@@ -295,11 +268,11 @@
EOT
end
end
def image_theme?
- @id.end_with?("-images")
+ @theme_conf.id.end_with?("-images")
end
def category
if image_theme?
"Image"
@@ -319,63 +292,11 @@
else
"rd"
end
end
- def markup_syntax(markup_language)
- case markup_language
- when :rd
- {
- :heading1 => "= %{title}",
- :heading2 => "== %{title}",
- :heading3 => "=== %{title}",
- :definition_list_item => ": %{item}\n %{description}",
- :unorderd_list_item => " * %{item}",
- :image =>
- " # image\n" +
- " # src = %{src}\n" +
- " # relative_height = %{relative_height}",
- :preformatted_line => " %{content}",
- :comment => "# %{content}",
- }
- when :hiki
- {
- :heading1 => "! %{title}",
- :heading2 => "!! %{title}",
- :heading3 => "!!! %{title}",
- :definition_list_item => ":%{item}:%{description}",
- :unorderd_list_item => "* %{item}",
- :image =>
- "{{image(\"%{src}\",\n" +
- " {\n" +
- " :relative_height => %{relative_height},\n" +
- " })}}",
- :preformatted_line => " %{content}",
- :comment => "// %{content}",
- }
- when :markdown
- {
- :heading1 => "# %{title}",
- :heading2 => "## %{title}",
- :heading3 => "### %{title}",
- :definition_list_item => "%{item}\n %{description}",
- :unorderd_list_item => "* %{item}",
- :image =>
- "{:relative_height='%{relative_height}'}",
- :preformatted_line => " %{content}",
- :comment => "",
- }
- else
- nil
- end
- end
-
- def gem_name
- "#{gem_name_prefix}-#{@id}"
- end
-
- def gem_name_prefix
- "rabbit-theme"
+ def create_file(path, &block)
+ super(File.join(@theme_conf.id, path), &block)
end
end
end
end