【问题标题】:compass/sass remote themeing via sftp/scp with alternate port通过带有备用端口的 sftp/scp 的 compass/sass 远程主题
【发布时间】:2016-05-10 21:35:58
【问题描述】:

我正在尝试让 compass/sass 观察本地计算机上的更改,并使用自定义 config.rb 脚本远程反映这些更改。 net::sftp 有效,但我的服务器需要自定义 ssh 端口。我找不到任何使 sftp 与备用端口一起工作的模块,所以我现在尝试net:scp,问题是我不知道使用 net:scp 上传的正确命令结构,并想看看是否有人可以帮助我。这是我的代码:

  # Require any additional compass plugins here.
require 'net/ssh'
require 'net/scp'

# SFTP Connection Details - Does not support alternate ports os SSHKeys, but could with mods
remote_theme_dir_absolute = '/home2/trinsic/public_html/scottrlarson.com/sites/all/themes/ gateway_symbology_zen/css'
sftp_host = 'xxx.xxx.xxx.xxx' # Can be an IP
sftp_user = 'user' # SFTP Username
sftp_pass = 'password' # SFTP Password

# Callback to be used when a file change is written. This will upload to a remote WP install
on_stylesheet_saved do |filename|
  $local_path_to_css_file = css_dir + '/' + File.basename(filename)

  Net::SSH.start( sftp_host, sftp_user, {:password => sftp_pass,:port => 2222} ) do ssh.scp.upload! $local_path_to_css_file, remote_theme_dir_absolute + '/' + File.basename(filename)
    end
  puts ">>>> Compass is polling for changes. Press Ctrl-C to Stop"
end

#
# This file is only needed for Compass/Sass integration. If you are not using
# Compass, you may safely ignore or delete this file.
#
# If you'd like to learn more about Sass and Compass, see the sass/README.txt
# file for more information.
#


# Change this to :production when ready to deploy the CSS to the live server.
environment = :development
#environment = :production

# In development, we can turn on the FireSass-compatible debug_info.
firesass = false
#firesass = true


# Location of the theme's resources.
css_dir         = "css"
sass_dir        = "sass"
extensions_dir  = "sass-extensions"
images_dir      = "images"
javascripts_dir = "js"


# Require any additional compass plugins installed on your system.
#require 'ninesixty'
#require 'zen-grids'

# Assuming this theme is in sites/*/themes/THEMENAME, you can add the partials
# included with a module by uncommenting and modifying one of the lines below:
#add_import_path "../../../default/modules/FOO"
#add_import_path "../../../all/modules/FOO"
#add_import_path "../../../../modules/FOO"


##
## You probably don't need to edit anything below this.
##

# You can select your preferred output style here (can be overridden via the command line):
# output_style = :expanded or :nested or :compact or :compressed
output_style = (environment == :development) ? :expanded : :compressed

# To enable relative paths to assets via compass helper functions. Since Drupal
# themes can be installed in multiple locations, we don't need to worry about
# the absolute path to the theme from the server root.
relative_assets = true

# To disable debugging comments that display the original location of your selectors. Uncomment:
# line_comments = false

# Pass options to sass. For development, we turn on the FireSass-compatible
# debug_info if the firesass config variable above is true.
sass_options = (environment == :development && firesass == true) ? {:debug_info => true} : {}

运行命令时出现错误:compass watch:

NoMethodError on line ["17"] of K: undefined method `upload!' for #<Net::SSH::Co
nnection::Session:0x000000036bb220>
Run with --trace to see the full backtrace

【问题讨论】:

    标签: sass remote-access compass theming zen


    【解决方案1】:

    我也需要一个解决方案,但在任何地方都没有找到任何令人满意的答案。 在阅读了 Ruby Net::ssh 文档和 Compass 的一些来源之后,这是我将 CSS 和 sourcemap 上传到具有非标准端口和强制公钥授权的远程 SSH 服务器的解决方案:

    首先确保您已安装所需的 gems

    sudo gem install net-ssh net-sftp
    

    然后将其添加到您的 config.rb

    # Add this to the first lines of your config.rb
    require 'net/ssh'
    require 'net/sftp'
    
    ...
    # Your normal compass config comes here
    ...
    
    # At the end of your config.rb add the config for the upload code
    remote_theme_dir_absolute = '/path/to/my/remote/stylesheets'
    
    sftp_host = 'ssh_host' # Can be an IP
    sftp_user = 'ssh_user' # SFTP Username
    
    on_stylesheet_saved do |filename|
    
      # You can use the ssh-agent for authorisation. 
      # In this case you can remove the :passphrase from the config and set :use_agent => true.
    
      Net::SFTP.start(
    
        sftp_host, 
        sftp_user , 
        :port => 10022, 
        :keys_only => true, 
        :keys => ['/path/to/my/private/id_rsa'], 
        :auth_methods => ['publickey'], 
        :passphrase => 'my_secret_passphrase', 
        :use_agent => false, 
        :verbose => :warn
    
      ) do |sftp|
    
          puts sftp.upload! css_dir + '/app.css', remote_theme_dir_absolute + '/' + 'app.css'
    
      end
    
    end
    
    on_sourcemap_saved do |filename|
    
      # You can use the ssh-agent for authorisation. 
      # In this case you can remove the :passphrase from the config and set :use_agent true.
    
      Net::SFTP.start(
        sftp_host, 
        sftp_user , 
        :port => 10022, 
        :keys_only => true, 
        :keys => ['/path/to/my/private/id_rsa'], 
        :auth_methods => ['publickey'], 
        :passphrase => 'my_secret_passphrase', 
        :use_agent => false, 
        :verbose => :warn
      ) do |sftp|
    
        puts sftp.upload! css_dir + '/app.css.map', remote_theme_dir_absolute + '/' + 'app.css.map'
    
      end
    
    end
    

    在这对我有用之前,这是相当多的试验和错误。 一些失败点是:

    • 如果没有 ssh-agent 可用,连接将失败,直到您明确设置 :ssh_agent =&gt; false
    • 如果您不使用 :keys 限制可用密钥,所有可用密钥将一个接一个地尝试。如果您使用 ssh-agent 并且安装了 3 个以上的密钥,那么如果您尝试太多对您当前连接的服务器无效的密钥,远程服务器将关闭连接。
    • 在任何连接问题上将详细级别设置为:verbose =&gt; :debug 以查看发生了什么。请记住停止compass watch 并重新启动以确保应用配置更改。

    【讨论】:

      猜你喜欢
      • 2012-06-29
      • 2014-08-18
      • 2014-12-07
      • 1970-01-01
      • 2013-11-22
      • 2011-01-18
      • 2011-10-03
      • 2011-11-06
      • 2015-04-03
      相关资源
      最近更新 更多