Class: Smooster::Cli::Executable

Inherits:
Thor
  • Object
show all
Defined in:
lib/smooster/cli/executable.rb

Instance Method Summary collapse

Instance Method Details

#configureObject



144
145
146
147
148
149
150
151
152
153
# File 'lib/smooster/cli/executable.rb', line 144

def configure()

  if File.exists?("#{Smooster::Application.instance.base_dir}/site_config.yml")
    Smooster::Deploy::Setting.upload()

    puts "done!"
  else
    puts "no site_config.yml could be found in your project root folder. Please use 'smooster setup SITE_ID' to create site_config.yml".colorize(:red)
  end
end

#deploy(type = "assets") ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
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
# File 'lib/smooster/cli/executable.rb', line 58

def deploy(type="assets")

  unless File.directory?("#{Smooster::Application.instance.base_dir}/#{Smooster::Application.instance.html_folder()}")
    puts "ERROR: There is no #{Smooster::Application.instance.html_folder()}/ folder, please call smooster deploy from a folder including a folder named #{Smooster::Application.instance.html_folder()}/".colorize(:red)
    return false
  end

  puts "Starting push to smooster..."

  if type == "assets" || type == "all" || type == "initial"
    Smooster::Deploy::MediaAsset.all.each do |ma|
      status = "[deployed]".colorize(:blue)
      status = "[unchanged]".colorize(:green) if ma.checksum.to_s == ma.load_checksum.to_s
      puts "#{ma.file_path} #{status}"
      ma.upload
    end
  end

  if type == "templates" || type == "all" || type == "initial"
    Smooster::Deploy::SiteTemplate.all.each do |st|
      status = "[deployed]".colorize(:blue)
      status = "[unchanged]".colorize(:green) if st.checksum.to_s == st.load_checksum.to_s
      st.upload
      puts "#{st.path} #{status}"
    end
  end

  if type == "initial"
    urls = []
    Smooster::Deploy::SiteTemplate.all.each do |st|
      status = "[create]".colorize(:blue)
      #status = "[exists]".colorize(:green) if st.checksum.to_s == st.load_checksum.to_s
      p = Smooster::Deploy::Page.new({:title => st.title, :filename => st.title, :site_template_id => st.smo_id})
      p.upload
      urls << p.url
      puts "#{p.filename} #{status}"
    end
    puts "Starting validation of #{urls.count} pages"
    return if urls.count == 0
    urls.each do |url|
      begin
        puts "#{url}"
        url_encoded = CGI.escape(url)
        if options[:validator]
          Launchy.open("http://validator.w3.org/check?uri=#{url_encoded}&charset=%28detect+automatically%29&doctype=Inline&group=0")
          sleep 1
        end
      rescue => e
        Smooster::Application.instance.logger.error "Error in page validation for #{url}!: #{e} / #{e.backtrace.inspect}"
        puts "This url failed to be validated: #{url}".colorize(:red)
      end
    end
  end

  puts "#{type} done!"
end

#load(type = "assets") ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/smooster/cli/executable.rb', line 117

def load(type="assets")

  unless File.directory?("#{Smooster::Application.instance.base_dir}/#{Smooster::Application.instance.html_folder()}")
    puts "ERROR: There is no #{Smooster::Application.instance.html_folder()}/ folder, please call smooster load from a folder including a folder named #{Smooster::Application.instance.html_folder()}/".colorize(:red)
    return false
  end

  puts "Starting loading from smooster..."

  if type == "assets" || type == "all"
    Smooster::Deploy::MediaAsset.all.each do |ma|
      status = "[loading]".colorize(:blue)
      status = "[unchanged]".colorize(:green) if ma.checksum.to_s == ma.load_checksum.to_s
      puts "#{ma.file_path} #{status}"
      ma.download(options[:keep])
    end
  end

  if type == "templates" || type == "all"
    puts "NOTICE: This feature is not yet implemented".colorize(:blue)
    return false
  end

  puts "#{type} done!"
end

#register(api_key) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/smooster/cli/executable.rb', line 18

def register(api_key)

  unless File.directory?("#{Dir.home}/.smo")
    FileUtils.mkdir_p("#{Dir.home}/.smo")
  end

  Smooster::Application.instance.update_api_key(api_key)
  puts Smooster::Application.instance.api_key()
  puts "done!"
end

#setup(site_id, api_url = "http://cms.smooster.com/api", html_folder = "html") ⇒ Object

method_options :force => :boolean, :alias => :string



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/smooster/cli/executable.rb', line 31

def setup(site_id, api_url="http://cms.smooster.com/api", html_folder="html")

  unless File.directory?("#{Smooster::Application.instance.base_dir}/#{html_folder}")
    puts "ERROR: There is no #{html_folder}/ folder, please call smooster setup from a folder including a folder named #{html_folder}/".colorize(:red)
    return false
  end

  unless File.directory?("#{Smooster::Application.instance.base_dir}/.smo")
    FileUtils.mkdir_p("#{Smooster::Application.instance.base_dir}/.smo")
  end

  config_store = Smooster::Application.instance.config
  config_store.transaction do
    config_store[:api_url] = api_url
    config_store[:html_folder] = html_folder
    config_store[:site_id] = site_id
  end

  #if ([(print 'Create a site_config.yml file? [y]: '), gets.rstrip][1] == "y")
    unless File.exists?("#{Smooster::Application.instance.base_dir}/site_config.yml")
      File.open("#{Smooster::Application.instance.base_dir}/site_config.yml", "w+") { |file| file.write(File.read(File.expand_path('../../templates/site_config.yml', __FILE__))) }
    end
  #end
end

#testObject



11
12
13
14
15
# File 'lib/smooster/cli/executable.rb', line 11

def test
  puts "smooster Gem Version: #{Gem.loaded_specs["smooster"].version}"
  puts Smooster::Application.instance.api_key()
  puts Dir.pwd
end