Class: Amiba::Site::Generate

Inherits:
Thor::Group
  • Object
show all
Includes:
Generator
Defined in:
lib/amiba/site.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Generator

included

Class Method Details

.source_rootObject



115
116
117
# File 'lib/amiba/site.rb', line 115

def self.source_root
  Dir.pwd
end

Instance Method Details

#build_entriesObject



162
163
164
165
166
# File 'lib/amiba/site.rb', line 162

def build_entries
  Amiba::Source::Entry.send(state).each do |entry|
    build_page entry
  end
end

#build_feedsObject



191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/amiba/site.rb', line 191

def build_feeds
  Dir.glob('feeds/*.builder').each do |feed_file|
    feed = Amiba::Source::Feed.new(feed_file)
    begin
      create_file(feed.output_filename) do
        Amiba::Tilt.new(feed.filename).render(Amiba::Scope.new(feed), :xml => Builder::XmlMarkup.new)
      end
    rescue
      say_status "Failed", "Unable to process #{feed.name}: #{$!}, skipping", :red
    end
  end
end

#build_jsonObject



177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/amiba/site.rb', line 177

def build_json
  Dir.glob('entries/*').each do |cat|
    next unless File.directory? cat
    c = File.basename cat
    create_file(File.join(Amiba::Configuration.site_dir, "public", c, "latest.json")) do
      Amiba::Source::Entry.send(c.to_sym.pluralize).limit(20).each.inject([]) do |acc, ent|
        a = ent.
        a["content"] = ent.render
        acc << a
      end.to_json
    end
  end
end

#build_pagesObject



168
169
170
171
172
173
174
175
# File 'lib/amiba/site.rb', line 168

def build_pages
  Dir.glob('pages/**/[^_]*').each do |page_file|
    next if File.directory? page_file
    page = Amiba::Source::Page.new(File.relpath(page_file, "pages"))
    next unless (page.state == "published" || options[:drafts])
    build_page page
  end
end

#cleardownObject



119
120
121
122
# File 'lib/amiba/site.rb', line 119

def cleardown
  remove_dir Amiba::Configuration.site_dir
  remove_dir Amiba::Configuration.staged_dir
end

#copy_cssObject



148
149
150
151
152
# File 'lib/amiba/site.rb', line 148

def copy_css
  Dir.glob('public/css/*.css').each do |css_file|
    copy_file css_file, File.join(Amiba::Configuration.site_dir, "public/css/", File.basename(css_file))
  end
end

#copy_faviconObject



128
129
130
131
132
# File 'lib/amiba/site.rb', line 128

def copy_favicon
  if File.exists? "public/images/favicon.ico"
    copy_file "public/images/favicon.ico", File.join(Amiba::Configuration.site_dir, "public/favicon.ico")
  end
end

#copy_imagesObject



144
145
146
# File 'lib/amiba/site.rb', line 144

def copy_images
  directory "public/images", File.join(Amiba::Configuration.site_dir, "public/images")
end

#copy_javascriptObject



140
141
142
# File 'lib/amiba/site.rb', line 140

def copy_javascript
  directory "public/js", File.join(Amiba::Configuration.site_dir, "public/js")
end

#copy_xdomainObject



134
135
136
137
138
# File 'lib/amiba/site.rb', line 134

def copy_xdomain
  if File.exists? "public/crossdomain.xml"
    copy_file "public/crossdomain.xml", File.join(Amiba::Configuration.site_dir, "public/crossdomain.xml")
  end
end

#create_site_structureObject



124
125
126
# File 'lib/amiba/site.rb', line 124

def create_site_structure
  empty_directory Amiba::Configuration.site_dir
end

#process_and_copy_sassObject



154
155
156
157
158
159
160
# File 'lib/amiba/site.rb', line 154

def process_and_copy_sass
  Dir.glob('public/css/[^_]*.scss').each do |scss_file|
    create_file File.join(Amiba::Configuration.site_dir,"public/css/", File.basename(scss_file).gsub('scss', 'css')) do
      Amiba::Tilt.new(scss_file).render
    end
  end
end