Last active
December 20, 2016 13:07
-
-
Save dustalov/8c5ae1761fe311a86d46 to your computer and use it in GitHub Desktop.
Listing generator for a computer program copyright registration.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
TEMPLATE = File.read('source.tex.erb').freeze | |
SOURCE = File.expand_path(ENV['SOURCE'] || '.').freeze | |
EXTENSIONS = %w(*.java).freeze | |
IGNORE = [ | |
/package-info\.java$/, | |
/^src\/test/, | |
/^target/, | |
/^dependency-reduced-pom.xml/ | |
].freeze | |
require 'erb' | |
Source = Struct.new(:filename, :path) | |
File.open('source.tex', 'w') do |file| | |
EXTENSIONS.each do |extension| | |
Dir['%s/**/%s' % [SOURCE, extension]].sort.each do |path| | |
filename = path[SOURCE.length + 1..-1] | |
next if IGNORE.any? { |re| re =~ filename } | |
source = Source.new(filename, path) | |
result = ERB.new(TEMPLATE).result(source.instance_eval { binding }) | |
file.puts(result) | |
file.puts | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: clean lister latex view | |
clean: | |
latexmk -C -pdf | |
rm -f source.tex | |
lister: | |
./lister.rb | |
latex: | |
latexmk -pdf -pdflatex="xelatex %O %S" listing | |
view: | |
xdg-open listing.pdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\subsection*{<%= filename.gsub('_', '\_') %>} | |
<% if /\.java$/ =~ filename %> | |
\lstinputlisting[language=java,firstline=17]{<%= path %>} | |
<% else %> | |
\lstinputlisting{<%= path %>} | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\thispagestyle{empty} | |
\centering | |
{\addtolength{\parskip}{-\parskip} | |
\vspace*{10em} | |
\uppercase{Программа для ЭВМ} | |
\bigskip | |
{\Large\bfseries% | |
Название программы для ЭВМ% | |
} | |
\bigskip | |
Фрагменты исходного текста программы | |
\bigskip | |
\begin{flushright} | |
\begin{minipage}{.5\textwidth} | |
Листов \pageref{LastPage}. | |
\end{minipage} | |
\end{flushright} | |
\bigskip | |
\begin{flushright} | |
\begin{minipage}{.5\textwidth} | |
Автор: | |
Фамилия Имя Отчество. | |
\end{minipage} | |
\end{flushright} | |
\vfill | |
\textcopyright~Фамилия Имя Отчество, 2016. | |
\vspace{3em} | |
г.~Екатеринбург\\ | |
2016~г. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment