Module: Juli::Util
- Included in:
- Command::RecentUpdate, Command::Sitemap, Command::Tag, Macro::Base, Visitor::Html, Visitor::Html::Helper::AbstractHelper, Visitor::Html::HtmlLine, Visitor::LineTree, Visitor::Tree
- Defined in:
- lib/juli/util.rb,
lib/juli/util/juli_i18n.rb
Defined Under Namespace
Classes: Config, JuliI18n, Repo
Class Method Summary collapse
-
.conf ⇒ Object
return REPO/config hash.
-
.find_template(template, t_opt = nil) ⇒ Object
find erb template under the following order:.
-
.in_filename(out_filename) ⇒ Object
INPUTS out_filename:: relative path under OUTPUT_TOP.
-
.juli_repo(path = '.') ⇒ Object
fullpath of juli-repository.
-
.mkdir(path) ⇒ Object
mkdir for out_file if necessary.
-
.out_filename(in_filename, o_opt = nil) ⇒ Object
INPUTS in_filename:: relative path under repository o_opt:: output path which -o command-line option specifies.
- .str_limit(str) ⇒ Object
-
.str_trim(str) ⇒ Object
trim string just for printing purpose here.
-
.to_wikiname(in_filename) ⇒ Object
input filename to wikiname.
-
.underscore(str) ⇒ Object
Similar to Rails underscore() method.
- .usage ⇒ Object
-
.visitor(str) ⇒ Object
Visitor::#str constantize.
- .visitor_list ⇒ Object
Instance Method Summary collapse
Class Method Details
.conf ⇒ Object
return REPO/config hash
156 157 158 |
# File 'lib/juli/util.rb', line 156 def conf Config.instance.conf end |
.find_template(template, t_opt = nil) ⇒ Object
find erb template under the following order:
if t_opt (‘-t’ command-line option arg) is specified:
1st) template_path in absolute or relative from current dir, or
2nd) -t template_path in JULI_REPO/.juli/, or
3rd) -t template_path in lib/juli/template/
otherwise, error
else:
4th) {template} in JULI_REPO/.juli/, or
5th) {template} in lib/juli/template.
otherwise, error
Where, template means conf
INPUTS
- template
-
template name
- t_opt
-
template name which -t command-line option specifies
231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/juli/util.rb', line 231 def find_template(template, t_opt = nil) if t_opt if File.exist?(t_opt) t_opt else find_template_sub(t_opt) end else find_template_sub(template) end end |
.in_filename(out_filename) ⇒ Object
INPUTS
- out_filename
-
relative path under OUTPUT_TOP
RETURN
relative path of in-filename, but **no extention**.
EXAMPLE
diary/2010/12/31.shtml -> 31
208 209 210 211 |
# File 'lib/juli/util.rb', line 208 def in_filename(out_filename) File.join(File.dirname(out_filename), File.basename(out_filename).gsub(/\.[^\.]*$/,'')) end |
.juli_repo(path = '.') ⇒ Object
fullpath of juli-repository
it is enough to have one value in whole juli modules so SINGLETON-pattern is used.
123 124 125 126 |
# File 'lib/juli/util.rb', line 123 def juli_repo(path='.') $_repo ||= Repo.new(path) $_repo.juli_repo end |
.mkdir(path) ⇒ Object
mkdir for out_file if necessary
162 163 164 165 166 167 |
# File 'lib/juli/util.rb', line 162 def mkdir(path) dir = File.dirname(path) if !File.directory?(dir) FileUtils.mkdir_p(dir) end end |
.out_filename(in_filename, o_opt = nil) ⇒ Object
INPUTS
- in_filename
-
relative path under repository
- o_opt
-
output path which -o command-line option specifies
RETURN
full path of out filename. if o_opt is specified, it is used.
EXAMPLE
diary/2010/12/31.txt -> OUTPUT_TOP/diary/2010/12/31.shtml
193 194 195 196 197 |
# File 'lib/juli/util.rb', line 193 def out_filename(in_filename, o_opt = nil) o_opt || File.join(conf['output_top'], to_wikiname(in_filename) + conf['ext']) end |
.str_limit(str) ⇒ Object
80 81 82 |
# File 'lib/juli/util.rb', line 80 def str_limit(str) str.size > 45 ? str[0..45] + '...' : str end |
.str_trim(str) ⇒ Object
trim string just for printing purpose here
86 87 88 |
# File 'lib/juli/util.rb', line 86 def str_trim(str) str_limit(str.gsub(/\n/, '\n').gsub(/\r/, '\r')) end |
.to_wikiname(in_filename) ⇒ Object
input filename to wikiname
INPUTS
- in_filename
-
juli repo file path
EXAMPLE
diary/2010/12/31.txt -> diary/2010/12/31
177 178 179 |
# File 'lib/juli/util.rb', line 177 def to_wikiname(in_filename) in_filename.gsub(/\.[^\.]*$/,'') end |
.underscore(str) ⇒ Object
Similar to Rails underscore() method.
Example: ‘A::B::HelperMethod’ -> ‘helper_method’
94 95 96 97 98 99 100 |
# File 'lib/juli/util.rb', line 94 def underscore(str) str.gsub(/.*::/,''). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |
.usage ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/juli/util.rb', line 34 def usage <<EOM USAGE: juli [general_options] COMMAND [command_options] [files] general_options: --help --version COMMAND (default = gen): init initialize current directory as juli-repo gen generate outputs from files under juli-repo This is the default juli command. sitemap generate sitemap to JULI_REPO/sitemap.shtml recent_update generate reent updates to JULI_REPO/recent_update.shtml NOTE: file extention '.shtml' above is the default. you can change it by 'init' command -e option (see below), or by modifying JULI_REPO/.juli/config 'ext' entry later anytime. tag generate tag-list page. see tag(macro) manual. command_options for: init: -o output_top default='../html/' -t template set the template at config (default='default.html'). This template name will be used at 'gen' command (described below) to search 1) JULI_REPO/.juli/ or 2) lib/juli/template/ -e ext generating html file extention (default='.shtml') gen: -g generator specify generator as follows(default=html): #{visitor_list.join("\n" + " "*25)} -f force generate -t template_path use the template path rather than juli-config value set at 'juli init -t ...' -o output_path specify output file path. It cannot be set at bulk-mode. default is under the directory defined at .juli/config 'output_top' entry. Where, JULI_REPO is the directory which 'juli init' is executed. EOM end |
Instance Method Details
#camelize(str) ⇒ Object
8 9 10 |
# File 'lib/juli/util.rb', line 8 def camelize(str) str.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } end |