Class: Octopress::Ink::Plugin
- Inherits:
-
Object
- Object
- Octopress::Ink::Plugin
- Includes:
- Bootstrap
- Defined in:
- lib/octopress-ink/plugin.rb
Constant Summary collapse
- DEFAULT_CONFIG =
{ type: 'plugin', bootstrap: true }
Instance Attribute Summary collapse
-
#assets_path ⇒ Object
readonly
Returns the value of attribute assets_path.
-
#bootstrap ⇒ Object
readonly
Returns the value of attribute bootstrap.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#docs ⇒ Object
readonly
Returns the value of attribute docs.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#files_dir ⇒ Object
readonly
Returns the value of attribute files_dir.
-
#fonts ⇒ Object
readonly
Returns the value of attribute fonts.
-
#gem ⇒ Object
readonly
Returns the value of attribute gem.
-
#images ⇒ Object
readonly
Returns the value of attribute images.
-
#images_dir ⇒ Object
readonly
Returns the value of attribute images_dir.
-
#includes ⇒ Object
readonly
Returns the value of attribute includes.
-
#includes_dir ⇒ Object
readonly
Returns the value of attribute includes_dir.
-
#javascripts_dir ⇒ Object
readonly
Returns the value of attribute javascripts_dir.
-
#layouts ⇒ Object
readonly
Returns the value of attribute layouts.
-
#layouts_dir ⇒ Object
readonly
Returns the value of attribute layouts_dir.
-
#local ⇒ Object
readonly
Returns the value of attribute local.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#source_url ⇒ Object
readonly
Returns the value of attribute source_url.
-
#stylesheets_dir ⇒ Object
readonly
Returns the value of attribute stylesheets_dir.
-
#templates ⇒ Object
readonly
Returns the value of attribute templates.
-
#templates_dir ⇒ Object
readonly
Returns the value of attribute templates_dir.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
-
#website ⇒ Object
readonly
Returns the value of attribute website.
Attributes included from Bootstrap
#articles_feed, #category_feed, #category_index, #links_feed, #main_feed, #post_archive, #post_index, #tag_feed, #tag_index
Instance Method Summary collapse
-
#add_asset_files(options) ⇒ Object
Add asset files which aren’t disabled.
-
#add_template_pages ⇒ Object
Plugin authors override with template page adding.
-
#config(lang = nil) ⇒ Object
Plugin configuration.
-
#copy_asset_files(path, options) ⇒ Object
Copy asset files to plugin override path.
- #find_page(path) ⇒ Object
- #include(file) ⇒ Object
-
#initialize(options) ⇒ Plugin
constructor
A new instance of Plugin.
- #javascripts ⇒ Object
- #lang_config_files(dir) ⇒ Object
-
#lang_config_hash ⇒ Object
Language configurations.
-
#list(options = {}) ⇒ Object
List info about plugin’s assets.
- #no_compress_js ⇒ Object
- #plugin_lang_configs ⇒ Object
- #read_config ⇒ Object
- #register ⇒ Object
-
#remove_jekyll_assets(files) ⇒ Object
Remove files from Jekyll since they’ll be proccessed by Ink instead.
- #reset ⇒ Object
-
#slug ⇒ Object
Themes should always have the slug “theme”.
- #sort(files, config) ⇒ Object
-
#stylesheets ⇒ Object
stylesheets should include Sass and CSS.
- #user_lang_configs ⇒ Object
- #user_plugin_dir ⇒ Object
Methods included from Bootstrap
#add_feeds, #add_indexes, #add_meta_indexes, add_page, #articles_feed_config, #bootstrap_plugin, category, #category_config_defaults, #category_feed_config, #category_index_config, #feed_config_defaults, #feed_type, #inject_configs, #inject_pages, #linkposts?, #links_feed_config, #main_feed_config, #optional_configs, page, #page_permalink, #page_title, #page_type, #post_archive_config, #post_index_config, #posts?, #register_templates, reset, tag, #tag_config_defaults, #tag_feed_config, #tag_index_config, #tag_or_category_display_label
Constructor Details
#initialize(options) ⇒ Plugin
Returns a new instance of Plugin.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/octopress-ink/plugin.rb', line 18 def initialize() @options = Jekyll::Utils.symbolize_hash_keys( || configuration) DEFAULT_CONFIG.merge().each { |k,v| set_config(k,v) } @layouts_dir = 'layouts' @files_dir = 'files' @pages_dir = 'pages' @docs_dir = 'docs' @fonts_dir = 'fonts' @images_dir = 'images' @includes_dir = 'includes' @javascripts_dir = 'javascripts' @stylesheets_dir = 'stylesheets' @templates_dir = 'templates' @slug ||= @name @assets_path ||= File.join(@path, 'assets') end |
Instance Attribute Details
#assets_path ⇒ Object (readonly)
Returns the value of attribute assets_path.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def assets_path @assets_path end |
#bootstrap ⇒ Object (readonly)
Returns the value of attribute bootstrap.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def bootstrap @bootstrap end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def description @description end |
#docs ⇒ Object (readonly)
Returns the value of attribute docs.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def docs @docs end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def files @files end |
#files_dir ⇒ Object (readonly)
Returns the value of attribute files_dir.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def files_dir @files_dir end |
#fonts ⇒ Object (readonly)
Returns the value of attribute fonts.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def fonts @fonts end |
#gem ⇒ Object (readonly)
Returns the value of attribute gem.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def gem @gem end |
#images ⇒ Object (readonly)
Returns the value of attribute images.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def images @images end |
#images_dir ⇒ Object (readonly)
Returns the value of attribute images_dir.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def images_dir @images_dir end |
#includes ⇒ Object (readonly)
Returns the value of attribute includes.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def includes @includes end |
#includes_dir ⇒ Object (readonly)
Returns the value of attribute includes_dir.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def includes_dir @includes_dir end |
#javascripts_dir ⇒ Object (readonly)
Returns the value of attribute javascripts_dir.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def javascripts_dir @javascripts_dir end |
#layouts ⇒ Object (readonly)
Returns the value of attribute layouts.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def layouts @layouts end |
#layouts_dir ⇒ Object (readonly)
Returns the value of attribute layouts_dir.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def layouts_dir @layouts_dir end |
#local ⇒ Object (readonly)
Returns the value of attribute local.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def local @local end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def name @name end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def pages @pages end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def path @path end |
#source_url ⇒ Object (readonly)
Returns the value of attribute source_url.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def source_url @source_url end |
#stylesheets_dir ⇒ Object (readonly)
Returns the value of attribute stylesheets_dir.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def stylesheets_dir @stylesheets_dir end |
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def templates @templates end |
#templates_dir ⇒ Object (readonly)
Returns the value of attribute templates_dir.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def templates_dir @templates_dir end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def type @type end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def version @version end |
#website ⇒ Object (readonly)
Returns the value of attribute website.
14 15 16 |
# File 'lib/octopress-ink/plugin.rb', line 14 def website @website end |
Instance Method Details
#add_asset_files(options) ⇒ Object
Add asset files which aren’t disabled
98 99 100 101 102 103 |
# File 'lib/octopress-ink/plugin.rb', line 98 def add_asset_files() select_assets().each do |name, assets| next if name == 'config-file' assets.each {|file| file.add unless file.disabled? } end end |
#add_template_pages ⇒ Object
Plugin authors override with template page adding
107 |
# File 'lib/octopress-ink/plugin.rb', line 107 def add_template_pages; end |
#config(lang = nil) ⇒ Object
Plugin configuration
returns: Hash of merged user and default config.yml files
155 156 157 158 159 160 161 |
# File 'lib/octopress-ink/plugin.rb', line 155 def config(lang=nil) if lang lang_config_hash[lang] || read_config else read_config end end |
#copy_asset_files(path, options) ⇒ Object
Copy asset files to plugin override path
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/octopress-ink/plugin.rb', line 111 def copy_asset_files(path, ) copied = [] select_assets().each do |name, assets| next if name == 'user-lang-configs' assets.each { |a| copied << a.copy(path) } end copied.compact end |
#find_page(path) ⇒ Object
228 229 230 |
# File 'lib/octopress-ink/plugin.rb', line 228 def find_page(path) @pages.find {|page| page.filename == path } end |
#include(file) ⇒ Object
224 225 226 |
# File 'lib/octopress-ink/plugin.rb', line 224 def include(file) Pathname.new(@includes.find{|i| i.filename == file }.path) end |
#javascripts ⇒ Object
139 140 141 |
# File 'lib/octopress-ink/plugin.rb', line 139 def javascripts sort(js.clone.concat(coffee), config['order_js'] || []) end |
#lang_config_files(dir) ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/octopress-ink/plugin.rb', line 205 def lang_config_files(dir) configs = {} if defined?(Octopress::Multilingual) && Octopress.site.config['lang'] files = Dir[File.join(dir, 'config_*.yml')] files.each do |file| # Determine the language from the filename pattern: conifg_[lang].yml lang = File.basename(file, '.*').split('_').last configs[lang] = file end end configs end |
#lang_config_hash ⇒ Object
Language configurations
returns: Hash of configs for files matching: conifg_.yml
Example:
{
'de' => { configs },
'fr' => { configs }
}
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/octopress-ink/plugin.rb', line 177 def lang_config_hash @lang_config_hash ||= begin configs = {} user_lang_configs.each do |lang, file| configs[lang] = Jekyll::Utils.deep_merge_hashes(config, SafeYAML.load_file(file)) end plugin_lang_configs.each do |lang, file| # Add to lang @lang_configs << Assets::LangConfig.new(self, File.basename(file), lang) configs[lang] = Jekyll::Utils.deep_merge_hashes(config, @lang_configs.last.read) end configs end end |
#list(options = {}) ⇒ Object
List info about plugin’s assets
returs: String filled with asset info
88 89 90 91 92 93 94 |
# File 'lib/octopress-ink/plugin.rb', line 88 def list(={}) if ['minimal'] minimal_list else detailed_list() end end |
#no_compress_js ⇒ Object
143 144 145 |
# File 'lib/octopress-ink/plugin.rb', line 143 def no_compress_js @no_compress_js.reject(&:disabled?).compact end |
#plugin_lang_configs ⇒ Object
195 196 197 |
# File 'lib/octopress-ink/plugin.rb', line 195 def plugin_lang_configs lang_config_files(@assets_path) end |
#read_config ⇒ Object
163 164 165 |
# File 'lib/octopress-ink/plugin.rb', line 163 def read_config @config ||= configs.first.read end |
#register ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/octopress-ink/plugin.rb', line 53 def register reset unless @assets_path.nil? disable_assets add_assets add_images if Octopress::Docs.enabled? add_docs end if Octopress::Ink.enabled? add_includes add_layouts add_javascripts add_stylesheets add_fonts add_files add_pages add_templates bootstrap_plugin if @bootstrap end end end |
#remove_jekyll_assets(files) ⇒ Object
Remove files from Jekyll since they’ll be proccessed by Ink instead
220 221 222 |
# File 'lib/octopress-ink/plugin.rb', line 220 def remove_jekyll_assets(files) files.each {|f| f.remove_jekyll_asset } end |
#reset ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/octopress-ink/plugin.rb', line 37 def reset @lang_configs = [] @layouts = [] @includes = [] @css = [] @js = [] @no_compress_js = [] @coffee = [] @images = [] @sass = [] @fonts = [] @files = [] @pages = [] @templates = [] end |
#slug ⇒ Object
Themes should always have the slug “theme”
80 81 82 |
# File 'lib/octopress-ink/plugin.rb', line 80 def slug Filters.sluggify @type == 'theme' ? 'theme' : @slug end |
#sort(files, config) ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/octopress-ink/plugin.rb', line 122 def sort(files, config) sorted = [] config.each do |item| files.each do |file| sorted << files.delete(file) if file.path.to_s.include? item end end sorted.concat files end |
#stylesheets ⇒ Object
stylesheets should include Sass and CSS
135 136 137 |
# File 'lib/octopress-ink/plugin.rb', line 135 def stylesheets sort(css.clone.concat(sass_without_partials), config['order_css'] || []) end |
#user_lang_configs ⇒ Object
199 200 201 202 203 |
# File 'lib/octopress-ink/plugin.rb', line 199 def user_lang_configs files = lang_config_files(user_plugin_dir) plugin_lang_configs.keys.each {|k| files.delete(k)} files end |
#user_plugin_dir ⇒ Object
147 148 149 |
# File 'lib/octopress-ink/plugin.rb', line 147 def user_plugin_dir File.join(Plugins.custom_dir, slug) end |