Class: Octopress::Ink::Plugin

Inherits:
Object
  • Object
show all
Includes:
Bootstrap
Defined in:
lib/octopress-ink/plugin.rb

Constant Summary collapse

DEFAULT_CONFIG =
{
  type: 'plugin',
  bootstrap: true
}

Instance Attribute Summary collapse

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

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)
  @options = Jekyll::Utils.symbolize_hash_keys(options || configuration)

  DEFAULT_CONFIG.merge(options).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_pathObject (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

#bootstrapObject (readonly)

Returns the value of attribute bootstrap.



14
15
16
# File 'lib/octopress-ink/plugin.rb', line 14

def bootstrap
  @bootstrap
end

#descriptionObject (readonly)

Returns the value of attribute description.



14
15
16
# File 'lib/octopress-ink/plugin.rb', line 14

def description
  @description
end

#docsObject (readonly)

Returns the value of attribute docs.



14
15
16
# File 'lib/octopress-ink/plugin.rb', line 14

def docs
  @docs
end

#filesObject (readonly)

Returns the value of attribute files.



14
15
16
# File 'lib/octopress-ink/plugin.rb', line 14

def files
  @files
end

#files_dirObject (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

#fontsObject (readonly)

Returns the value of attribute fonts.



14
15
16
# File 'lib/octopress-ink/plugin.rb', line 14

def fonts
  @fonts
end

#gemObject (readonly)

Returns the value of attribute gem.



14
15
16
# File 'lib/octopress-ink/plugin.rb', line 14

def gem
  @gem
end

#imagesObject (readonly)

Returns the value of attribute images.



14
15
16
# File 'lib/octopress-ink/plugin.rb', line 14

def images
  @images
end

#images_dirObject (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

#includesObject (readonly)

Returns the value of attribute includes.



14
15
16
# File 'lib/octopress-ink/plugin.rb', line 14

def includes
  @includes
end

#includes_dirObject (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_dirObject (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

#layoutsObject (readonly)

Returns the value of attribute layouts.



14
15
16
# File 'lib/octopress-ink/plugin.rb', line 14

def layouts
  @layouts
end

#layouts_dirObject (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

#localObject (readonly)

Returns the value of attribute local.



14
15
16
# File 'lib/octopress-ink/plugin.rb', line 14

def local
  @local
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/octopress-ink/plugin.rb', line 14

def name
  @name
end

#pagesObject (readonly)

Returns the value of attribute pages.



14
15
16
# File 'lib/octopress-ink/plugin.rb', line 14

def pages
  @pages
end

#pathObject (readonly)

Returns the value of attribute path.



14
15
16
# File 'lib/octopress-ink/plugin.rb', line 14

def path
  @path
end

#source_urlObject (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_dirObject (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

#templatesObject (readonly)

Returns the value of attribute templates.



14
15
16
# File 'lib/octopress-ink/plugin.rb', line 14

def templates
  @templates
end

#templates_dirObject (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

#typeObject (readonly)

Returns the value of attribute type.



14
15
16
# File 'lib/octopress-ink/plugin.rb', line 14

def type
  @type
end

#versionObject (readonly)

Returns the value of attribute version.



14
15
16
# File 'lib/octopress-ink/plugin.rb', line 14

def version
  @version
end

#websiteObject (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(options)
  select_assets(options).each do |name, assets|
    next if name == 'config-file'
    assets.each {|file| file.add unless file.disabled? }
  end
end

#add_template_pagesObject

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, options)
  copied = []

  select_assets(options).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

#javascriptsObject



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_hashObject

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(options={})
  if options['minimal']
    minimal_list
  else
    detailed_list(options)
  end
end

#no_compress_jsObject



143
144
145
# File 'lib/octopress-ink/plugin.rb', line 143

def no_compress_js
  @no_compress_js.reject(&:disabled?).compact
end

#plugin_lang_configsObject



195
196
197
# File 'lib/octopress-ink/plugin.rb', line 195

def plugin_lang_configs
  lang_config_files(@assets_path)
end

#read_configObject



163
164
165
# File 'lib/octopress-ink/plugin.rb', line 163

def read_config
  @config ||= configs.first.read
end

#registerObject



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

#resetObject



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

#slugObject

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

#stylesheetsObject

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_configsObject



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_dirObject



147
148
149
# File 'lib/octopress-ink/plugin.rb', line 147

def user_plugin_dir
  File.join(Plugins.custom_dir, slug)
end