Skip to content

Commit

Permalink
Rewrote external file (theme) funtionality - old style now broken!
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelsey Judson committed Sep 23, 2012
1 parent 98df982 commit 4613f52
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
20120924 - 0.1.9
* Old theme functionality is broken. I felt there was no choice but to remove it in favour of a more flexible alternative. The old method (matching against .*_theme$) meant that no option could end in "_theme". This obviously caused issues when I tried to set "gtk3_theme: Adwaita". This is just a result of poor planning. The new method is to specify a file (rather than "theme") in a template as "{{file:the_option}}", then simply use "the_option:" in dotfile.conf. The files matched will be searched for under ~.dotfile/files (or Dotfile::FILES).
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ Setting Up the Environment
| | +-dotfile_two
+-scripts/
| +-script.sh # As specified in dotfile.conf (execute_before/after)
| +-script.rb #
+-themes/
| +-script.rb # "
+-files/
+-dotfile.conf
+-groups.conf

Expand All @@ -72,8 +72,8 @@ Dotfiles are stored as one of two types based on their filename. Files ending in

All dotfiles (both templates and static files) are found in `~/.dotfile/dotfiles`. Every dotfile is part of a "group" which is specified in `~/.dotfile/groups.conf`. Any dotfile within a group that is listed under `groups` in `~/.dotfile/dotfile.conf` will be copied over during a `dotfile --update`. See the `default/groups.conf` file for more information on how this file works.

### Themes
Where there is a `_theme` suffix to an option in `~/.dotfile/dotfile.conf`, it refers to the corresponding file found in `~/.dotfile/themes`. This functionality will likely be superceded by Chromatic (more information below).
### External Files
Where there is a `file:` prefix to an option in a template file, it refers to the corresponding file found in `~/.dotfile/files`. The `file:` prefix to the option should be left off in `~/.dotfile/dotfile.conf`. For example, a theme file specified `{{file:x_theme}}` in a template file may be written as `x_theme: themes/my_theme` in `~/.dotfile/dotfile.conf`. This file will then be found under `~/.dotfile/files/themes/my_theme`.

### Optional Scripts
Files listed under `execute_before` or `execute_after` in `~/.dotfile/dotfile.conf` refer to similarly named scripts in the `~/.dotfile/scripts` directory. These files are executed at the beginning or end of the installation process respectively. Either ruby or shell sripts are acceptable. Filenames for ruby scripts should end in the `.rb` suffix.
Expand Down
2 changes: 1 addition & 1 deletion dotfile.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'dotfile/version'
files = Dir['lib/**/*'] +
Dir['default/*'] +
Dir['bin/*'] +
%w{ LICENSE README.md dotfile.gemspec }
%w{ CHANGELOG LICENSE README.md dotfile.gemspec }

Gem::Specification.new do |s|

Expand Down
2 changes: 1 addition & 1 deletion lib/dotfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Dotfile
SETTINGS = "#{DIRECTORY}/dotfile.conf"
GROUPS = "#{DIRECTORY}/groups.conf"
DOTFILES = "#{DIRECTORY}/dotfiles"
THEMES = "#{DIRECTORY}/themes"
FILES = "#{DIRECTORY}/files"
SCRIPTS = "#{DIRECTORY}/scripts"

class Error < StandardError
Expand Down
11 changes: 7 additions & 4 deletions lib/dotfile/dotfile_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def parse
lines = File.readlines(@source)
# Substitute any placeholders for equivalent key/value in config file.
lines.map! do |l|
l.gsub(/\{\{[\w-]+\}\}/) do |option|
l.gsub(/\{\{[\w:-]+\}\}/) do |option|
option.gsub!(/\{\{|\}\}/, "")
option_value(option)
end
Expand All @@ -25,12 +25,15 @@ def parse
end

def option_value(option)
value_is_file = option =~ /^file.*/
option.sub!('file:', '')

error_message = "Option #{option} for #{name} not found in dotfile.conf."
raise(Dotfile::Error, error_message) if @settings[option] == nil

# If option is a theme, it must be sourced from an external file.
if option =~ /.*_theme/
File.readlines("#{Dotfile::THEMES}/#{@settings[option]}").join
# If option is a file, it must be sourced.
if value_is_file
File.readlines("#{Dotfile::FILES}/#{@settings[option]}").join
else
@settings[option]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dotfile/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Dotfile

VERSION = '0.1.8'
VERSION = '0.1.9'

end

0 comments on commit 4613f52

Please sign in to comment.