Class: Alula::Site

Inherits:
Object
  • Object
show all
Defined in:
lib/alula/site.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Site

Returns a new instance of Site.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/alula/site.rb', line 70

def initialize(options)
  @@instance = self
  
  # Read local config
  @config = Config.new(options)

  @storage = Storage.load(site: self)
  
  @metadata = Content::Metadata.new({
    base_locale: @config.locale,
    environment: @config.environment,
    
    title: @config.title,
    author: @config.author,
    description: @config.description,
    tagline: @config.tagline,
    url: @config.url,
    
    theme: @config.theme,
    
    # Use this to store information of GIT site or note
    git: ::File.directory?(".git"),
  })
  
  # Progress displayer
  @progress = Progress.new(debug: options["debug"])
  
  # Compressors
  compressors = if @config.assets.compress
    {
      html: Alula::Compressors::HTMLCompressor.new,
      css: Alula::Compressors::CSSCompressor.new,
      js: Alula::Compressors::JSCompressor.new,
    }
  else
    {
      html: Alula::Compressors::DummyCompressor.new,
      css: Alula::Compressors::DummyCompressor.new,
      js: Alula::Compressors::DummyCompressor.new,
    }
  end
  @compressors = Hashie::Mash.new(compressors)
  
  @attachments = AttachmentProcessor.new(site: self)
  
  # Set up CDN resolver
  @cdn = CDN.load(site: self)
  
  @plugins = {}
  
  @filters = {}
  
  # Set up I18n
  l10n_path = File.join(File.dirname(__FILE__), "..", "..", "locales", "l10n", "*.yml")
  locale_path = File.join(File.dirname(__FILE__), "..", "..", "locales", "*.yml")
  custom_locale_path = File.join(@storage.path(:custom, "locales"), "*.yml")
  I18n.load_path += Dir[l10n_path]
  I18n.load_path += Dir[locale_path]
  I18n.load_path += Dir[custom_locale_path]
  I18n.default_locale = @config.locale
  
  # Set up default head addons
  Alula::Plugin.addon(:head, "<meta name=\"generator\" content=\"Alula #{Alula::VERSION::STRING}\">")
  Alula::Plugin.addon(:head, ->(context){"<link rel=\"icon\" type=\"image/png\" href=\"#{context.asset_url('favicon.png')}\">"})
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object

Proxy to metadata



171
172
173
174
175
176
177
178
179
# File 'lib/alula/site.rb', line 171

def method_missing(meth, *args, &blk)
  # Proxy to metadata
  if !meth[/=$/] and self..respond_to?(meth)
    args.unshift(self.context.locale || self.config.locale) if args.empty?
    self..send(meth, *args)
  else
    super
  end
end

Instance Attribute Details

#attachmentsObject (readonly)

Site attachment mapping



59
60
61
# File 'lib/alula/site.rb', line 59

def attachments
  @attachments
end

#cdnObject (readonly)

CDN Resolver for Site



44
45
46
# File 'lib/alula/site.rb', line 44

def cdn
  @cdn
end

#compressorsObject (readonly)

Compressors



53
54
55
# File 'lib/alula/site.rb', line 53

def compressors
  @compressors
end

#configObject (readonly)

Global configuration



32
33
34
# File 'lib/alula/site.rb', line 32

def config
  @config
end

#contentObject (readonly)

User generated content



65
66
67
# File 'lib/alula/site.rb', line 65

def content
  @content
end

#contextObject (readonly)

Context for rendering



38
39
40
# File 'lib/alula/site.rb', line 38

def context
  @context
end

#filtersObject (readonly)

Site filters



50
51
52
# File 'lib/alula/site.rb', line 50

def filters
  @filters
end

#generatedObject (readonly)

System generated content, pages, pagination, etc.



68
69
70
# File 'lib/alula/site.rb', line 68

def generated
  @generated
end

#metadataObject (readonly)

Site metadata information



56
57
58
# File 'lib/alula/site.rb', line 56

def 
  @metadata
end

#pluginsObject (readonly)

Site Plugins



47
48
49
# File 'lib/alula/site.rb', line 47

def plugins
  @plugins
end

#progressObject (readonly)

Progress displayer



41
42
43
# File 'lib/alula/site.rb', line 41

def progress
  @progress
end

#storageObject (readonly)

Storage



35
36
37
# File 'lib/alula/site.rb', line 35

def storage
  @storage
end

#themeObject (readonly)

Theme



62
63
64
# File 'lib/alula/site.rb', line 62

def theme
  @theme
end

Class Method Details

.instanceObject



29
# File 'lib/alula/site.rb', line 29

def self.instance; @@instance; end

Instance Method Details

#deployObject



164
165
166
167
168
# File 'lib/alula/site.rb', line 164

def deploy
  banner
  
  
end

#generateObject

Compiles a site to static website



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/alula/site.rb', line 137

def generate
  banner
  
  # Load our plugins and filters
  load_plugins
  load_filters
  
  # Prepare public folder
  prepare(true)
  
  load_content
  
  process_attachments
  
  compile_assets
  
  render
  
  cleanup
  
  compress
  
  # Store cached version of configuration
  cached_config = File.join(storage.path(:cache), "config.yml")
  @config.write_cache(cached_config)
end