latex-project-template 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -54,13 +54,13 @@ To list templates in ~/.latex\_project\_template, we type
54
54
  ## Special notations of template file names
55
55
 
56
56
  \_\_IMPORT\_\_
57
- :In \_\_IMPORT\_\_ we write list of files to import from other template.
57
+ : In \_\_IMPORT\_\_ we write list of files to import from other template.
58
58
  \_\_PROJECT\_\_
59
- :Replace \_\_PROJECT\_\_ by name of project.
59
+ : Replace \_\_PROJECT\_\_ by name of project.
60
60
  \_\_DOT\_\_
61
- :Replace \_\_DOT\_\_ by '.'.
61
+ : Replace \_\_DOT\_\_ by '.'.
62
62
  \_\_IGNORE\_\_
63
- :Files including \_\_IGNORE\_\_ are ignored.
63
+ : Files including \_\_IGNORE\_\_ are ignored.
64
64
 
65
65
  ## Contributing to latex-project-template
66
66
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -10,7 +10,7 @@ Usage: #{File.basename(__FILE__)} project [template]
10
10
 
11
11
  HELP
12
12
 
13
- Version = '0.0.1'
13
+ Version = '0.0.2'
14
14
 
15
15
  options = {
16
16
  :mode => :create
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{latex-project-template}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Takayuki YAMAGUCHI"]
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
35
35
  "spec/task_spec.rb",
36
36
  "template/default/Rakefile.erb",
37
37
  "template/default/__DOT__gitignore",
38
- "template/default/__PROJECT__.tex",
38
+ "template/default/__PROJECT__.tex.erb",
39
39
  "template/japanese/__IMPORT__",
40
40
  "template/japanese/latexmkrc"
41
41
  ]
@@ -11,47 +11,63 @@ class LaTeXProjectTemplate
11
11
  end
12
12
 
13
13
  class Configuration
14
+ TEMPLATE_DIRECTORY = 'template'
15
+ VARIABLE_DIRECTORY = 'variable'
16
+ DEFAULT_PROFILE_YAML = { :name => "Your Name" }
17
+
14
18
  def self.create_new_config(home_path = nil)
15
19
  config = LPTConfig.new(DEFAULT_CONFIG, :home => home_path)
16
20
  dir = config.directory
17
- Dir.glob("#{File.expand_path(File.join(File.dirname(__FILE__), '../template/'))}/*").each do |d|
18
- FileUtils.cp_r(d, dir)
21
+ FileUtils.cp_r("#{File.expand_path(File.join(File.dirname(__FILE__), '../template/'))}", dir)
22
+ vars_dir = File.join(dir, VARIABLE_DIRECTORY)
23
+ FileUtils.mkdir_p(vars_dir)
24
+ open(File.join(vars_dir, 'profile.yaml'), 'w') do |f|
25
+ f.print DEFAULT_PROFILE_YAML.to_yaml
19
26
  end
20
27
  end
21
28
 
22
29
  def initialize(home_path)
23
- @config = UserConfig.new(DEFAULT_CONFIG, :home => home_path)
30
+ @user_config = LPTConfig.new(DEFAULT_CONFIG, :home => home_path)
24
31
  end
25
32
 
26
33
  def config_directory
27
- @config.directory
34
+ @user_config.directory
28
35
  end
29
36
 
30
37
  def list_template
31
- @config.list_in_directory('.')
38
+ @user_config.list_in_directory(TEMPLATE_DIRECTORY)
39
+ end
40
+
41
+ def user_config_template_path(template_name)
42
+ File.join(TEMPLATE_DIRECTORY, template_name)
32
43
  end
44
+ private :user_config_template_path
33
45
 
34
46
  def template_exist?(template)
35
- if path = @config.exist?(template)
47
+ if path = @user_config.exist?(user_config_template_path(template))
36
48
  return LaTeXProjectTemplate::Directory.new(path)
37
49
  end
38
50
  false
39
51
  end
40
52
 
41
- def template_file(template, name)
42
- unless path = @config.template_exist?(File.join(template, name))
43
- path = @config.template_exist?(File.join('default', name))
44
- end
45
- path
46
- end
47
-
48
53
  def delete_template(template)
49
54
  if String === template && template.size > 0
50
- @config.delete(template)
55
+ @user_config.delete(user_config_template_path(template))
51
56
  else
52
57
  raise ArgumentError, "Invalid template name to delete: #{template.inspect}"
53
58
  end
54
59
  end
60
+
61
+ def user_variables
62
+ vars = {}
63
+ if dir = @user_config.exist?('variable')
64
+ Dir.glob(File.join(dir, '*.yaml')).each do |yaml_path|
65
+ key = File.basename(yaml_path).sub(/\.yaml$/, '').intern
66
+ vars[key] = YAML.load_file(yaml_path)
67
+ end
68
+ end
69
+ vars
70
+ end
55
71
  end
56
72
 
57
73
  class Directory
@@ -146,8 +162,11 @@ class LaTeXProjectTemplate
146
162
  class ErbObject
147
163
  attr_reader :project_name
148
164
 
149
- def initialize(project_name)
165
+ def initialize(project_name, variables)
150
166
  @project_name = project_name
167
+ variables.each do |key, val|
168
+ instance_variable_set("@#{key}", val)
169
+ end
151
170
  end
152
171
  end
153
172
 
@@ -164,7 +183,7 @@ class LaTeXProjectTemplate
164
183
  end
165
184
 
166
185
  def create_files
167
- erb_obj = LaTeXProjectTemplate::ErbObject.new(@project_name)
186
+ erb_obj = LaTeXProjectTemplate::ErbObject.new(@project_name, @config.user_variables)
168
187
  created_files = @template.copy_to_directory(@target_dir, erb_obj)
169
188
  @template.files_to_import.each do |name, files|
170
189
  if template_to_import = @config.template_exist?(name)
@@ -180,7 +199,7 @@ class LaTeXProjectTemplate
180
199
  git = Git.init(@target_dir)
181
200
  files = create_files
182
201
  git.add
183
- git.commit("Copy template '#{@template.name}'.")
202
+ git.commit("Copy template: #{@template.name}.")
184
203
  if io = opts[:io]
185
204
  files.map! do |path|
186
205
  path.sub!(@target_dir, '')
@@ -33,6 +33,12 @@ describe LaTeXProjectTemplate::Configuration do
33
33
  subject.template_exist?('not_exist').should be_false
34
34
  end
35
35
 
36
+ it "should return profile" do
37
+ vars = subject.user_variables
38
+ vars.should be_an_instance_of Hash
39
+ vars[:profile][:name].should == "Your Name"
40
+ end
41
+
36
42
  after(:all) do
37
43
  FileUtils.rm_r(@home_directory)
38
44
  end
@@ -1,6 +1,11 @@
1
1
  \documentclass[a4paper]{article}
2
2
  \usepackage{amsmath, amsfonts, amsthm}
3
3
 
4
+ \author{<%= @profile[:name] %>}
5
+ \date{}
6
+
4
7
  \begin{document}
5
8
 
9
+ \section{}
10
+
6
11
  \end{document}
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: latex-project-template
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Takayuki YAMAGUCHI
@@ -160,7 +160,7 @@ files:
160
160
  - spec/task_spec.rb
161
161
  - template/default/Rakefile.erb
162
162
  - template/default/__DOT__gitignore
163
- - template/default/__PROJECT__.tex
163
+ - template/default/__PROJECT__.tex.erb
164
164
  - template/japanese/__IMPORT__
165
165
  - template/japanese/latexmkrc
166
166
  has_rdoc: true
@@ -177,7 +177,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
- hash: 729348687421723767
180
+ hash: -1327005119075032685
181
181
  segments:
182
182
  - 0
183
183
  version: "0"